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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
useWidgetValueStore
} from '@/stores/widgetValueStore'
import {
createNodeExecutionId,
createLeafNodeExecutionId,
createNodeLocatorId
} from '@/types/nodeIdentification'
import type { NodeExecutionId, NodeLocatorId } from '@/types/nodeIdentification'
Expand Down Expand Up @@ -471,7 +471,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)
Expand Down
19 changes: 19 additions & 0 deletions src/types/nodeIdentification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { toNodeId } from '@/types/nodeId'
import type { NodeId } from '@/types/nodeId'
import {
compareExecutionId,
createLeafNodeExecutionId,
createNodeExecutionId,
createNodeLocatorId,
getAncestorExecutionIds,
Expand Down Expand Up @@ -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', () => {
Expand Down
24 changes: 24 additions & 0 deletions src/types/nodeIdentification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:<opId>:root:node:<originalId>`, 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 {
Expand Down
15 changes: 15 additions & 0 deletions src/utils/graphTraversalUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:<opId>:root:node:<originalId>). 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'
Expand Down
17 changes: 12 additions & 5 deletions src/utils/graphTraversalUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -604,14 +605,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
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,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'] }],
Expand All @@ -190,28 +191,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')
Expand Down
23 changes: 20 additions & 3 deletions src/workbench/extensions/agent/crdt/agentNodeMaterializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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,
Expand Down Expand Up @@ -362,9 +366,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).
Expand Down
Loading