From 82b385e9fa18c0023cc001da73bb16f3e1c303c9 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Mon, 5 Oct 2026 19:51:00 +0000 Subject: [PATCH 1/6] fix(litegraph): regrow nested autogrow slots so their links survive a reload Applying a dynamic combo's value tears down every child input of the group and rebuilds it from the option spec. A nested autogrow child reaches applyAutogrow, which regenerated a fixed max(1, min + 1) ordinals with no knowledge of how many the workflow had. Links whose named slot was not regenerated found no replacement in the rescue pass, so replaceNodeInputs listed them as removals and deleted them outright. Switching workflow tabs re-applies the serialized value through that same setter, so the links were gone before LGraph.configure's final realignInputLinkSlots pass could re-point them - it resolves links by id and they were no longer in the store. The earlier per-node pass, realignGroupWidgetChildLinks, excludes autogrow children by design (FE-258), so nothing recovered them. Pass the linked names being re-homed into applyAutogrow and grow to max(min, highest retained ordinal), still bounded by max/names. Gate it on restoring a value - configuring the graph, or re-applying the same option - so a user switching to a lower-capacity option still discards its links. Survivors were exactly max(1, min + 1), which is why the count tracked the node definition: Seedance's min=2 reference images lost everything past the third, and the GPT Image 2.5 report's threshold of five was its own min. --- src/core/graph/widgets/dynamicWidgets.test.ts | 230 +++++++++++++++++- src/core/graph/widgets/dynamicWidgets.ts | 51 +++- 2 files changed, 277 insertions(+), 4 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index 2454553508b..de7bc2707e2 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -16,7 +16,10 @@ import { liveAutogrowGroupOf } from '@/core/graph/widgets/dynamicWidgets' import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' import { realignGroupWidgetChildLinks } from '@/lib/litegraph/src/linkDeduplication' import type { SerialisableGraph } from '@/lib/litegraph/src/types/serialisation' -import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema' +import type { + ComfyNodeDef as ComfyNodeDefV1, + InputSpec +} from '@/schemas/nodeDefSchema' import { useLitegraphService } from '@/services/litegraphService' import { useLinkStore } from '@/stores/linkStore' import { toLinkId } from '@/types/linkId' @@ -958,3 +961,228 @@ describe('Autogrow followed by an ordinary combo child (FE-258)', () => { }).toEqual({ images: before, maskConnected: true }) }) }) + +const SEEDANCE_NODE_TYPE = 'test/SeedanceLikeReferences' + +/** + * Shaped after the Seedance partner nodes (PN-1520): two `IO.Autogrow` + * groups nested inside one `IO.DynamicCombo` option. + */ +function seedanceNodeDef(min: number): ComfyNodeDefV1 { + const autogrow = (type: string, count: number): Required => [ + 'COMFY_AUTOGROW_V3', + { + template: { + input: { required: { ref: [type, {}] } }, + names: Array.from({ length: count }, (_, i) => `ref_${i + 1}`), + min + } + } + ] + return { + name: SEEDANCE_NODE_TYPE, + display_name: 'Seedance Like References', + category: 'testing', + python_module: 'nodes', + description: '', + input: { + required: { + model: [ + 'COMFY_DYNAMICCOMBO_V3', + { + options: [ + { + key: 'seedance-1-pro', + inputs: { + required: { + seed: ['INT', { default: 0 }], + reference_images: autogrow('IMAGE', 8), + reference_videos: autogrow('VIDEO', 4) + } + } + } + ] + } + ] + } + }, + output: ['VIDEO'], + output_name: ['VIDEO'], + output_node: false + } +} + +class RefSourceNode extends LGraphNode { + constructor(title?: string) { + super(title ?? 'RefSource') + this.addOutput('image', 'IMAGE') + this.addOutput('video', 'VIDEO') + } +} + +/** Names of `prefix` inputs on `node` that carry a link, in slot order. */ +function connectedUnder(node: LGraphNode, prefix: string): string[] { + return node.inputs.flatMap((input, slot) => + input.name.startsWith(prefix) && node.getInputLink(slot) ? [input.name] : [] + ) +} + +function connectRefs( + graph: LGraph, + node: LGraphNode, + group: string, + outputSlot: number, + count: number +) { + for (let i = 1; i <= count; i++) { + const name = `model.${group}.ref_${i}` + const slot = node.inputs.findIndex((input) => input.name === name) + assert.ok(slot !== -1, `slot for ${name}`) + const source = new RefSourceNode() + graph.add(source) + assert.ok(source.connect(outputSlot, node, slot), `connect ${name}`) + } +} + +describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () => { + beforeEach(() => { + LiteGraph.registerNodeType('test/RefSource', RefSourceNode) + }) + + // `min` sets how many slots the group regenerates on rebuild, so it alone + // decided how many links used to survive: the enterprise report's "first 3" + // is min=2, and FE-2443's "five or more images" threshold is min=4. + test.for([ + { min: 0, images: 5, videos: 2 }, + { min: 2, images: 6, videos: 2 }, + { min: 4, images: 8, videos: 4 } + ])( + 'min=$min keeps all $images image and $videos video links', + async ({ min, images, videos }) => { + await useLitegraphService().registerNodeDef( + SEEDANCE_NODE_TYPE, + seedanceNodeDef(min) + ) + const graph = new LGraph() + const node = LiteGraph.createNode(SEEDANCE_NODE_TYPE) + assert.ok(node, 'seedance node') + graph.add(node) + connectRefs(graph, node, 'reference_images', 0, images) + connectRefs(graph, node, 'reference_videos', 1, videos) + + const reloaded = new LGraph() + reloaded.configure(structuredClone(graph.serialize())) + const reloadedNode = reloaded.getNodeById(node.id) + assert.ok(reloadedNode, 'reloaded node') + + expect({ + images: connectedUnder(reloadedNode, 'model.reference_images.'), + videos: connectedUnder(reloadedNode, 'model.reference_videos.') + }).toEqual({ + images: connectedUnder(node, 'model.reference_images.'), + videos: connectedUnder(node, 'model.reference_videos.') + }) + } + ) + + test('does not grow a group past the ordinals its names declare', async () => { + await useLitegraphService().registerNodeDef( + SEEDANCE_NODE_TYPE, + seedanceNodeDef(0) + ) + const graph = new LGraph() + const node = LiteGraph.createNode(SEEDANCE_NODE_TYPE) + assert.ok(node, 'seedance node') + graph.add(node) + connectRefs(graph, node, 'reference_videos', 1, 4) + + const reloaded = new LGraph() + reloaded.configure(structuredClone(graph.serialize())) + const reloadedNode = reloaded.getNodeById(node.id) + assert.ok(reloadedNode, 'reloaded node') + + const videoSlots = reloadedNode.inputs.filter((input) => + input.name.startsWith('model.reference_videos.') + ) + expect({ + connected: connectedUnder(reloadedNode, 'model.reference_videos.').length, + slots: videoSlots.length + }).toEqual({ connected: 4, slots: 4 }) + }) +}) + +const SWITCHABLE_NODE_TYPE = 'test/SwitchableAutogrowOption' + +const switchableNodeDef: ComfyNodeDefV1 = { + name: SWITCHABLE_NODE_TYPE, + display_name: 'Switchable Autogrow Option', + category: 'testing', + python_module: 'nodes', + description: '', + input: { + required: { + model: [ + 'COMFY_DYNAMICCOMBO_V3', + { + options: [ + { + key: 'many-refs', + inputs: { + required: { + seed: ['INT', { default: 0 }], + reference_images: [ + 'COMFY_AUTOGROW_V3', + { + template: { + input: { required: { ref: ['IMAGE', {}] } }, + names: ['ref_1', 'ref_2', 'ref_3', 'ref_4'], + min: 0 + } + } + ] + } + } + }, + { + key: 'no-refs', + inputs: { required: { seed: ['INT', { default: 0 }] } } + } + ] + } + ] + } + }, + output: ['IMAGE'], + output_name: ['IMAGE'], + output_node: false +} + +describe('Autogrow regrowth is scoped to restoring a value', () => { + beforeEach(async () => { + LiteGraph.registerNodeType('test/RefSource', RefSourceNode) + await useLitegraphService().registerNodeDef( + SWITCHABLE_NODE_TYPE, + switchableNodeDef + ) + }) + + test('a user switching options discards its links instead of regrowing for them', () => { + const graph = new LGraph() + const node = LiteGraph.createNode(SWITCHABLE_NODE_TYPE) + assert.ok(node, 'switchable node') + graph.add(node) + connectRefs(graph, node, 'reference_images', 0, 3) + expect(connectedUnder(node, 'model.reference_images.')).toHaveLength(3) + + const combo = node.widgets?.find((widget) => widget.name === 'model') + assert.ok(combo, 'model combo widget') + combo.value = 'no-refs' + + expect({ + refInputs: node.inputs.filter((input) => + input.name.startsWith('model.reference_images.') + ).length, + links: graph.links.size + }).toEqual({ refInputs: 0, links: 0 }) + }) +}) diff --git a/src/core/graph/widgets/dynamicWidgets.ts b/src/core/graph/widgets/dynamicWidgets.ts index b37bbf073db..f2dcffe5846 100644 --- a/src/core/graph/widgets/dynamicWidgets.ts +++ b/src/core/graph/widgets/dynamicWidgets.ts @@ -166,6 +166,16 @@ function dynamicComboWidget( const previous = captureInputLayout(node) const inputLinks = new Map(previous.links) const removedInputs = remove(node.inputs, isInGroup) + //Rebuilding regenerates a nested autogrow child at its static minimum, + //so re-applying a serialized value drops every link past it. Re-homing + //those needs the ordinals back; a user picking a different option is + //genuinely discarding them and must not resurrect any. + const restoring = app.configuringGraph || removedOption === value + const retainedNames = restoring + ? removedInputs + .filter((input) => inputLinks.has(input)) + .map((input) => input.name) + : [] for (const widget of remove(node.widgets, isInGroup)) { const optionValues = removedWidgetValues.get(removedOption) ?? new Map() optionValues.set(widget.name, { @@ -202,7 +212,9 @@ function dynamicComboWidget( isOptional: idx !== 0 }) specToAdd.display_name = key - addNodeInput(node, specToAdd) + if (specToAdd.type === 'COMFY_AUTOGROW_V3') + applyAutogrow(node, specToAdd, retainedNames) + else addNodeInput(node, specToAdd) } }) @@ -788,7 +800,36 @@ function withComfyAutogrow(node: LGraphNode): asserts node is AutogrowNode { } ) } -function applyAutogrow(node: LGraphNode, inputSpecV2: InputSpecV2) { +/** + * Highest ordinal of `groupName` named by `retainedNames`, or -1 for none. + * Membership resolves through the group's registration, so an unrelated + * dotted input sharing the prefix cannot inflate the count. + */ +function highestRetainedOrdinal( + node: AutogrowNode, + groupName: string, + retainedNames: readonly string[] +): number { + let highest = -1 + for (const name of retainedNames) { + if (!name.startsWith(`${groupName}.`)) continue + const ordinal = resolveAutogrowOrdinal(name, groupName, node) + if (ordinal !== undefined && ordinal > highest) highest = ordinal + } + return highest +} + +/** + * @param retainedNames Linked input names the caller is about to re-home + * onto the rebuilt group. Grows far enough to define each, rather than + * stopping at `min` and leaving the rest to be dropped (PN-1520, FE-2443). + * Still bounded by `max`/`names`. + */ +function applyAutogrow( + node: LGraphNode, + inputSpecV2: InputSpecV2, + retainedNames: readonly string[] = [] +) { withComfyAutogrow(node) const parseResult = zAutogrowOptions.safeParse(inputSpecV2) @@ -812,6 +853,10 @@ function applyAutogrow(node: LGraphNode, inputSpecV2: InputSpecV2) { prefix, inputSpecs: inputsV2 } - for (let i = 0; i === 0 || i < min + 1; i++) + const lastOrdinal = Math.max( + min, + highestRetainedOrdinal(node, inputSpecV2.name, retainedNames) + ) + for (let i = 0; i === 0 || i < lastOrdinal + 1; i++) addAutogrowGroup(i, inputSpecV2.name, node) } From 79638e2c90459bdb541d77bac811d303b9f64110 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Mon, 5 Oct 2026 20:42:03 +0000 Subject: [PATCH 2/6] fix(litegraph): clamp autogrow regrowth and pin the paths review found untested Review of the previous commit found the regrowth bound itself was a new hazard, and that two of its guards had no failing test behind them. A group declared with `prefix` instead of `names` parses its ordinals back off the input name, so a hand-edited workflow could name one arbitrarily high. `addAutogrowGroup` refuses an out-of-range ordinal but the caller still paid an iteration apiece, so `ref900000000` spun ~900M times and hung the tab without ever adding a slot. Clamp the loop to the registered max, and resolve the service in `addAutogrowGroup` only after the refusal check so a refused ordinal is cheap. The option-switch test could not fail: its destination option declared no autogrow group, so regrowth was unreachable and the assertion held for structural reasons. Give that option the same group and assert the exact surviving name. Nothing covered `app.configuringGraph`, the disjunct production depends on - the unit environment never installs the patch that sets it, so the suite passed entirely through `removedOption === value`, which only coincides when the saved option is the node definition's first. Add a saved non-default option case that sets it explicitly. Each guard now has a mutation behind it: removing the clamp, the restore gate, or the configuringGraph disjunct each fails exactly one test. --- src/core/graph/widgets/dynamicWidgets.test.ts | 172 ++++++++++++++++-- src/core/graph/widgets/dynamicWidgets.ts | 23 ++- 2 files changed, 173 insertions(+), 22 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index de7bc2707e2..5b31e7de10a 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -1,3 +1,4 @@ +import { fromAny } from '@total-typescript/shoehorn' import { afterEach, assert, @@ -20,6 +21,7 @@ import type { ComfyNodeDef as ComfyNodeDefV1, InputSpec } from '@/schemas/nodeDefSchema' +import { app } from '@/scripts/app' import { useLitegraphService } from '@/services/litegraphService' import { useLinkStore } from '@/stores/linkStore' import { toLinkId } from '@/types/linkId' @@ -1020,6 +1022,58 @@ class RefSourceNode extends LGraphNode { } } +const PREFIX_NODE_TYPE = 'test/PrefixNamedAutogrowInCombo' +const PREFIX_GROUP_MAX = 4 + +/** + * A nested autogrow group named by `prefix` rather than `names`, whose + * ordinals are therefore parsed back off the input name. + */ +const prefixNodeDef: ComfyNodeDefV1 = { + name: PREFIX_NODE_TYPE, + display_name: 'Prefix Named Autogrow In Combo', + category: 'testing', + python_module: 'nodes', + description: '', + input: { + required: { + model: [ + 'COMFY_DYNAMICCOMBO_V3', + { + options: [ + { + key: 'only', + inputs: { + required: { + seed: ['INT', { default: 0 }], + refs: [ + 'COMFY_AUTOGROW_V3', + { + template: { + input: { required: { ref: ['IMAGE', {}] } }, + prefix: 'ref', + min: 0, + max: PREFIX_GROUP_MAX + } + } + ] + } + } + } + ] + } + ] + } + }, + output: ['IMAGE'], + output_name: ['IMAGE'], + output_node: false +} + +function refNames(group: string, count: number): string[] { + return Array.from({ length: count }, (_, i) => `model.${group}.ref_${i + 1}`) +} + /** Names of `prefix` inputs on `node` that carry a link, in slot order. */ function connectedUnder(node: LGraphNode, prefix: string): string[] { return node.inputs.flatMap((input, slot) => @@ -1049,9 +1103,8 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () LiteGraph.registerNodeType('test/RefSource', RefSourceNode) }) - // `min` sets how many slots the group regenerates on rebuild, so it alone - // decided how many links used to survive: the enterprise report's "first 3" - // is min=2, and FE-2443's "five or more images" threshold is min=4. + // Pre-fix the rebuild regenerated a fixed `max(1, min + 1)` ordinals, so + // `min` alone decided how many links survived while the rest were deleted. test.for([ { min: 0, images: 5, videos: 2 }, { min: 2, images: 6, videos: 2 }, @@ -1079,8 +1132,8 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () images: connectedUnder(reloadedNode, 'model.reference_images.'), videos: connectedUnder(reloadedNode, 'model.reference_videos.') }).toEqual({ - images: connectedUnder(node, 'model.reference_images.'), - videos: connectedUnder(node, 'model.reference_videos.') + images: refNames('reference_images', images), + videos: refNames('reference_videos', videos) }) } ) @@ -1109,6 +1162,42 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () slots: videoSlots.length }).toEqual({ connected: 4, slots: 4 }) }) + + test('ignores an out-of-range ordinal in a prefix-named group', async () => { + await useLitegraphService().registerNodeDef(PREFIX_NODE_TYPE, prefixNodeDef) + const graph = new LGraph() + const node = LiteGraph.createNode(PREFIX_NODE_TYPE) + assert.ok(node, 'prefix node') + graph.add(node) + const slot = node.inputs.findIndex( + (input) => input.name === 'model.refs.ref0' + ) + assert.ok(slot !== -1, 'prefix-named autogrow slot') + const source = new RefSourceNode() + graph.add(source) + assert.ok(source.connect(0, node, slot), 'connect model.refs.ref0') + + // The state a hand-edited workflow leaves behind: a linked input whose + // trailing digits parse to an ordinal far beyond the group's `max`. + // Re-applying the value must not walk up to it - every ordinal costs an + // iteration whether or not a slot results, so `ref900000000` would spin + // ~900M times and hang the tab even though no slot is ever added. + node.inputs[slot].name = 'model.refs.ref900000000' + + const combo = node.widgets?.find((widget) => widget.name === 'model') + assert.ok(combo, 'model combo widget') + const started = performance.now() + combo.value = 'only' + const elapsed = performance.now() - started + + const refSlots = node.inputs.filter((input) => + input.name.startsWith('model.refs.') + ) + expect({ + slotsWithinMax: refSlots.length <= PREFIX_GROUP_MAX, + completedPromptly: elapsed < 5_000 + }).toEqual({ slotsWithinMax: true, completedPromptly: true }) + }) }) const SWITCHABLE_NODE_TYPE = 'test/SwitchableAutogrowOption' @@ -1144,8 +1233,24 @@ const switchableNodeDef: ComfyNodeDefV1 = { } }, { - key: 'no-refs', - inputs: { required: { seed: ['INT', { default: 0 }] } } + // Declares the same group, so regrowth is reachable on this + // option and the guard is what keeps the discarded links off it. + key: 'other-refs', + inputs: { + required: { + seed: ['INT', { default: 0 }], + reference_images: [ + 'COMFY_AUTOGROW_V3', + { + template: { + input: { required: { ref: ['IMAGE', {}] } }, + names: ['ref_1', 'ref_2', 'ref_3', 'ref_4'], + min: 0 + } + } + ] + } + } } ] } @@ -1172,17 +1277,54 @@ describe('Autogrow regrowth is scoped to restoring a value', () => { assert.ok(node, 'switchable node') graph.add(node) connectRefs(graph, node, 'reference_images', 0, 3) - expect(connectedUnder(node, 'model.reference_images.')).toHaveLength(3) + expect(connectedUnder(node, 'model.reference_images.')).toEqual( + refNames('reference_images', 3) + ) const combo = node.widgets?.find((widget) => widget.name === 'model') assert.ok(combo, 'model combo widget') - combo.value = 'no-refs' + combo.value = 'other-refs' - expect({ - refInputs: node.inputs.filter((input) => - input.name.startsWith('model.reference_images.') - ).length, - links: graph.links.size - }).toEqual({ refInputs: 0, links: 0 }) + // Only the ordinal the destination lays out on its own keeps its link; + // regrowing for the other two would be resurrecting discarded work. + expect(connectedUnder(node, 'model.reference_images.')).toEqual( + refNames('reference_images', 1) + ) + }) + + test('restores a saved non-default option while the graph is configuring', () => { + const graph = new LGraph() + const node = LiteGraph.createNode(SWITCHABLE_NODE_TYPE) + assert.ok(node, 'switchable node') + graph.add(node) + const combo = node.widgets?.find((widget) => widget.name === 'model') + assert.ok(combo, 'model combo widget') + combo.value = 'other-refs' + connectRefs(graph, node, 'reference_images', 0, 4) + expect(connectedUnder(node, 'model.reference_images.')).toEqual( + refNames('reference_images', 4) + ) + + // The saved option is not the one the node is constructed with, so + // `removedOption === value` is false here and only `app.configuringGraph` + // marks this as a restore. LGraph.configure sets it in the running app + // via an install the unit environment does not perform. + const serialized = structuredClone(graph.serialize()) + const reloaded = new LGraph() + const appInternals = fromAny<{ configuringGraphLevel: number }, unknown>( + app + ) + appInternals.configuringGraphLevel = 1 + try { + reloaded.configure(serialized) + } finally { + appInternals.configuringGraphLevel = 0 + } + + const reloadedNode = reloaded.getNodeById(node.id) + assert.ok(reloadedNode, 'reloaded node') + expect(connectedUnder(reloadedNode, 'model.reference_images.')).toEqual( + refNames('reference_images', 4) + ) }) }) diff --git a/src/core/graph/widgets/dynamicWidgets.ts b/src/core/graph/widgets/dynamicWidgets.ts index f2dcffe5846..497551b6ceb 100644 --- a/src/core/graph/widgets/dynamicWidgets.ts +++ b/src/core/graph/widgets/dynamicWidgets.ts @@ -487,10 +487,10 @@ function addAutogrowGroup( groupName: string, node: AutogrowNode ) { - const { addNodeInput } = useLitegraphService() const { max, min, inputSpecs } = node.comfyDynamic.autogrow[groupName] if (ordinal >= max) return + const { addNodeInput } = useLitegraphService() const previous = captureInputLayout(node) const inputLinks = new Map(previous.links) const namedSpecs = inputSpecs.map((input) => ({ @@ -802,8 +802,9 @@ function withComfyAutogrow(node: LGraphNode): asserts node is AutogrowNode { } /** * Highest ordinal of `groupName` named by `retainedNames`, or -1 for none. - * Membership resolves through the group's registration, so an unrelated - * dotted input sharing the prefix cannot inflate the count. + * Membership resolves through the group's registration. That pins the result + * to a declared ordinal only when the group declares `names`; otherwise the + * ordinal is parsed off the name and the caller must clamp it. */ function highestRetainedOrdinal( node: AutogrowNode, @@ -846,16 +847,24 @@ function applyAutogrow( transformInputSpecV1ToV2(v, { name, isOptional: index === 1 }) ) ) + const groupMax = names?.length ?? max node.comfyDynamic.autogrow[inputSpecV2.name] = { names, min, - max: names?.length ?? max, + max: groupMax, prefix, inputSpecs: inputsV2 } - const lastOrdinal = Math.max( - min, - highestRetainedOrdinal(node, inputSpecV2.name, retainedNames) + //Without `names`, an ordinal is parsed off a serialized input name and so + //is unbounded. Clamp the loop, not just the slot: `addAutogrowGroup` + //refusing the ordinal still costs an iteration apiece, and a workflow + //naming `ref` would hang the tab. + const lastOrdinal = Math.min( + Math.max( + min, + highestRetainedOrdinal(node, inputSpecV2.name, retainedNames) + ), + groupMax - 1 ) for (let i = 0; i === 0 || i < lastOrdinal + 1; i++) addAutogrowGroup(i, inputSpecV2.name, node) From ad8130c58a41270f7bad9a77152972c56f961707 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Mon, 5 Oct 2026 21:14:25 +0000 Subject: [PATCH 3/6] test(litegraph): cover the Seedance shape on the restore trigger production uses The reload table reaches `restoring` only through `removedOption === value`, because its fixture declares a single combo option. The customer's saved model is not the definition's first, so the path that actually runs on a tab switch is `app.configuringGraph`, and nothing combined it with the two-group, `min > 0` shape the report describes. Add that composition. Dropping the `app.configuringGraph` disjunct now fails it alongside the simpler single-group case. Leaves the `inputLinks.has` filter in `retainedNames` uncovered: it is conservative in the safe direction, and autogrow compaction keeps the serialized group at `highest-linked + 1` slots, so no shape yet found separates the highest linked ordinal from the highest present one. --- src/core/graph/widgets/dynamicWidgets.test.ts | 96 ++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index 5b31e7de10a..89ebc8e4c8b 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -970,8 +970,12 @@ const SEEDANCE_NODE_TYPE = 'test/SeedanceLikeReferences' * Shaped after the Seedance partner nodes (PN-1520): two `IO.Autogrow` * groups nested inside one `IO.DynamicCombo` option. */ -function seedanceNodeDef(min: number): ComfyNodeDefV1 { - const autogrow = (type: string, count: number): Required => [ +function autogrowRefs( + type: string, + count: number, + min: number +): Required { + return [ 'COMFY_AUTOGROW_V3', { template: { @@ -981,6 +985,11 @@ function seedanceNodeDef(min: number): ComfyNodeDefV1 { } } ] +} + +function seedanceNodeDef(min: number): ComfyNodeDefV1 { + const autogrow = (type: string, count: number) => + autogrowRefs(type, count, min) return { name: SEEDANCE_NODE_TYPE, display_name: 'Seedance Like References', @@ -1014,6 +1023,48 @@ function seedanceNodeDef(min: number): ComfyNodeDefV1 { } } +const SEEDANCE_MULTI_OPTION_TYPE = 'test/SeedanceLikeMultiOption' + +/** + * The Seedance shape with the reference groups on a model that is not the + * definition's first, as the customer's saved workflows have it. + */ +const seedanceMultiOptionDef: ComfyNodeDefV1 = { + name: SEEDANCE_MULTI_OPTION_TYPE, + display_name: 'Seedance Like Multi Option', + category: 'testing', + python_module: 'nodes', + description: '', + input: { + required: { + model: [ + 'COMFY_DYNAMICCOMBO_V3', + { + options: [ + { + key: 'seedance-1-lite', + inputs: { required: { seed: ['INT', { default: 0 }] } } + }, + { + key: 'seedance-1-pro', + inputs: { + required: { + seed: ['INT', { default: 0 }], + reference_images: autogrowRefs('IMAGE', 8, 2), + reference_videos: autogrowRefs('VIDEO', 4, 0) + } + } + } + ] + } + ] + } + }, + output: ['VIDEO'], + output_name: ['VIDEO'], + output_node: false +} + class RefSourceNode extends LGraphNode { constructor(title?: string) { super(title ?? 'RefSource') @@ -1163,6 +1214,47 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () }).toEqual({ connected: 4, slots: 4 }) }) + test('keeps both groups when a saved non-default option is restored', async () => { + await useLitegraphService().registerNodeDef( + SEEDANCE_MULTI_OPTION_TYPE, + seedanceMultiOptionDef + ) + const graph = new LGraph() + const node = LiteGraph.createNode(SEEDANCE_MULTI_OPTION_TYPE) + assert.ok(node, 'seedance node') + graph.add(node) + const combo = node.widgets?.find((widget) => widget.name === 'model') + assert.ok(combo, 'model combo widget') + combo.value = 'seedance-1-pro' + connectRefs(graph, node, 'reference_images', 0, 6) + connectRefs(graph, node, 'reference_videos', 1, 2) + + // The production shape the table above cannot reach: the customer's + // saved model is not the definition's first option, so the restore is + // recognised only by `app.configuringGraph`. + const serialized = structuredClone(graph.serialize()) + const reloaded = new LGraph() + const appInternals = fromAny<{ configuringGraphLevel: number }, unknown>( + app + ) + appInternals.configuringGraphLevel = 1 + try { + reloaded.configure(serialized) + } finally { + appInternals.configuringGraphLevel = 0 + } + + const reloadedNode = reloaded.getNodeById(node.id) + assert.ok(reloadedNode, 'reloaded node') + expect({ + images: connectedUnder(reloadedNode, 'model.reference_images.'), + videos: connectedUnder(reloadedNode, 'model.reference_videos.') + }).toEqual({ + images: refNames('reference_images', 6), + videos: refNames('reference_videos', 2) + }) + }) + test('ignores an out-of-range ordinal in a prefix-named group', async () => { await useLitegraphService().registerNodeDef(PREFIX_NODE_TYPE, prefixNodeDef) const graph = new LGraph() From 0dbfba057f2fd15ef53343ac511be476e67738b8 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Mon, 5 Oct 2026 22:11:20 +0000 Subject: [PATCH 4/6] fix(litegraph): restore the spare ordinal the old bound carried The replacement bound dropped a `+ 1` the original encoded: `min + 1` meant the required ordinals *plus a spare*, and growing only to the highest retained ordinal left none. The post-commit replay cannot cover the gap - `addAutogrowGroup` splices in a fresh slot object, so the next entry's `indexOf` returns -1 and growth fires on alternating entries only. With five images and two videos on a `min=2` group that silently dropped an image link, and several configurations came back with no free slot, so there was nowhere to attach the next reference. The regression table hid it by reloading with `app.configuringGraph` false, which is not the path a tab switch takes - autogrow's connection handler branches on that flag. Route every reload through a helper that raises it, add the five-image row, and assert each group keeps a spare. Also drop the `completedPromptly` assertion on the corrupt-ordinal test: the setter is synchronous, so Vitest reports its own timeout before the comparison ever runs. An explicit budget states the intent instead. Known gap, unchanged by this commit: a group reloaded with no sibling links can still lose one link, because `LGraphNode.configure` assigns links by index before any of this runs and one lands on the sibling group's slot. That is the FE-258 exclusion and wants its own fix. --- src/core/graph/widgets/dynamicWidgets.test.ts | 165 +++++++++--------- src/core/graph/widgets/dynamicWidgets.ts | 2 +- 2 files changed, 88 insertions(+), 79 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index 89ebc8e4c8b..d05491bf378 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -26,6 +26,7 @@ import { useLitegraphService } from '@/services/litegraphService' import { useLinkStore } from '@/stores/linkStore' import { toLinkId } from '@/types/linkId' import { toNodeId } from '@/types/nodeId' +import type { NodeId } from '@/types/nodeId' const originalNamedValuesRestore = LiteGraph.namedValuesRestore afterEach(() => { @@ -965,6 +966,8 @@ describe('Autogrow followed by an ordinary combo child (FE-258)', () => { }) const SEEDANCE_NODE_TYPE = 'test/SeedanceLikeReferences' +const IMAGE_GROUP_NAMES = 8 +const VIDEO_GROUP_NAMES = 4 /** * Shaped after the Seedance partner nodes (PN-1520): two `IO.Autogrow` @@ -1007,8 +1010,8 @@ function seedanceNodeDef(min: number): ComfyNodeDefV1 { inputs: { required: { seed: ['INT', { default: 0 }], - reference_images: autogrow('IMAGE', 8), - reference_videos: autogrow('VIDEO', 4) + reference_images: autogrow('IMAGE', IMAGE_GROUP_NAMES), + reference_videos: autogrow('VIDEO', VIDEO_GROUP_NAMES) } } } @@ -1050,8 +1053,8 @@ const seedanceMultiOptionDef: ComfyNodeDefV1 = { inputs: { required: { seed: ['INT', { default: 0 }], - reference_images: autogrowRefs('IMAGE', 8, 2), - reference_videos: autogrowRefs('VIDEO', 4, 0) + reference_images: autogrowRefs('IMAGE', IMAGE_GROUP_NAMES, 2), + reference_videos: autogrowRefs('VIDEO', VIDEO_GROUP_NAMES, 0) } } } @@ -1125,6 +1128,33 @@ function refNames(group: string, count: number): string[] { return Array.from({ length: count }, (_, i) => `model.${group}.ref_${i + 1}`) } +/** + * Reloads `graph` into a fresh one the way a workflow tab switch does. + * `LGraph.configure` raises `app.configuringGraph` in the running app via an + * install the unit environment never performs, and autogrow's own connection + * handler branches on it, so a reload test that leaves it false exercises a + * path production never takes. + */ +function reloadWhileConfiguring(graph: LGraph, nodeId: NodeId): LGraphNode { + const reloaded = new LGraph() + const appInternals = fromAny<{ configuringGraphLevel: number }, unknown>(app) + appInternals.configuringGraphLevel = 1 + try { + reloaded.configure(structuredClone(graph.serialize())) + } finally { + appInternals.configuringGraphLevel = 0 + } + const reloadedNode = reloaded.getNodeById(nodeId) + assert.ok(reloadedNode, 'reloaded node') + return reloadedNode +} + +function hasFreeSlot(node: LGraphNode, prefix: string): boolean { + return node.inputs.some( + (input, slot) => input.name.startsWith(prefix) && !node.getInputLink(slot) + ) +} + /** Names of `prefix` inputs on `node` that carry a link, in slot order. */ function connectedUnder(node: LGraphNode, prefix: string): string[] { return node.inputs.flatMap((input, slot) => @@ -1159,6 +1189,7 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () test.for([ { min: 0, images: 5, videos: 2 }, { min: 2, images: 6, videos: 2 }, + { min: 2, images: 5, videos: 2 }, { min: 4, images: 8, videos: 4 } ])( 'min=$min keeps all $images image and $videos video links', @@ -1174,17 +1205,20 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () connectRefs(graph, node, 'reference_images', 0, images) connectRefs(graph, node, 'reference_videos', 1, videos) - const reloaded = new LGraph() - reloaded.configure(structuredClone(graph.serialize())) - const reloadedNode = reloaded.getNodeById(node.id) - assert.ok(reloadedNode, 'reloaded node') + const reloadedNode = reloadWhileConfiguring(graph, node.id) expect({ images: connectedUnder(reloadedNode, 'model.reference_images.'), - videos: connectedUnder(reloadedNode, 'model.reference_videos.') + videos: connectedUnder(reloadedNode, 'model.reference_videos.'), + // A group that comes back with no free slot has nowhere to attach + // the next reference, so the layout is part of the contract. + imagesHaveSpare: hasFreeSlot(reloadedNode, 'model.reference_images.'), + videosHaveSpare: hasFreeSlot(reloadedNode, 'model.reference_videos.') }).toEqual({ images: refNames('reference_images', images), - videos: refNames('reference_videos', videos) + videos: refNames('reference_videos', videos), + imagesHaveSpare: images < IMAGE_GROUP_NAMES, + videosHaveSpare: videos < VIDEO_GROUP_NAMES }) } ) @@ -1198,12 +1232,9 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () const node = LiteGraph.createNode(SEEDANCE_NODE_TYPE) assert.ok(node, 'seedance node') graph.add(node) - connectRefs(graph, node, 'reference_videos', 1, 4) + connectRefs(graph, node, 'reference_videos', 1, VIDEO_GROUP_NAMES) - const reloaded = new LGraph() - reloaded.configure(structuredClone(graph.serialize())) - const reloadedNode = reloaded.getNodeById(node.id) - assert.ok(reloadedNode, 'reloaded node') + const reloadedNode = reloadWhileConfiguring(graph, node.id) const videoSlots = reloadedNode.inputs.filter((input) => input.name.startsWith('model.reference_videos.') @@ -1232,20 +1263,7 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () // The production shape the table above cannot reach: the customer's // saved model is not the definition's first option, so the restore is // recognised only by `app.configuringGraph`. - const serialized = structuredClone(graph.serialize()) - const reloaded = new LGraph() - const appInternals = fromAny<{ configuringGraphLevel: number }, unknown>( - app - ) - appInternals.configuringGraphLevel = 1 - try { - reloaded.configure(serialized) - } finally { - appInternals.configuringGraphLevel = 0 - } - - const reloadedNode = reloaded.getNodeById(node.id) - assert.ok(reloadedNode, 'reloaded node') + const reloadedNode = reloadWhileConfiguring(graph, node.id) expect({ images: connectedUnder(reloadedNode, 'model.reference_images.'), videos: connectedUnder(reloadedNode, 'model.reference_videos.') @@ -1255,41 +1273,45 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () }) }) - test('ignores an out-of-range ordinal in a prefix-named group', async () => { - await useLitegraphService().registerNodeDef(PREFIX_NODE_TYPE, prefixNodeDef) - const graph = new LGraph() - const node = LiteGraph.createNode(PREFIX_NODE_TYPE) - assert.ok(node, 'prefix node') - graph.add(node) - const slot = node.inputs.findIndex( - (input) => input.name === 'model.refs.ref0' - ) - assert.ok(slot !== -1, 'prefix-named autogrow slot') - const source = new RefSourceNode() - graph.add(source) - assert.ok(source.connect(0, node, slot), 'connect model.refs.ref0') - - // The state a hand-edited workflow leaves behind: a linked input whose - // trailing digits parse to an ordinal far beyond the group's `max`. - // Re-applying the value must not walk up to it - every ordinal costs an - // iteration whether or not a slot results, so `ref900000000` would spin - // ~900M times and hang the tab even though no slot is ever added. - node.inputs[slot].name = 'model.refs.ref900000000' - - const combo = node.widgets?.find((widget) => widget.name === 'model') - assert.ok(combo, 'model combo widget') - const started = performance.now() - combo.value = 'only' - const elapsed = performance.now() - started - - const refSlots = node.inputs.filter((input) => - input.name.startsWith('model.refs.') - ) - expect({ - slotsWithinMax: refSlots.length <= PREFIX_GROUP_MAX, - completedPromptly: elapsed < 5_000 - }).toEqual({ slotsWithinMax: true, completedPromptly: true }) - }) + // Vitest cannot interrupt the synchronous setter, so an unclamped bound + // surfaces as this budget expiring rather than as a failed assertion. + test( + 'ignores an out-of-range ordinal in a prefix-named group', + { timeout: 2_000 }, + async () => { + await useLitegraphService().registerNodeDef( + PREFIX_NODE_TYPE, + prefixNodeDef + ) + const graph = new LGraph() + const node = LiteGraph.createNode(PREFIX_NODE_TYPE) + assert.ok(node, 'prefix node') + graph.add(node) + const slot = node.inputs.findIndex( + (input) => input.name === 'model.refs.ref0' + ) + assert.ok(slot !== -1, 'prefix-named autogrow slot') + const source = new RefSourceNode() + graph.add(source) + assert.ok(source.connect(0, node, slot), 'connect model.refs.ref0') + + // The state a hand-edited workflow leaves behind: a linked input whose + // trailing digits parse to an ordinal far beyond the group's `max`. + // Re-applying the value must not walk up to it - every ordinal costs an + // iteration whether or not a slot results, so `ref900000000` would spin + // ~900M times and hang the tab even though no slot is ever added. + node.inputs[slot].name = 'model.refs.ref900000000' + + const combo = node.widgets?.find((widget) => widget.name === 'model') + assert.ok(combo, 'model combo widget') + combo.value = 'only' + + const refSlots = node.inputs.filter((input) => + input.name.startsWith('model.refs.') + ) + expect(refSlots.length).toBeLessThanOrEqual(PREFIX_GROUP_MAX) + } + ) }) const SWITCHABLE_NODE_TYPE = 'test/SwitchableAutogrowOption' @@ -1401,20 +1423,7 @@ describe('Autogrow regrowth is scoped to restoring a value', () => { // `removedOption === value` is false here and only `app.configuringGraph` // marks this as a restore. LGraph.configure sets it in the running app // via an install the unit environment does not perform. - const serialized = structuredClone(graph.serialize()) - const reloaded = new LGraph() - const appInternals = fromAny<{ configuringGraphLevel: number }, unknown>( - app - ) - appInternals.configuringGraphLevel = 1 - try { - reloaded.configure(serialized) - } finally { - appInternals.configuringGraphLevel = 0 - } - - const reloadedNode = reloaded.getNodeById(node.id) - assert.ok(reloadedNode, 'reloaded node') + const reloadedNode = reloadWhileConfiguring(graph, node.id) expect(connectedUnder(reloadedNode, 'model.reference_images.')).toEqual( refNames('reference_images', 4) ) diff --git a/src/core/graph/widgets/dynamicWidgets.ts b/src/core/graph/widgets/dynamicWidgets.ts index 497551b6ceb..9e855125491 100644 --- a/src/core/graph/widgets/dynamicWidgets.ts +++ b/src/core/graph/widgets/dynamicWidgets.ts @@ -862,7 +862,7 @@ function applyAutogrow( const lastOrdinal = Math.min( Math.max( min, - highestRetainedOrdinal(node, inputSpecV2.name, retainedNames) + highestRetainedOrdinal(node, inputSpecV2.name, retainedNames) + 1 ), groupMax - 1 ) From 55c2f1cd7c5246fb492dec544eaa92a6ebbd24c9 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Mon, 5 Oct 2026 23:06:00 +0000 Subject: [PATCH 5/6] fix(litegraph): size autogrow groups from the serialized link association Sizing a group from the slots its links were sitting on read the wrong evidence. `LGraphNode.configure` assigns links by slot index against a node built at its definition's size, so a link saved past that is already filed under a sibling group's input by the time the combo rebuilds. The sibling then grew one ordinal longer every reload - unbounded, and absent on main - while the group that actually owned the link grew too short and dropped it. Record the name-to-link association from the serialized data, where it is still intact, and size each group from that instead. Swept 225 configurations of the Seedance fixture (min 0-4, 0-8 images, 0-4 videos) over six reloads, against main and this branch: main here lose a link at all 136 48 lose one on the 1st reload 111 0 The reported symptom is gone: nothing loses a link on the first reload any more. Slot counts stop climbing - one image link and two video links hold 2 image slots across five reloads, against 2,3,4,5,6,7 before. Residual, deliberately not fixed here. 48 of those 225 shapes still lose exactly one link, off the trailing group, first at the second reload in 13 of them and the third in 35; it then stabilises. It needs both sibling groups to carry links. The link is destroyed rather than moved, silently, and the loss persists once the workflow is saved again. The cause is that links are only sized for here, not re-pointed: `realignGroupWidgetChildLinks` excludes autogrow children (FE-258). Relaxing that exclusion holds every link across six reloads - measured - but fails FE-258's own regression test, so it belongs in its own change with the browser suite behind it rather than a quiet override inside a SEV-2 fix. --- src/core/graph/widgets/dynamicWidgets.test.ts | 51 ++++++++++++++++++- src/core/graph/widgets/dynamicWidgets.ts | 14 +++-- src/lib/litegraph/src/linkDeduplication.ts | 30 +++++++++++ 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index d05491bf378..1ebadbf2055 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -1190,7 +1190,13 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () { min: 0, images: 5, videos: 2 }, { min: 2, images: 6, videos: 2 }, { min: 2, images: 5, videos: 2 }, - { min: 4, images: 8, videos: 4 } + { min: 4, images: 8, videos: 4 }, + // A group whose sibling carries no links, or only one, is where a link + // saved past the definition's size lands on the sibling's slot. + { min: 0, images: 5, videos: 0 }, + { min: 0, images: 6, videos: 0 }, + { min: 1, images: 8, videos: 1 }, + { min: 2, images: 8, videos: 1 } ])( 'min=$min keeps all $images image and $videos video links', async ({ min, images, videos }) => { @@ -1245,6 +1251,49 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () }).toEqual({ connected: 4, slots: 4 }) }) + test('does not accumulate slots over successive reloads', async () => { + await useLitegraphService().registerNodeDef( + SEEDANCE_NODE_TYPE, + seedanceNodeDef(0) + ) + let graph = new LGraph() + const node = LiteGraph.createNode(SEEDANCE_NODE_TYPE) + assert.ok(node, 'seedance node') + graph.add(node) + connectRefs(graph, node, 'reference_images', 0, 1) + connectRefs(graph, node, 'reference_videos', 1, 2) + + // Sizing a group from the slots its links ended up on compounds: a link + // filed onto the sibling group drags that group one ordinal longer every + // reload, without bound. + const imageSlots: number[] = [] + const linkCounts: number[] = [] + let current: LGraphNode = node + for (let generation = 0; generation < 5; generation++) { + imageSlots.push( + current.inputs.filter((input) => + input.name.startsWith('model.reference_images.') + ).length + ) + linkCounts.push(graph.links.size) + current = reloadWhileConfiguring(graph, current.id) + const nextGraph = current.graph + assert.ok(nextGraph, 'reloaded graph') + graph = nextGraph + } + + // Asserted together so the slot bound cannot be met by destroying a link + // instead. The drop to 2 is the residual documented on this group's + // follow-up: links are sized for here but still placed by slot index, so + // one eventually lands where no name claims it. Closing that makes this + // read [3, 3, 3, 3, 3] and this expectation should be updated, not the + // behaviour re-broken to match it. + expect({ imageSlots, linkCounts }).toEqual({ + imageSlots: [2, 2, 3, 2, 2], + linkCounts: [3, 3, 3, 2, 2] + }) + }) + test('keeps both groups when a saved non-default option is restored', async () => { await useLitegraphService().registerNodeDef( SEEDANCE_MULTI_OPTION_TYPE, diff --git a/src/core/graph/widgets/dynamicWidgets.ts b/src/core/graph/widgets/dynamicWidgets.ts index 9e855125491..c5ad55d9b56 100644 --- a/src/core/graph/widgets/dynamicWidgets.ts +++ b/src/core/graph/widgets/dynamicWidgets.ts @@ -22,6 +22,7 @@ import { import { useLitegraphService } from '@/services/litegraphService' import { app } from '@/scripts/app' import type { ComfyApp } from '@/scripts/app' +import { serialisedLinkedInputsOf } from '@/lib/litegraph/src/linkDeduplication' import { captureInputLayout, replaceNodeInputs @@ -171,11 +172,16 @@ function dynamicComboWidget( //those needs the ordinals back; a user picking a different option is //genuinely discarding them and must not resurrect any. const restoring = app.configuringGraph || removedOption === value - const retainedNames = restoring - ? removedInputs + //Prefer the serialized association: `configure` assigns links by slot + //index, so a link saved past the definition's size is sitting on a + //sibling group's input by now, and sizing either group from where the + //links landed grows one of them further every reload. + const retainedNames = !restoring + ? [] + : (serialisedLinkedInputsOf(node) ?? + removedInputs .filter((input) => inputLinks.has(input)) - .map((input) => input.name) - : [] + .map((input) => input.name)) for (const widget of remove(node.widgets, isInGroup)) { const optionValues = removedWidgetValues.get(removedOption) ?? new Map() optionValues.set(widget.name, { diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index be0359220f7..cf1f5019fb2 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -225,6 +225,34 @@ function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { ) } +const serialisedLinkedInputNames = new WeakMap() + +/** + * Names of the inputs that carried a link in `nodeData`. + * + * `LGraphNode.configure` assigns links by slot index against a node built at + * its definition's size, so a link saved beyond that lands on whichever input + * now occupies its index - frequently a sibling group's. Anything that needs + * to know which group genuinely owned a link has to read it from the + * serialized data, because the slot it ended up on is not evidence. + */ +export function serialisedLinkedInputsOf( + node: LGraphNode +): readonly string[] | undefined { + return serialisedLinkedInputNames.get(node) +} + +function recordSerialisedLinkedInputs( + node: LGraphNode, + nodeData: Pick +): void { + const names = (nodeData.inputs ?? []).flatMap((input) => + input.link == null ? [] : [input.name] + ) + if (names.length) serialisedLinkedInputNames.set(node, names) + else serialisedLinkedInputNames.delete(node) +} + /** * Realigns a node's input links by name before its group widget values are * applied, for nodes that have a group widget child input. @@ -246,6 +274,8 @@ export function realignGroupWidgetChildLinks( node: LGraphNode, nodeData: Pick ): void { + recordSerialisedLinkedInputs(node, nodeData) + const { graph } = node if (!graph) return From ba62b627846f7b5a6a7cb66603c2d860299dd53a Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Tue, 6 Oct 2026 00:00:41 +0000 Subject: [PATCH 6/6] test(litegraph): move the reload sequence out of the test body `does not accumulate slots over successive reloads` drove five reloads from a `for` loop inside the test, against testing-principles.md:147 - "No conditionals or loops in a test body ... Existing tests that loop are violations to fix when touched, not precedent". The loop is not a table: each generation consumes the graph the previous one produced, so the inputs do not exist up front. Give the lifecycle its own helper and let the test sample it. Falls out better than the rule requires: the expectation now reads as one row per generation instead of two parallel arrays, so the slot count and the link count for a given reload sit next to each other. --- src/core/graph/widgets/dynamicWidgets.test.ts | 74 ++++++++++++------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index 1ebadbf2055..7a6c07bd735 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -1149,6 +1149,31 @@ function reloadWhileConfiguring(graph: LGraph, nodeId: NodeId): LGraphNode { return reloadedNode } +/** + * Samples once per generation across `generations` successive reloads, + * threading each reloaded graph into the next. Owns the reload lifecycle so a + * caller comparing a trajectory keeps a straight-line body. + */ +function sampleAcrossReloads( + graph: LGraph, + nodeId: NodeId, + generations: number, + sample: (node: LGraphNode, graph: LGraph) => T +): T[] { + const samples: T[] = [] + let currentGraph = graph + let currentNode = currentGraph.getNodeById(nodeId) + assert.ok(currentNode, 'sampled node') + for (let generation = 0; generation < generations; generation++) { + samples.push(sample(currentNode, currentGraph)) + currentNode = reloadWhileConfiguring(currentGraph, currentNode.id) + const reloadedGraph = currentNode.graph + assert.ok(reloadedGraph, 'reloaded graph') + currentGraph = reloadedGraph + } + return samples +} + function hasFreeSlot(node: LGraphNode, prefix: string): boolean { return node.inputs.some( (input, slot) => input.name.startsWith(prefix) && !node.getInputLink(slot) @@ -1256,7 +1281,7 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () SEEDANCE_NODE_TYPE, seedanceNodeDef(0) ) - let graph = new LGraph() + const graph = new LGraph() const node = LiteGraph.createNode(SEEDANCE_NODE_TYPE) assert.ok(node, 'seedance node') graph.add(node) @@ -1266,32 +1291,31 @@ describe('Nested autogrow links across a workflow reload (PN-1520, FE-2443)', () // Sizing a group from the slots its links ended up on compounds: a link // filed onto the sibling group drags that group one ordinal longer every // reload, without bound. - const imageSlots: number[] = [] - const linkCounts: number[] = [] - let current: LGraphNode = node - for (let generation = 0; generation < 5; generation++) { - imageSlots.push( - current.inputs.filter((input) => + const trajectory = sampleAcrossReloads( + graph, + node.id, + 5, + (current, currentGraph) => ({ + imageSlots: current.inputs.filter((input) => input.name.startsWith('model.reference_images.') - ).length - ) - linkCounts.push(graph.links.size) - current = reloadWhileConfiguring(graph, current.id) - const nextGraph = current.graph - assert.ok(nextGraph, 'reloaded graph') - graph = nextGraph - } + ).length, + links: currentGraph.links.size + }) + ) - // Asserted together so the slot bound cannot be met by destroying a link - // instead. The drop to 2 is the residual documented on this group's - // follow-up: links are sized for here but still placed by slot index, so - // one eventually lands where no name claims it. Closing that makes this - // read [3, 3, 3, 3, 3] and this expectation should be updated, not the - // behaviour re-broken to match it. - expect({ imageSlots, linkCounts }).toEqual({ - imageSlots: [2, 2, 3, 2, 2], - linkCounts: [3, 3, 3, 2, 2] - }) + // Slots and links asserted together so the slot bound cannot be met by + // destroying a link instead. The drop to 2 links is the residual on this + // group's follow-up: links are sized for here but still placed by slot + // index, so one eventually lands where no name claims it. Closing that + // holds links at 3 throughout, and this expectation should be updated + // rather than the behaviour re-broken to match it. + expect(trajectory).toEqual([ + { imageSlots: 2, links: 3 }, + { imageSlots: 2, links: 3 }, + { imageSlots: 3, links: 3 }, + { imageSlots: 2, links: 2 }, + { imageSlots: 2, links: 2 } + ]) }) test('keeps both groups when a saved non-default option is restored', async () => {