Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 73 additions & 1 deletion src/core/graph/widgets/dynamicGroupWidget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ describe('DynamicGroup widgets', () => {
).toBe(true)
const outerInput = outerHost.inputs[0]
expect(promotedInputWidget(outerInput)?.label).toBe('LoRA #2 strength')
return { widget, innerHost, outerHost, outerSubgraph, outerInput }
return { node, widget, innerHost, outerHost, outerSubgraph, outerInput }
}

it.for([
Expand Down Expand Up @@ -472,6 +472,78 @@ describe('DynamicGroup widgets', () => {
await vi.waitFor(() => expect(promotedInputWidget(outerInput)).toBeNull())
})

it('disconnects the deleted row at the outer host while keeping the next row connected', async () => {
const { node, widget, innerHost, outerHost, outerInput } =
setupTwiceDeepPromotion()
const graph = innerHost.subgraph.rootGraph
widget('loras').value = 3
widget('loras.2.lora_name').value = 'C'
widget('loras.2.strength').value = 0.37
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)
const survivingInput = outerHost.inputs[1]
const otherHost = createTestSubgraphNode(outerHost.subgraph)
graph.add(otherHost)
const source = new LGraphNode('Strength source')
source.addOutput('strength', 'FLOAT')
graph.add(source)
const removed = source.connect(0, outerHost, 0)
const otherRemoved = source.connect(0, otherHost, 0)
const retained = source.connect(0, outerHost, 1)
assert.exists(removed)
assert.exists(otherRemoved)
assert.exists(retained)

widget('loras.1').callback?.(undefined)

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()
assert.exists(survivingInput.link)
expect(graph.getLink(survivingInput.link)).toBe(retained)
expect(promotedInputWidget(survivingInput)?.value).toBe(0.37)
expect(promotedInputWidget(survivingInput)?.label).toBe('LoRA #2 strength')
expect(widget('loras.1.lora_name').value).toBe('C')
expect(widget('loras.1.strength').value).toBe(0.37)
})

it('keeps the outer connection when another node still consumes the promoted input', () => {
const { widget, innerHost, outerHost, outerInput } =
setupTwiceDeepPromotion()
const graph = innerHost.subgraph.rootGraph
const other = new LGraphNode('Another strength consumer')
const input = other.addInput('strength', 'FLOAT')
innerHost.subgraph.add(other)
const internal = innerHost.subgraph.inputNode.slots[0].connect(input, other)
const source = new LGraphNode('Strength source')
source.addOutput('strength', 'FLOAT')
graph.add(source)
const external = source.connect(0, outerHost, 0)
assert.exists(internal)
assert.exists(external)

widget('loras.1').callback?.(undefined)

assert.exists(outerInput.link)
assert.exists(input.link)
expect(graph.getLink(outerInput.link)).toBe(external)
expect(innerHost.subgraph.getLink(input.link)).toBe(internal)
expect(innerHost.subgraph.inputs[0].linkIds).toEqual([internal.id])
expect(widget('loras').value).toBe(1)
})

it.for([
{ label: 'LoRA #2 strength', expected: 'LoRA 1행 strength' },
{ label: 'My strength', expected: 'My strength' }
Expand Down
5 changes: 3 additions & 2 deletions src/core/graph/widgets/dynamicGroupWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,10 @@ function disconnectOrphanedPromotion(
if (!isSubgraph(graph) || graph.inputs[slot]?.linkIds.length) return
for (const host of hosts(graph)) {
const link = host.graph && inputLink(host.graph, host.id, slot)
if (link?.origin_id !== SUBGRAPH_INPUT_ID) continue
if (!link) continue
host.disconnectInput(slot)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low — Without the origin_id === SUBGRAPH_INPUT_ID guard, deleting a row now also cuts links from ordinary upstream nodes into the orphaned host slot, on every host instance that hosts() returns. The new test shows this is intended. One side effect is easy to miss, though: if the upstream node is a legacy PrimitiveNode, losing its last link fires onLastDisconnect(), which drops its widgets and stored value, and only undo brings them back. Confirm that this is acceptable and that the cuts across instances land in a single undo step. Otherwise, skip or warn on sources that hold user-entered values. Raised by 2 of 6 reviewers (claude-opus-5-5-xhigh adversarial, claude-opus-5-5-xhigh edge-case).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disconnection uses the existing LiteGraph input-disconnect lifecycle, including PrimitiveNode cleanup when its last consumer is removed. Keeping that orphaned wire would retain a connection to a deleted row. cda28cd extends the regression to two hosts sharing the subgraph definition and verifies that both orphaned wires are removed within the existing single beforeChange/afterChange boundary, while another row’s wire/value and shared surviving consumers are retained. All44 targeted tests pass. This test does not claim a separate end-to-end Undo/Redo proof.

disconnectOrphanedPromotion(host.graph, link.origin_slot, hosts)
if (link.origin_id === SUBGRAPH_INPUT_ID)
disconnectOrphanedPromotion(host.graph, link.origin_slot, hosts)
}
}

Expand Down
Loading