From d9c57939005a04d27253c6d9f16aaa11d47463cc Mon Sep 17 00:00:00 2001 From: jaeone lee <89377375+jaeone94@users.noreply.github.com> Date: Thu, 15 Oct 2026 03:23:03 +0000 Subject: [PATCH] fix: remove orphaned promoted inputs when a DynamicGroup row is deleted (#21050) ## Summary Deleting a DynamicGroup row whose field is promoted through nested subgraphs left an unconnected input for the deleted row on every enclosing host. Reported in 1.57 QA: https://comfy-organization.slack.com/archives/C0932CGKT5K/p1792020581765129 `disconnectOrphanedPromotion` (#20181, #20708) disconnected each host input once the inner subgraph input had no remaining links, but never removed that subgraph input. Hosts mirror subgraph inputs, so the socket stayed. It now removes the orphaned subgraph input after disconnecting the hosts, at each level it walks. ## Review focus - The input is removed even when an outer node is connected to the host input; the row it fed no longer exists. An input that still has another consumer inside the subgraph is kept, as before. - Two existing tests asserted the old disconnect-only behavior and now assert the inputs are gone. ## Tests - New: `removes the deleted row inputs from both hosts while keeping the next row`, which follows the QA repro (three rows, rows 2 and 3 promoted through two boundaries, delete row 2). - `dynamicGroupWidget.test.ts`: 3 failed / 42 passed on main, 45 passed with the fix. - `src/core`, `src/lib/litegraph/src/subgraph`, `src/workbench/extensions/agent`, `src/renderer/extensions/vueNodes`: 5,316 passed. One timing test in `useAgentSession.test.ts` failed once under load and passed on two isolated reruns. --- .../graph/widgets/dynamicGroupWidget.test.ts | 128 +++++++++++++++++- src/core/graph/widgets/dynamicGroupWidget.ts | 42 ++++-- 2 files changed, 157 insertions(+), 13 deletions(-) diff --git a/src/core/graph/widgets/dynamicGroupWidget.test.ts b/src/core/graph/widgets/dynamicGroupWidget.test.ts index fec0992e797..22eb83707f5 100644 --- a/src/core/graph/widgets/dynamicGroupWidget.test.ts +++ b/src/core/graph/widgets/dynamicGroupWidget.test.ts @@ -464,14 +464,134 @@ describe('DynamicGroup widgets', () => { ) it('removes a field promoted through two boundaries when its row is removed', async () => { - const { widget, innerHost, outerInput } = setupTwiceDeepPromotion() + const { widget, innerHost, outerHost, outerInput } = + setupTwiceDeepPromotion() widget('loras.1').callback?.(undefined) - expect(innerHost.inputs[0].link).toBeNull() + expect(innerHost.inputs).toEqual([]) + expect(outerHost.inputs).toEqual([]) await vi.waitFor(() => expect(promotedInputWidget(outerInput)).toBeNull()) }) + it('removes the deleted row inputs from both hosts while keeping the next row', () => { + const { node, widget, innerHost, outerHost } = setupTwiceDeepPromotion() + widget('loras').value = 3 + expect( + promoteValueWidgetViaSubgraphInput( + innerHost, + node, + widget('loras.2.strength') + ).ok + ).toBe(true) + const innerPromoted = promotedInputWidget(innerHost.inputs[1]) + assert.exists(innerPromoted) + expect( + promoteValueWidgetViaSubgraphInput(outerHost, innerHost, innerPromoted).ok + ).toBe(true) + + widget('loras.1').callback?.(undefined) + + expect(innerHost.subgraph.inputs).toHaveLength(1) + expect(outerHost.subgraph.inputs).toHaveLength(1) + expect( + [innerHost.inputs, outerHost.inputs].map((inputs) => + inputs.map((input) => promotedInputWidget(input)?.label) + ) + ).toEqual([['LoRA #2 strength'], ['LoRA #2 strength']]) + }) + + it('drops the rerouted promotion link of a removed subgraph input', () => { + const { node, widget, innerHost } = setupTwiceDeepPromotion() + const subgraph = innerHost.subgraph + const linkId = node.inputs.find( + (input) => input.name === 'loras.1.strength' + )?.link + const link = linkId == null ? undefined : subgraph.links.get(linkId) + assert.exists(link) + assert.exists(subgraph.createReroute([0, 0], link)) + + widget('loras.1').callback?.(undefined) + + expect(subgraph.inputs).toEqual([]) + expect(subgraph.floatingLinks.size).toBe(0) + }) + + it('drops the rerouted link of a later promoted field in the same row', () => { + const { node, widget, innerHost } = setupTwiceDeepPromotion() + const subgraph = innerHost.subgraph + expect( + promoteValueWidgetViaSubgraphInput( + innerHost, + node, + widget('loras.1.enabled') + ).ok + ).toBe(true) + const linkId = node.inputs.find( + (input) => input.name === 'loras.1.enabled' + )?.link + const link = linkId == null ? undefined : subgraph.links.get(linkId) + assert.exists(link) + assert.exists(subgraph.createReroute([0, 0], link)) + + widget('loras.1').callback?.(undefined) + + expect(subgraph.inputs).toEqual([]) + expect(subgraph.floatingLinks.size).toBe(0) + }) + + it('drops a floating host link left on a removed promoted input', () => { + const { widget, innerHost, outerSubgraph } = setupTwiceDeepPromotion() + const linkId = innerHost.inputs[0].link + const link = linkId == null ? undefined : outerSubgraph.links.get(linkId) + assert.exists(link) + assert.exists(outerSubgraph.createReroute([0, 0], link)) + link.disconnect(outerSubgraph, 'input') + expect(outerSubgraph.floatingLinks.size).toBe(1) + + widget('loras.1').callback?.(undefined) + + expect(innerHost.inputs).toEqual([]) + expect(outerSubgraph.floatingLinks.size).toBe(0) + }) + + it('removes every promoted field of the deleted row through two boundaries', () => { + const { node, widget, innerHost, outerHost } = setupTwiceDeepPromotion() + widget('loras').value = 3 + expect( + promoteValueWidgetViaSubgraphInput( + innerHost, + node, + widget('loras.1.enabled') + ).ok + ).toBe(true) + const enabled = promotedInputWidget(innerHost.inputs[1]) + assert.exists(enabled) + expect( + promoteValueWidgetViaSubgraphInput(outerHost, innerHost, enabled).ok + ).toBe(true) + expect( + promoteValueWidgetViaSubgraphInput( + innerHost, + node, + widget('loras.2.strength') + ).ok + ).toBe(true) + const strength = promotedInputWidget(innerHost.inputs[2]) + assert.exists(strength) + expect( + promoteValueWidgetViaSubgraphInput(outerHost, innerHost, strength).ok + ).toBe(true) + + widget('loras.1').callback?.(undefined) + + expect( + [innerHost.inputs, outerHost.inputs].map((inputs) => + inputs.map((input) => promotedInputWidget(input)?.label) + ) + ).toEqual([['LoRA #2 strength'], ['LoRA #2 strength']]) + }) + it('disconnects the deleted row at the outer host while keeping the next row connected', async () => { const { node, widget, innerHost, outerHost, outerInput } = setupTwiceDeepPromotion() @@ -509,8 +629,8 @@ describe('DynamicGroup widgets', () => { await vi.waitFor(() => expect(promotedInputWidget(outerInput)).toBeNull()) expect(graph.getLink(removed.id)).toBeUndefined() expect(graph.getLink(otherRemoved.id)).toBeUndefined() - expect(outerInput.link).toBeNull() - expect(otherHost.inputs[0].link).toBeNull() + expect(outerHost.inputs).toEqual([survivingInput]) + expect(otherHost.inputs).toHaveLength(1) assert.exists(survivingInput.link) expect(graph.getLink(survivingInput.link)).toBe(retained) expect(promotedInputWidget(survivingInput)?.value).toBe(0.37) diff --git a/src/core/graph/widgets/dynamicGroupWidget.ts b/src/core/graph/widgets/dynamicGroupWidget.ts index 46a34295646..23d6abe21bc 100644 --- a/src/core/graph/widgets/dynamicGroupWidget.ts +++ b/src/core/graph/widgets/dynamicGroupWidget.ts @@ -150,12 +150,17 @@ export function dynamicGroupWidget( const inputs = previous.inputs.filter( (input) => !input.name.startsWith(`${prefix}.`) ) - const promotedSlots = previous.inputs.flatMap((input) => { - const link = previous.links.get(input) - return !inputs.includes(input) && link?.origin_id === SUBGRAPH_INPUT_ID - ? [link.origin_slot] - : [] - }) + const graph = node.graph + const promotedInputs = new Set( + previous.inputs.flatMap((input) => { + const link = previous.links.get(input) + return isSubgraph(graph) && + !inputs.includes(input) && + link?.origin_id === SUBGRAPH_INPUT_ID + ? [graph.inputs[link.origin_slot]] + : [] + }) + ) const result = replaceNodeInputs( node, previous, @@ -173,8 +178,9 @@ export function dynamicGroupWidget( previous.inputs.forEach((input, slot) => { if (!inputs.includes(input)) node.onInputRemoved?.(slot, input) }) - for (const slot of promotedSlots) - disconnectOrphanedPromotion(node.graph, slot, hosts) + if (isSubgraph(graph)) + for (const input of promotedInputs) + disconnectOrphanedPromotion(graph, graph.inputs.indexOf(input), hosts) return true } @@ -415,14 +421,32 @@ function disconnectOrphanedPromotion( slot: number, hosts: PromotionHostLookup ) { - if (!isSubgraph(graph) || graph.inputs[slot]?.linkIds.length) return + if (!isSubgraph(graph) || graph.inputs[slot]?.linkIds.length !== 0) return + const input = graph.inputs[slot] for (const host of hosts(graph)) { + removeFloatingHostLinks(host, slot) const link = host.graph && inputLink(host.graph, host.id, slot) if (!link) continue host.disconnectInput(slot) if (link.origin_id === SUBGRAPH_INPUT_ID) disconnectOrphanedPromotion(host.graph, link.origin_slot, hosts) } + graph.removeInput(input) + if (!graph.inputs.includes(input)) removeFloatingLinksFrom(graph, slot) +} + +function removeFloatingLinksFrom(graph: Subgraph, slot: number) { + for (const link of graph.floatingLinks.values()) { + if (link.origin_id !== SUBGRAPH_INPUT_ID) continue + if (link.origin_slot === slot) graph.removeFloatingLink(link) + else if (link.origin_slot > slot) link.origin_slot-- + } +} + +function removeFloatingHostLinks(host: SubgraphNode, slot: number) { + for (const link of host.graph?.floatingLinks.values() ?? []) + if (link.target_id === host.id && link.target_slot === slot) + host.graph?.removeFloatingLink(link) } class DynamicGroupNoticeWidget extends VueOnlyWidget {