From 1118aa96438f58a285a62fa8113be4d7f8535847 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Fri, 30 Oct 2026 12:17:01 -0700 Subject: [PATCH 1/4] fix(graph): enrich serialization mismatch diagnostics --- .../litegraph/src/LGraph.serialise.test.ts | 12 +++++++++- src/lib/litegraph/src/LGraph.test.ts | 6 ++++- src/lib/litegraph/src/LGraph.ts | 24 ++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/lib/litegraph/src/LGraph.serialise.test.ts b/src/lib/litegraph/src/LGraph.serialise.test.ts index cc529698609..b88b0bae435 100644 --- a/src/lib/litegraph/src/LGraph.serialise.test.ts +++ b/src/lib/litegraph/src/LGraph.serialise.test.ts @@ -86,6 +86,9 @@ describe('LGraph Serialisation', () => { graph.add(registered) const adapterOnly = new LGraphNode('Adapter only') adapterOnly.id = toNodeId(99) + adapterOnly.graph = graph + adapterOnly._state.graphId = graph.id + adapterOnly._graphScope = graphScopeOf(graph) graph._nodes.push(adapterOnly) const serialized = graph.serialize() @@ -103,7 +106,14 @@ describe('LGraph Serialisation', () => { errorType: 'graph_serialization_state_mismatch', context: { graphId: graph.id, - mismatch: `live node ${adapterOnly.id} has no stored state` + rootGraphId: graph.rootGraph.id, + mismatch: `live node ${adapterOnly.id} has no stored state`, + mismatchKind: 'live_without_stored_state', + nodeId: adapterOnly.id, + nodeGraphId: graph.id, + stateGraphId: adapterOnly._state.graphId, + registrationRootGraphId: graph.rootGraph.id, + registrationGraphId: graph.id } } ) diff --git a/src/lib/litegraph/src/LGraph.test.ts b/src/lib/litegraph/src/LGraph.test.ts index db3b04ed193..2154892e0c6 100644 --- a/src/lib/litegraph/src/LGraph.test.ts +++ b/src/lib/litegraph/src/LGraph.test.ts @@ -935,7 +935,11 @@ describe('Store-driven serialization parity', () => { errorType: 'graph_serialization_state_mismatch', context: { graphId: graph.id, - mismatch: expect.stringMatching(/stored node .* has no live adapter/) + rootGraphId: graph.rootGraph.id, + mismatch: expect.stringMatching(/stored node .* has no live adapter/), + mismatchKind: 'stored_without_live_adapter', + nodeId: expect.anything(), + stateGraphId: graph.id } } ) diff --git a/src/lib/litegraph/src/LGraph.ts b/src/lib/litegraph/src/LGraph.ts index c7024409b5f..6a3777dd435 100644 --- a/src/lib/litegraph/src/LGraph.ts +++ b/src/lib/litegraph/src/LGraph.ts @@ -492,7 +492,29 @@ function serialiseStoredNodes(owner: LGraph, sortNodes: boolean) { reportError(new Error('Graph serialization state mismatch'), { surface: 'graph', errorType: 'graph_serialization_state_mismatch', - context: { graphId: owner.id, mismatch } + context: { + graphId: owner.id, + rootGraphId: owner.rootGraph.id, + mismatch, + ...(missingState + ? { + mismatchKind: 'stored_without_live_adapter', + nodeId: missingState.id, + stateGraphId: missingState.graphId + } + : missingAdapter + ? { + mismatchKind: 'live_without_stored_state', + nodeId: missingAdapter.id, + nodeGraphId: missingAdapter.graph?.id ?? null, + stateGraphId: missingAdapter._state.graphId, + registrationRootGraphId: + missingAdapter._graphScope?.rootGraphId ?? null, + registrationGraphId: + missingAdapter._graphScope?.owningGraphId ?? null + } + : { mismatchKind: 'count_mismatch' }) + } }) const nodes = sortNodes ? [...liveNodes].sort((a, b) => compareNodeIds(a.id, b.id)) From 58b5eec63edb7bf567150724e85082beecb06069 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Fri, 30 Oct 2026 20:14:07 -0700 Subject: [PATCH 2/4] test(graph): pin the provenance of each serialization-mismatch graph id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The payload's value is that `graphId`, `nodeGraphId`, `stateGraphId` and `registrationGraphId` can disagree — that is how the 1.58.0 alert tells a detached node apart from stale graph registration. Both existing tests use a single graph, so all four fields hold the same string and nothing pins which source each one reads. Mutating `registrationRootGraphId`/`registrationGraphId` to read `owner` instead of `missingAdapter._graphScope` keeps every pre-existing test green. - Add a live-without-stored-state case whose node state and registration scope name a second graph, so each id resolves to a distinct value. It fails on the mutation above. - Assert the real stored node id and mismatch string in the stored-without-live-adapter case instead of `expect.anything()`. - Drop the self-referential `stateGraphId: adapterOnly._state.graphId` expectation for the literal it is set to. --- .../litegraph/src/LGraph.serialise.test.ts | 46 ++++++++++++++++++- src/lib/litegraph/src/LGraph.test.ts | 8 ++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/lib/litegraph/src/LGraph.serialise.test.ts b/src/lib/litegraph/src/LGraph.serialise.test.ts index b88b0bae435..a6fcec396fa 100644 --- a/src/lib/litegraph/src/LGraph.serialise.test.ts +++ b/src/lib/litegraph/src/LGraph.serialise.test.ts @@ -111,7 +111,7 @@ describe('LGraph Serialisation', () => { mismatchKind: 'live_without_stored_state', nodeId: adapterOnly.id, nodeGraphId: graph.id, - stateGraphId: adapterOnly._state.graphId, + stateGraphId: graph.id, registrationRootGraphId: graph.rootGraph.id, registrationGraphId: graph.id } @@ -119,6 +119,50 @@ describe('LGraph Serialisation', () => { ) }) + // The production alert this payload serves is a live node whose own state and + // registration scope name a different graph than the one being serialised. The + // test above cannot tell those three sources apart, because a single graph makes + // every id field the same string. + test('reports the owning, node-state, and registration graph ids separately', ({ + expect + }) => { + const graph = new LGraph() + const otherGraph = new LGraph() + const registered = new LGraphNode('Registered') + graph.add(registered) + const staleScope = new LGraphNode('Stale scope') + staleScope.id = toNodeId(99) + staleScope.graph = graph + staleScope._state.graphId = otherGraph.id + staleScope._graphScope = graphScopeOf(otherGraph) + graph._nodes.push(staleScope) + + expect(graph.id).not.toBe(otherGraph.id) + + graph.serialize() + + expect(mockReportError).toHaveBeenCalledExactlyOnceWith( + expect.objectContaining({ + message: 'Graph serialization state mismatch' + }), + { + surface: 'graph', + errorType: 'graph_serialization_state_mismatch', + context: { + graphId: graph.id, + rootGraphId: graph.rootGraph.id, + mismatch: `live node ${staleScope.id} has no stored state`, + mismatchKind: 'live_without_stored_state', + nodeId: staleScope.id, + nodeGraphId: graph.id, + stateGraphId: otherGraph.id, + registrationRootGraphId: otherGraph.rootGraph.id, + registrationGraphId: otherGraph.id + } + } + ) + }) + test('serialises a node held twice in the live array only once', ({ expect }) => { diff --git a/src/lib/litegraph/src/LGraph.test.ts b/src/lib/litegraph/src/LGraph.test.ts index 2154892e0c6..5cf7acd9707 100644 --- a/src/lib/litegraph/src/LGraph.test.ts +++ b/src/lib/litegraph/src/LGraph.test.ts @@ -922,7 +922,9 @@ describe('Store-driven serialization parity', () => { test('falls back safely when a stored node has no live adapter', ({ expect }) => { - const graph = createGraph(new DummyNode()) + const stranded = new DummyNode() + const graph = createGraph(stranded) + const strandedId = stranded.id graph._nodes = [] expect(graph.asSerialisable().nodes).toEqual([]) @@ -936,9 +938,9 @@ describe('Store-driven serialization parity', () => { context: { graphId: graph.id, rootGraphId: graph.rootGraph.id, - mismatch: expect.stringMatching(/stored node .* has no live adapter/), + mismatch: `stored node ${strandedId} has no live adapter`, mismatchKind: 'stored_without_live_adapter', - nodeId: expect.anything(), + nodeId: strandedId, stateGraphId: graph.id } } From f62459f43e16bbc6ca54e982fb3e9070fbac7b0a Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Fri, 30 Oct 2026 20:37:29 -0700 Subject: [PATCH 3/4] test(graph): give each mismatch graph id a distinct value Addresses both review findings on the previous commit. The provenance case still collapsed three fields onto one string, because `_state.graphId` and both halves of `_graphScope` all came from one second graph. Serialising a subgraph of a separate root, attaching the live node to a third graph, and building the registration scope from distinct literals gives all six ids distinct values, asserted by set size. Five independent substitutions in `serialiseStoredNodes` now each fail exactly one test, where the first three passed before this commit: - `registrationGraphId` reading `_state.graphId` - both registration ids reading `owner` - `nodeGraphId` reading `owner.id` - `rootGraphId` reading `owner.id` - registration root and owning ids swapped Also drops the explanatory comments, per AGENTS.md: the rationale belongs in the commit message. --- .../litegraph/src/LGraph.serialise.test.ts | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/lib/litegraph/src/LGraph.serialise.test.ts b/src/lib/litegraph/src/LGraph.serialise.test.ts index a6fcec396fa..10b671b772b 100644 --- a/src/lib/litegraph/src/LGraph.serialise.test.ts +++ b/src/lib/litegraph/src/LGraph.serialise.test.ts @@ -10,6 +10,7 @@ import type { ISerialisedGraph } from '@/lib/litegraph/src/litegraph' import { useLinkStore } from '@/stores/linkStore' import { graphScopeOf } from '@comfyorg/graph-model/graphScopeId' import { toNodeId } from '@comfyorg/graph-model/nodeId' +import { createTestSubgraph } from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers' import { test } from './__fixtures__/testExtensions' @@ -119,27 +120,36 @@ describe('LGraph Serialisation', () => { ) }) - // The production alert this payload serves is a live node whose own state and - // registration scope name a different graph than the one being serialised. The - // test above cannot tell those three sources apart, because a single graph makes - // every id field the same string. test('reports the owning, node-state, and registration graph ids separately', ({ expect }) => { - const graph = new LGraph() - const otherGraph = new LGraph() + const rootGraph = new LGraph() + const subgraph = createTestSubgraph({ rootGraph }) + const attachedGraph = new LGraph() const registered = new LGraphNode('Registered') - graph.add(registered) + subgraph.add(registered) const staleScope = new LGraphNode('Stale scope') staleScope.id = toNodeId(99) - staleScope.graph = graph - staleScope._state.graphId = otherGraph.id - staleScope._graphScope = graphScopeOf(otherGraph) - graph._nodes.push(staleScope) + staleScope.graph = attachedGraph + staleScope._state.graphId = 'state-graph-id' + staleScope._graphScope = graphScopeOf({ + id: 'registration-owning-graph-id', + rootGraph: { id: 'registration-root-graph-id' } + }) + subgraph._nodes.push(staleScope) - expect(graph.id).not.toBe(otherGraph.id) + expect( + new Set([ + subgraph.id, + rootGraph.id, + attachedGraph.id, + 'state-graph-id', + 'registration-owning-graph-id', + 'registration-root-graph-id' + ]).size + ).toBe(6) - graph.serialize() + subgraph.asSerialisable() expect(mockReportError).toHaveBeenCalledExactlyOnceWith( expect.objectContaining({ @@ -149,15 +159,15 @@ describe('LGraph Serialisation', () => { surface: 'graph', errorType: 'graph_serialization_state_mismatch', context: { - graphId: graph.id, - rootGraphId: graph.rootGraph.id, + graphId: subgraph.id, + rootGraphId: rootGraph.id, mismatch: `live node ${staleScope.id} has no stored state`, mismatchKind: 'live_without_stored_state', nodeId: staleScope.id, - nodeGraphId: graph.id, - stateGraphId: otherGraph.id, - registrationRootGraphId: otherGraph.rootGraph.id, - registrationGraphId: otherGraph.id + nodeGraphId: attachedGraph.id, + stateGraphId: 'state-graph-id', + registrationRootGraphId: 'registration-root-graph-id', + registrationGraphId: 'registration-owning-graph-id' } } ) From d1662e244772dc3ca9b06c37f0e181640f04e6ab Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 2 Nov 2026 23:18:27 -0800 Subject: [PATCH 4/4] fix(graph): distinguish serialization divergence diagnostics --- .../litegraph/src/LGraph.serialise.test.ts | 93 ++++++++++++++++++- src/lib/litegraph/src/LGraph.test.ts | 14 ++- src/lib/litegraph/src/LGraph.ts | 74 +++++++++------ 3 files changed, 146 insertions(+), 35 deletions(-) diff --git a/src/lib/litegraph/src/LGraph.serialise.test.ts b/src/lib/litegraph/src/LGraph.serialise.test.ts index 10b671b772b..ec6676c0cea 100644 --- a/src/lib/litegraph/src/LGraph.serialise.test.ts +++ b/src/lib/litegraph/src/LGraph.serialise.test.ts @@ -105,6 +105,7 @@ describe('LGraph Serialisation', () => { { surface: 'graph', errorType: 'graph_serialization_state_mismatch', + tags: { outcome: 'degraded' }, context: { graphId: graph.id, rootGraphId: graph.rootGraph.id, @@ -114,7 +115,94 @@ describe('LGraph Serialisation', () => { nodeGraphId: graph.id, stateGraphId: graph.id, registrationRootGraphId: graph.rootGraph.id, - registrationGraphId: graph.id + registrationOwningGraphId: graph.id + } + } + ) + }) + + test('reports absent graph provenance for a detached live node', ({ + expect + }) => { + const graph = new LGraph() + const registered = new LGraphNode('Registered') + graph.add(registered) + const detached = new LGraphNode('Detached') + detached.id = toNodeId(99) + graph._nodes.push(detached) + + const serialized = graph.serialize() + + expect(serialized.nodes.map(({ title }) => title)).toEqual([ + 'Registered', + 'Detached' + ]) + expect(mockReportError).toHaveBeenCalledExactlyOnceWith( + expect.objectContaining({ + message: 'Graph serialization state mismatch' + }), + { + surface: 'graph', + errorType: 'graph_serialization_state_mismatch', + tags: { outcome: 'degraded' }, + context: { + graphId: graph.id, + rootGraphId: graph.rootGraph.id, + mismatch: `live node ${detached.id} has no stored state`, + mismatchKind: 'live_without_stored_state', + nodeId: detached.id, + nodeGraphId: null, + stateGraphId: detached._state.graphId, + registrationRootGraphId: null, + registrationOwningGraphId: null + } + } + ) + }) + + test('reports both sides of mixed stored and live divergence', ({ + expect + }) => { + const graph = new LGraph() + const storedOnly = new LGraphNode('Stored only') + graph.add(storedOnly) + graph._nodes = [] + storedOnly._state.graphId = 'stored-only-state-graph-id' + const liveOnly = new LGraphNode('Live only') + liveOnly.id = toNodeId(99) + liveOnly.graph = new LGraph() + liveOnly._state.graphId = 'live-only-state-graph-id' + liveOnly._graphScope = graphScopeOf({ + id: 'live-only-registration-owning-graph-id', + rootGraph: { id: 'live-only-registration-root-graph-id' } + }) + graph._nodes.push(liveOnly) + + const serialized = graph.serialize() + + expect(serialized.nodes.map(({ title }) => title)).toEqual(['Live only']) + expect(mockReportError).toHaveBeenCalledExactlyOnceWith( + expect.objectContaining({ + message: 'Graph serialization state mismatch' + }), + { + surface: 'graph', + errorType: 'graph_serialization_state_mismatch', + tags: { outcome: 'degraded' }, + context: { + graphId: graph.id, + rootGraphId: graph.rootGraph.id, + mismatch: `stored node ${storedOnly.id} has no live adapter; live node ${liveOnly.id} has no stored state`, + mismatchKind: 'stored_and_live_diverged', + storedOnlyNodeId: storedOnly.id, + storedOnlyStateGraphId: 'stored-only-state-graph-id', + liveOnlyNodeId: liveOnly.id, + liveOnlyNodeGraphId: liveOnly.graph.id, + liveOnlyStateGraphId: 'live-only-state-graph-id', + liveOnlyRegistrationRootGraphId: + 'live-only-registration-root-graph-id', + liveOnlyRegistrationOwningGraphId: + 'live-only-registration-owning-graph-id' } } ) @@ -158,6 +246,7 @@ describe('LGraph Serialisation', () => { { surface: 'graph', errorType: 'graph_serialization_state_mismatch', + tags: { outcome: 'degraded' }, context: { graphId: subgraph.id, rootGraphId: rootGraph.id, @@ -167,7 +256,7 @@ describe('LGraph Serialisation', () => { nodeGraphId: attachedGraph.id, stateGraphId: 'state-graph-id', registrationRootGraphId: 'registration-root-graph-id', - registrationGraphId: 'registration-owning-graph-id' + registrationOwningGraphId: 'registration-owning-graph-id' } } ) diff --git a/src/lib/litegraph/src/LGraph.test.ts b/src/lib/litegraph/src/LGraph.test.ts index 5cf7acd9707..e230aa7819a 100644 --- a/src/lib/litegraph/src/LGraph.test.ts +++ b/src/lib/litegraph/src/LGraph.test.ts @@ -923,10 +923,17 @@ describe('Store-driven serialization parity', () => { expect }) => { const stranded = new DummyNode() - const graph = createGraph(stranded) + const rootGraph = new LGraph() + const graph = createTestSubgraph({ rootGraph }) + graph.add(stranded) const strandedId = stranded.id + stranded._state.graphId = 'stored-state-graph-id' graph._nodes = [] + expect( + new Set([graph.id, rootGraph.id, stranded._state.graphId]).size + ).toBe(3) + expect(graph.asSerialisable().nodes).toEqual([]) expect(mockReportError).toHaveBeenCalledExactlyOnceWith( expect.objectContaining({ @@ -935,13 +942,14 @@ describe('Store-driven serialization parity', () => { { surface: 'graph', errorType: 'graph_serialization_state_mismatch', + tags: { outcome: 'degraded' }, context: { graphId: graph.id, - rootGraphId: graph.rootGraph.id, + rootGraphId: rootGraph.id, mismatch: `stored node ${strandedId} has no live adapter`, mismatchKind: 'stored_without_live_adapter', nodeId: strandedId, - stateGraphId: graph.id + stateGraphId: 'stored-state-graph-id' } } ) diff --git a/src/lib/litegraph/src/LGraph.ts b/src/lib/litegraph/src/LGraph.ts index 6a3777dd435..0b4faa22b84 100644 --- a/src/lib/litegraph/src/LGraph.ts +++ b/src/lib/litegraph/src/LGraph.ts @@ -478,42 +478,56 @@ function serialiseStoredNodes(owner: LGraph, sortNodes: boolean) { ordered.length !== adapters.size ) { const liveNodes = [...adapters.values()] - const missingState = ordered.find((state) => !adapters.has(state.id)) - let missingAdapter: LGraphNode | undefined - if (missingState === undefined) { - const stateIds = new Set(ordered.map((state) => state.id)) - missingAdapter = liveNodes.find((adapter) => !stateIds.has(adapter.id)) - } - const mismatch = missingState - ? `stored node ${missingState.id} has no live adapter` - : missingAdapter - ? `live node ${missingAdapter.id} has no stored state` - : `${ordered.length} stored nodes do not match ${adapters.size} live nodes` + const stateIds = new Set(ordered.map((state) => state.id)) + const storedOnlyState = ordered.find((state) => !adapters.has(state.id)) + const liveOnlyAdapter = liveNodes.find( + (adapter) => !stateIds.has(adapter.id) + ) + const mismatchDetails = storedOnlyState + ? liveOnlyAdapter + ? { + mismatch: `stored node ${storedOnlyState.id} has no live adapter; live node ${liveOnlyAdapter.id} has no stored state`, + mismatchKind: 'stored_and_live_diverged', + storedOnlyNodeId: storedOnlyState.id, + storedOnlyStateGraphId: storedOnlyState.graphId, + liveOnlyNodeId: liveOnlyAdapter.id, + liveOnlyNodeGraphId: liveOnlyAdapter.graph?.id ?? null, + liveOnlyStateGraphId: liveOnlyAdapter._state.graphId, + liveOnlyRegistrationRootGraphId: + liveOnlyAdapter._graphScope?.rootGraphId ?? null, + liveOnlyRegistrationOwningGraphId: + liveOnlyAdapter._graphScope?.owningGraphId ?? null + } + : { + mismatch: `stored node ${storedOnlyState.id} has no live adapter`, + mismatchKind: 'stored_without_live_adapter', + nodeId: storedOnlyState.id, + stateGraphId: storedOnlyState.graphId + } + : liveOnlyAdapter + ? { + mismatch: `live node ${liveOnlyAdapter.id} has no stored state`, + mismatchKind: 'live_without_stored_state', + nodeId: liveOnlyAdapter.id, + nodeGraphId: liveOnlyAdapter.graph?.id ?? null, + stateGraphId: liveOnlyAdapter._state.graphId, + registrationRootGraphId: + liveOnlyAdapter._graphScope?.rootGraphId ?? null, + registrationOwningGraphId: + liveOnlyAdapter._graphScope?.owningGraphId ?? null + } + : { + mismatch: `${ordered.length} stored nodes do not match ${adapters.size} live nodes`, + mismatchKind: 'count_mismatch' + } reportError(new Error('Graph serialization state mismatch'), { surface: 'graph', errorType: 'graph_serialization_state_mismatch', + tags: { outcome: 'degraded' }, context: { graphId: owner.id, rootGraphId: owner.rootGraph.id, - mismatch, - ...(missingState - ? { - mismatchKind: 'stored_without_live_adapter', - nodeId: missingState.id, - stateGraphId: missingState.graphId - } - : missingAdapter - ? { - mismatchKind: 'live_without_stored_state', - nodeId: missingAdapter.id, - nodeGraphId: missingAdapter.graph?.id ?? null, - stateGraphId: missingAdapter._state.graphId, - registrationRootGraphId: - missingAdapter._graphScope?.rootGraphId ?? null, - registrationGraphId: - missingAdapter._graphScope?.owningGraphId ?? null - } - : { mismatchKind: 'count_mismatch' }) + ...mismatchDetails } }) const nodes = sortNodes