diff --git a/src/renderer/extensions/vueNodes/composables/processedWidgetRenderModel.ts b/src/renderer/extensions/vueNodes/composables/processedWidgetRenderModel.ts index a293198f30b..e6b9fe3709d 100644 --- a/src/renderer/extensions/vueNodes/composables/processedWidgetRenderModel.ts +++ b/src/renderer/extensions/vueNodes/composables/processedWidgetRenderModel.ts @@ -27,7 +27,7 @@ import { useWidgetValueStore } from '@/stores/widgetValueStore' import { - createNodeExecutionId, + createLeafNodeExecutionId, createNodeLocatorId } from '@/types/nodeIdentification' import type { NodeExecutionId, NodeLocatorId } from '@/types/nodeIdentification' @@ -490,7 +490,7 @@ export function computeProcessedWidgets({ const nodeExecId = isGraphReady && rootGraph ? executionIdFromState(rootGraph, nodeData) - : createNodeExecutionId([nodeData.id]) + : createLeafNodeExecutionId(nodeData.id) if (!nodeExecId) return [] const hostNode = getHostNode(rootGraph, nodeData) diff --git a/src/types/nodeIdentification.test.ts b/src/types/nodeIdentification.test.ts index 6c22b09a278..60c66861c93 100644 --- a/src/types/nodeIdentification.test.ts +++ b/src/types/nodeIdentification.test.ts @@ -4,6 +4,7 @@ import { toNodeId } from '@/types/nodeId' import type { NodeId } from '@/types/nodeId' import { compareExecutionId, + createLeafNodeExecutionId, createNodeExecutionId, createNodeLocatorId, getAncestorExecutionIds, @@ -241,6 +242,24 @@ describe('nodeIdentification', () => { ).toBeNull() }) }) + + describe('createLeafNodeExecutionId', () => { + it('behaves like createNodeExecutionId for an ordinary, colon-free id', () => { + expect(createLeafNodeExecutionId(toNodeId(123))).toBe('123') + }) + + it('keeps a colon-bearing root-level id whole instead of rejecting it (PM-1580)', () => { + // comfy-multi-player's insert_workflow remaps every inserted node's + // id to a derived string with colons unrelated to subgraph scoping. + const rawId = toNodeId('insert:abc123:root:node:5') + expect(createNodeExecutionId([rawId])).toBeNull() + expect(createLeafNodeExecutionId(rawId)).toBe(rawId) + }) + + it('returns null for an empty id', () => { + expect(createLeafNodeExecutionId(toNodeId(''))).toBeNull() + }) + }) }) describe('Integration tests', () => { diff --git a/src/types/nodeIdentification.ts b/src/types/nodeIdentification.ts index d4411e278ea..f238a9230f9 100644 --- a/src/types/nodeIdentification.ts +++ b/src/types/nodeIdentification.ts @@ -147,6 +147,30 @@ export function createNodeExecutionId( : null } +/** + * Create a `NodeExecutionId` for a single, already-local node id, tolerating + * a colon inside it. + * + * `createNodeExecutionId` treats every array element as one path SEGMENT and + * rejects a colon inside any of them, because colon is the separator between + * segments once they are joined. That is the right contract for a real + * multi-segment path, but it is too strict for the single-id, no-ancestor + * case some callers hit: a node materialized at the root graph can have a + * raw id that itself contains colons for reasons that have nothing to do + * with subgraph-path encoding (comfy-multi-player's `insert_workflow` + * remapped ids, e.g. `insert::root:node:`, PM-1580). + * There is no ancestor segment to disambiguate such an id from, so nothing + * is lost by keeping it whole rather than rejecting it outright. + */ +export function createLeafNodeExecutionId( + nodeId: SerializedNodeId +): NodeExecutionId | null { + const strict = createNodeExecutionId([nodeId]) + if (strict) return strict + const bare = parseNodeId(nodeId) + return bare ? (bare as unknown as NodeExecutionId) : null +} + export function tryNormalizeNodeExecutionId( value: string | number ): NodeExecutionId | null { diff --git a/src/utils/graphTraversalUtil.test.ts b/src/utils/graphTraversalUtil.test.ts index 4c90c745faf..2a1169b6c5e 100644 --- a/src/utils/graphTraversalUtil.test.ts +++ b/src/utils/graphTraversalUtil.test.ts @@ -1020,6 +1020,21 @@ describe('graphTraversalUtil', () => { expect(execId).toBe('777') }) + it('regression: keeps a root-level node id whole when it carries a colon that is not a subgraph-scope prefix (PM-1580)', () => { + // comfy-multi-player's insert_workflow remaps every inserted node's + // id to a derived string with colons unrelated to subgraph scoping + // (insert::root:node:). Neither branch below has a + // live node to resolve, so this exercises the same + // `createLeafNodeExecutionId` fallback both take. + const graph = createMockGraph([]) + const rawId = 'insert:abc123:root:node:5' + const execId = executionIdFromState(graph, { + id: toNodeId(rawId), + graphId: ROOT_GRAPH_ID + }) + expect(execId).toBe(rawId) + }) + it('should return full execution ID for node inside a subgraph', () => { const targetNode = createMockNode('999') const subgraphUuid = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890' diff --git a/src/utils/graphTraversalUtil.ts b/src/utils/graphTraversalUtil.ts index 86c80019920..263413ff816 100644 --- a/src/utils/graphTraversalUtil.ts +++ b/src/utils/graphTraversalUtil.ts @@ -7,6 +7,7 @@ import type { import { LGraphEventMode } from '@/lib/litegraph/src/types/globalEnums' import type { NodeExecutionId, NodeLocatorId } from '@/types/nodeIdentification' import { + createLeafNodeExecutionId, createNodeExecutionId, createNodeLocatorId, getParentExecutionIds, @@ -612,14 +613,20 @@ export function executionIdFromState( const localNodeId = parseNodeId(state.id) if (!localNodeId) return null + // A root-owned node has no ancestor path to encode, so its raw id can be + // kept whole even when it contains a colon that isn't a subgraph-scope + // prefix (comfy-multi-player's insert_workflow remapped ids, PM-1580) — + // see `createLeafNodeExecutionId`. A node that IS meant to live inside a + // subgraph still goes through the strict, segment-splitting path. + const fallback = subgraphIdFromState(state, rootGraph.id) + ? createNodeExecutionId([localNodeId]) + : createLeafNodeExecutionId(localNodeId) + const locatorId = locatorIdFromState(state, rootGraph.id) const node = locatorId && getNodeByLocatorId(rootGraph, locatorId) - if (!node) return createNodeExecutionId([localNodeId]) + if (!node) return fallback - return ( - getExecutionIdByNode(rootGraph, node) ?? - createNodeExecutionId([localNodeId]) - ) + return getExecutionIdByNode(rootGraph, node) ?? fallback } /** diff --git a/src/workbench/extensions/agent/crdt/agentInsertWorkflowWidgets.regression.test.ts b/src/workbench/extensions/agent/crdt/agentInsertWorkflowWidgets.regression.test.ts index 62638ed48a4..457aa1eec1b 100644 --- a/src/workbench/extensions/agent/crdt/agentInsertWorkflowWidgets.regression.test.ts +++ b/src/workbench/extensions/agent/crdt/agentInsertWorkflowWidgets.regression.test.ts @@ -162,20 +162,21 @@ describe('insert_workflow materializes a node whose widgets actually render', () expect(node.widgets?.[0]?.value).toBe('my_custom_prefix') }) - it("two inserted nodes sharing an original id do not steal each other's widgets", () => { + it("two inserted nodes sharing an original id, in the SAME graph, do not steal each other's widgets", () => { LiteGraph.registerNodeType('TestSaveImage', TestSaveImage) - const graphA = new LGraph() - const graphB = new LGraph() - const hostA = mint({ nodes: [], links: [] }, CATALOG) - const hostB = mint({ nodes: [], links: [] }, CATALOG) - const deliverA = bindProjection('wf-a', graphA) - const deliverB = bindProjection('wf-b', graphB) - deliverA(Y.encodeStateAsUpdate(hostA), []) - deliverB(Y.encodeStateAsUpdate(hostB), []) - - // Same original node id (9) in two independent insert_workflow ops, as - // could happen for two different templates that both number their sole - // SaveImage node "9". + const graph = new LGraph() + const host = mint({ nodes: [], links: [] }, CATALOG) + const deliver = bindProjection('wf-collision', graph) + deliver(Y.encodeStateAsUpdate(host), []) + + // Same original node id (9), same target graph, from two independent + // insert_workflow ops — as could happen inserting two different + // templates that both number their sole SaveImage node "9" into the + // same workflow. Only the differing `op_id` disambiguates the derived + // ids; a `stripGraphPrefix` that collapsed both down to their trailing + // segment ("9") would collide them in this SAME graph's per-node maps, + // unlike the cross-graph case where separate top-level graph keys would + // mask the collision regardless of the fix. const opA = insertOp( { nodes: [{ id: 9, type: 'TestSaveImage', widgets_values: ['a'] }], @@ -191,28 +192,29 @@ describe('insert_workflow materializes a node whose widgets actually render', () 'insert-op-b' ) - const vectorA = Y.encodeStateVector(hostA) - expect(applyOps(hostA, [opA], CATALOG).outcomes[0]?.outcome).toBe('applied') - expect(deliverA(Y.encodeStateAsUpdate(hostA, vectorA), [opA.op_id])).toBe( + const vectorA = Y.encodeStateVector(host) + expect(applyOps(host, [opA], CATALOG).outcomes[0]?.outcome).toBe('applied') + expect(deliver(Y.encodeStateAsUpdate(host, vectorA), [opA.op_id])).toBe( true ) - const vectorB = Y.encodeStateVector(hostB) - expect(applyOps(hostB, [opB], CATALOG).outcomes[0]?.outcome).toBe('applied') - expect(deliverB(Y.encodeStateAsUpdate(hostB, vectorB), [opB.op_id])).toBe( + const vectorB = Y.encodeStateVector(host) + expect(applyOps(host, [opB], CATALOG).outcomes[0]?.outcome).toBe('applied') + expect(deliver(Y.encodeStateAsUpdate(host, vectorB), [opB.op_id])).toBe( true ) - const nodeA = graphA._nodes.find((n) => n.type === 'TestSaveImage') - const nodeB = graphB._nodes.find((n) => n.type === 'TestSaveImage') - expect(nodeA).toBeDefined() - expect(nodeB).toBeDefined() - if (!nodeA || !nodeB) return + const saveImageNodes = graph._nodes.filter( + (n) => n.type === 'TestSaveImage' + ) + expect(saveImageNodes).toHaveLength(2) + const [nodeA, nodeB] = saveImageNodes + expect(nodeA.id).not.toBe(nodeB.id) - expect(renderedWidgetNames(graphA.rootGraph.id, String(nodeA.id))).toEqual([ + expect(renderedWidgetNames(graph.rootGraph.id, String(nodeA.id))).toEqual([ 'filename_prefix' ]) - expect(renderedWidgetNames(graphB.rootGraph.id, String(nodeB.id))).toEqual([ + expect(renderedWidgetNames(graph.rootGraph.id, String(nodeB.id))).toEqual([ 'filename_prefix' ]) expect(nodeA.widgets?.[0]?.value).toBe('a') diff --git a/src/workbench/extensions/agent/crdt/agentNodeMaterializer.ts b/src/workbench/extensions/agent/crdt/agentNodeMaterializer.ts index e435befb0b8..de4efb19027 100644 --- a/src/workbench/extensions/agent/crdt/agentNodeMaterializer.ts +++ b/src/workbench/extensions/agent/crdt/agentNodeMaterializer.ts @@ -7,7 +7,11 @@ import { import type { LGraph } from '@/lib/litegraph/src/LGraph' import { realignInputLinkSlots } from '@/lib/litegraph/src/linkDeduplication' import { materializeLinkAdapter } from '@/lib/litegraph/src/LLink' -import { LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' +import { + LGraphNode, + LiteGraph, + SubgraphNode +} from '@/lib/litegraph/src/litegraph' import { topologicalSortSubgraphs } from '@/lib/litegraph/src/subgraph/subgraphDeduplication' import type { ExportedSubgraph, @@ -373,9 +377,22 @@ function materialize( try { const savedInputs = serialised.inputs?.map((input) => ({ ...input })) - withNamedValuesRestore(() => + const configureNode = () => node.configure(withNamedWidgetValues(serialised, widgets)) - ) + // A SubgraphNode instance restores its promoted-input values through + // `_applyPromotedWidgetValues`, not the named-values path — and that + // method is the only place `proxyWidgetErrorQuarantine` overrides a + // stale value. `SubgraphNode.configure()` skips it precisely when + // `widgets_values_named` is set AND `namedValuesRestore` is on, so + // forcing the flag here would silently resurrect a quarantined value on + // every agent-materialized subgraph instance. Ordinary nodes have no + // such guard, so they still need the flag to restore their own + // `widgets_values` (PM-1580). + if (node instanceof SubgraphNode) { + configureNode() + } else { + withNamedValuesRestore(configureNode) + } replayUpdatedWidgetCallbacks(node, serialised, widgets) // After configure and any widget-driven restructuring, re-point the saved // links at their named inputs (CRDT-INPUTS-0030).