Repository navigation
WIP: assert registration-identity invariants in node state registration - #14405
mattmillerai wants to merge 9 commits into
Conversation
Collapses the twelve reviewed slices of the ECS migration into one commit so the series can be replayed onto main as a unit. Each slice kept its own review on GitHub: - ECS: Moving widgets out of the Node data (#13322) - ECS: Link topology store (single source of truth for link data) (#13436) - ECS: Reroute chain store with derived link membership (#13449) - ECS: derive slot floating links; reroute cleanup follow-ups (#13451) - refactor: read widgeted-input connectivity from linkStore (#13455) - feat: nodeBadgeStore + badge system (slice A) (#13458) - refactor: derive badge rows on read, delete the badge store (#13686) - refactor: host-scoped promoted widget rows (no source traversal) (#13434) - refactor!: delete the output.links runtime mirror (#13479) - refactor!: delete the input.link runtime mirror (#13498) - fix: ECS stack audit fixes (#13528) - refactor!: make nodeDataStore the source of truth for node shell state (#13963) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`LGraph.clear()` fires `node:before-removed` and `onNodeRemoved`, but not `node:removed` — only `LGraph.remove()` dispatches that. The error-clearing hooks listened for `node:removed`, so clearing or switching a workflow left missing model/media/node errors in their stores and the run button kept the warning triangle on an empty canvas. Reverts the automated expectation update that captured that triangle as the new baseline; the goldens are regenerated once the fix is in. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The previous revert rolled these back to the captures taken in the ECS squash commit, which predate #14177 and so lack both the run-button warning icon and the graph-toolbar button. Take main's versions as the baseline instead, leaving only genuinely branch-caused differences for the regeneration to pick up. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
registerNodeState overwrote node._graphId unconditionally, so a node re-registered under a second root graph stranded its entry in the old bucket (membership is by state identity; nothing removes it). unregisterNodeState discarded deleteNode's boolean, so a _state reassigned after registration left a ghost NodeState the renderer keeps drawing. Both now assert. _graphId is cleared before the unregister assert so the DEV throw still detaches the node rather than re-throwing on every later attempt.
…Shell Move the app-owned node shell-state lifecycle coordination out of the litegraph folder into an app-layer module, leaving thin call sites in litegraph. No behaviour change. - createNodeShellState / setTrackedNodeState / registerNodeState / unregisterNodeState / unregisterAllNodeStates now live in src/core/graph/nodeShell/nodeShellState.ts - attachNodeToStores / releaseGraphStores in nodeShellLifecycle.ts are the single calls LGraph.add and LGraph.clear make into the app stores - LGraphNode no longer imports useNodeDataStore - the litegraph barrel no longer re-exports the registration functions
The registration functions this branch asserts on moved from LGraphNode.ts into src/core/graph/nodeShell/. Resolve by taking the extracted layout; the asserts are re-applied in their new home in the next commit.
Three silent failure modes in the node-data-store registration lifecycle now fail loudly instead of leaving state the renderer keeps drawing. registerNodeState overwrote node._graphId unconditionally, so a node re-registered under a second root graph stranded its entry in the old bucket (membership is by state identity; nothing removes it). unregisterNodeState discarded deleteNode's boolean, so a _state reassigned after registration left a ghost NodeState behind. Both now assert. _graphId is cleared before the unregister assert so the DEV throw still detaches the node rather than re-throwing on every later attempt. nodeDataStore buckets are identity-keyed Sets, so two distinct states for one (id, graphId) coexist rather than overwriting. registerNode now asserts against a per-bucket index instead of scanning the Set, which would be quadratic over a graph load. The index records the key each state was registered under, so a node renumbered after registration still unregisters cleanly and frees the id it vacated.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
🎨 Storybook: ✅ Built — View Storybook🎭 Playwright: ✅ 1757 passed, 0 failed · 2 flaky📊 Browser Reports
📦 Bundle Size
⚡ Performance Report
Absolute values
Raw data{
"timestamp": "2026-07-30T18:38:49.902Z",
"gitSha": "26e8009b424208d0b4af74dec464afd9e5464f2f",
"branch": "matt/be-5048-registration-identity-asserts",
"measurements": [
{
"name": "canvas-idle",
"durationMs": 2017.721999999992,
"styleRecalcs": 11,
"styleRecalcDurationMs": 5.4079999999999995,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 376.241,
"heapDeltaBytes": -22696128,
"heapUsedBytes": 46214692,
"domNodes": 22,
"jsHeapTotalBytes": 19128320,
"scriptDurationMs": 14.077000000000002,
"eventListeners": 6,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.670000000000012,
"p95FrameDurationMs": 16.800000000000182
},
{
"name": "canvas-idle",
"durationMs": 2003.3619999999246,
"styleRecalcs": 12,
"styleRecalcDurationMs": 5.153,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 306.70799999999997,
"heapDeltaBytes": 4542520,
"heapUsedBytes": 73731960,
"domNodes": 24,
"jsHeapTotalBytes": 19525632,
"scriptDurationMs": 12.967999999999998,
"eventListeners": 6,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "canvas-mouse-sweep",
"durationMs": 1688.5780000000068,
"styleRecalcs": 74,
"styleRecalcDurationMs": 19.629,
"layouts": 12,
"layoutDurationMs": 1.9989999999999999,
"taskDurationMs": 528.601,
"heapDeltaBytes": 1824236,
"heapUsedBytes": 70872968,
"domNodes": 58,
"jsHeapTotalBytes": 20312064,
"scriptDurationMs": 87.617,
"eventListeners": 4,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.699999999999818
},
{
"name": "canvas-mouse-sweep",
"durationMs": 1718.0969999999434,
"styleRecalcs": 72,
"styleRecalcDurationMs": 19.386999999999997,
"layouts": 12,
"layoutDurationMs": 2.0709999999999997,
"taskDurationMs": 568.554,
"heapDeltaBytes": -17185272,
"heapUsedBytes": 51950640,
"domNodes": -271,
"jsHeapTotalBytes": 19390464,
"scriptDurationMs": 86.97399999999999,
"eventListeners": -150,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.66333333333335,
"p95FrameDurationMs": 16.699999999999818
},
{
"name": "canvas-zoom-sweep",
"durationMs": 1708.3630000000198,
"styleRecalcs": 32,
"styleRecalcDurationMs": 10.973,
"layouts": 6,
"layoutDurationMs": 0.608,
"taskDurationMs": 260.163,
"heapDeltaBytes": 7667948,
"heapUsedBytes": 76715884,
"domNodes": 79,
"jsHeapTotalBytes": 19787776,
"scriptDurationMs": 14.34,
"eventListeners": 19,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "canvas-zoom-sweep",
"durationMs": 1655.1310000000967,
"styleRecalcs": 30,
"styleRecalcDurationMs": 9.902999999999999,
"layouts": 6,
"layoutDurationMs": 0.44400000000000006,
"taskDurationMs": 244.61200000000002,
"heapDeltaBytes": 7918444,
"heapUsedBytes": 76915420,
"domNodes": 79,
"jsHeapTotalBytes": 19525632,
"scriptDurationMs": 13.557999999999998,
"eventListeners": 19,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.66333333333335,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "dom-widget-clipping",
"durationMs": 407.53499999999576,
"styleRecalcs": 13,
"styleRecalcDurationMs": 4.673,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 243.591,
"heapDeltaBytes": -11370592,
"heapUsedBytes": 57634008,
"domNodes": 22,
"jsHeapTotalBytes": 20574208,
"scriptDurationMs": 43.527,
"eventListeners": 2,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.663333333333338,
"p95FrameDurationMs": 16.800000000000182
},
{
"name": "dom-widget-clipping",
"durationMs": 418.1499999999687,
"styleRecalcs": 13,
"styleRecalcDurationMs": 4.571,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 247.14400000000003,
"heapDeltaBytes": -10147124,
"heapUsedBytes": 58896280,
"domNodes": 22,
"jsHeapTotalBytes": 19787776,
"scriptDurationMs": 43.97,
"eventListeners": 2,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.663333333333338,
"p95FrameDurationMs": 16.700000000000273
},
{
"name": "large-graph-idle",
"durationMs": 2018.2869999999866,
"styleRecalcs": 11,
"styleRecalcDurationMs": 5.442000000000001,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 545.678,
"heapDeltaBytes": 2464928,
"heapUsedBytes": 72940012,
"domNodes": -274,
"jsHeapTotalBytes": 2977792,
"scriptDurationMs": 138.192,
"eventListeners": -148,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "large-graph-idle",
"durationMs": 2020.8030000000008,
"styleRecalcs": 10,
"styleRecalcDurationMs": 4.506000000000001,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 533.491,
"heapDeltaBytes": 1255368,
"heapUsedBytes": 71632608,
"domNodes": -273,
"jsHeapTotalBytes": 3239936,
"scriptDurationMs": 135.955,
"eventListeners": -146,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "large-graph-pan",
"durationMs": 2154.5790000000125,
"styleRecalcs": 70,
"styleRecalcDurationMs": 11.664000000000001,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 1282.932,
"heapDeltaBytes": -14876844,
"heapUsedBytes": 56928996,
"domNodes": -271,
"jsHeapTotalBytes": 4026368,
"scriptDurationMs": 636.692,
"eventListeners": -146,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.66333333333332,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "large-graph-pan",
"durationMs": 2119.02299999997,
"styleRecalcs": 69,
"styleRecalcDurationMs": 8.58,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 1178.709,
"heapDeltaBytes": 870036,
"heapUsedBytes": 72524452,
"domNodes": -275,
"jsHeapTotalBytes": 4493312,
"scriptDurationMs": 597.82,
"eventListeners": -148,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.800000000000182
},
{
"name": "large-graph-zoom",
"durationMs": 3190.174999999954,
"styleRecalcs": 67,
"styleRecalcDurationMs": 12.825000000000001,
"layouts": 60,
"layoutDurationMs": 6.9270000000000005,
"taskDurationMs": 1387.932,
"heapDeltaBytes": -9940124,
"heapUsedBytes": 63481432,
"domNodes": -276,
"jsHeapTotalBytes": 8220672,
"scriptDurationMs": 663.752,
"eventListeners": -150,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.66333333333332,
"p95FrameDurationMs": 16.800000000000182
},
{
"name": "large-graph-zoom",
"durationMs": 3092.6299999999856,
"styleRecalcs": 66,
"styleRecalcDurationMs": 9.399000000000001,
"layouts": 60,
"layoutDurationMs": 5.18,
"taskDurationMs": 1222.5940000000003,
"heapDeltaBytes": 18195388,
"heapUsedBytes": 91950200,
"domNodes": 14,
"jsHeapTotalBytes": 8970240,
"scriptDurationMs": 595.3170000000001,
"eventListeners": 8,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.66333333333332,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "minimap-idle",
"durationMs": 2008.542000000034,
"styleRecalcs": 10,
"styleRecalcDurationMs": 4.879,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 530.4680000000001,
"heapDeltaBytes": 1539340,
"heapUsedBytes": 73947756,
"domNodes": -271,
"jsHeapTotalBytes": 2977792,
"scriptDurationMs": 132.247,
"eventListeners": -148,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "minimap-idle",
"durationMs": 2016.4119999999457,
"styleRecalcs": 10,
"styleRecalcDurationMs": 4.641000000000001,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 522.153,
"heapDeltaBytes": -8712436,
"heapUsedBytes": 63870752,
"domNodes": -275,
"jsHeapTotalBytes": 2715648,
"scriptDurationMs": 132.27800000000002,
"eventListeners": -146,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "subgraph-dom-widget-clipping",
"durationMs": 441.26799999997957,
"styleRecalcs": 49,
"styleRecalcDurationMs": 7.095000000000001,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 264.847,
"heapDeltaBytes": -11190464,
"heapUsedBytes": 57643940,
"domNodes": 24,
"jsHeapTotalBytes": 21622784,
"scriptDurationMs": 78.349,
"eventListeners": 8,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.663333333333338,
"p95FrameDurationMs": 16.800000000000182
},
{
"name": "subgraph-dom-widget-clipping",
"durationMs": 427.11400000007416,
"styleRecalcs": 49,
"styleRecalcDurationMs": 6.933,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 267.007,
"heapDeltaBytes": -11118752,
"heapUsedBytes": 57926776,
"domNodes": 24,
"jsHeapTotalBytes": 21884928,
"scriptDurationMs": 78.497,
"eventListeners": 8,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000273
},
{
"name": "subgraph-idle",
"durationMs": 2001.983999999993,
"styleRecalcs": 11,
"styleRecalcDurationMs": 4.954,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 305.20200000000006,
"heapDeltaBytes": 3900300,
"heapUsedBytes": 73070456,
"domNodes": 22,
"jsHeapTotalBytes": 19525632,
"scriptDurationMs": 10.399999999999999,
"eventListeners": 6,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.699999999999818
},
{
"name": "subgraph-idle",
"durationMs": 2001.888000000008,
"styleRecalcs": 11,
"styleRecalcDurationMs": 5.707,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 350.588,
"heapDeltaBytes": -22385788,
"heapUsedBytes": 46746116,
"domNodes": -271,
"jsHeapTotalBytes": 19128320,
"scriptDurationMs": 10.531999999999998,
"eventListeners": -150,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "subgraph-mouse-sweep",
"durationMs": 1727.6640000000043,
"styleRecalcs": 75,
"styleRecalcDurationMs": 25.445,
"layouts": 16,
"layoutDurationMs": 3.356,
"taskDurationMs": 602.185,
"heapDeltaBytes": -20822536,
"heapUsedBytes": 48324740,
"domNodes": -273,
"jsHeapTotalBytes": 19652608,
"scriptDurationMs": 69.959,
"eventListeners": -150,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.800000000000182
},
{
"name": "subgraph-mouse-sweep",
"durationMs": 1674.3089999999938,
"styleRecalcs": 76,
"styleRecalcDurationMs": 20.103,
"layouts": 16,
"layoutDurationMs": 2.1510000000000002,
"taskDurationMs": 488.654,
"heapDeltaBytes": -3949596,
"heapUsedBytes": 65039128,
"domNodes": 64,
"jsHeapTotalBytes": 19525632,
"scriptDurationMs": 60.494,
"eventListeners": 4,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.66333333333335,
"p95FrameDurationMs": 16.800000000000182
},
{
"name": "subgraph-transition-enter",
"durationMs": 849.5419999999285,
"styleRecalcs": 10,
"styleRecalcDurationMs": 19.116000000000007,
"layouts": 7,
"layoutDurationMs": 6.9750000000000005,
"taskDurationMs": 628.8179999999999,
"heapDeltaBytes": -1048032,
"heapUsedBytes": 84501968,
"domNodes": 13671,
"jsHeapTotalBytes": 9699328,
"scriptDurationMs": 23.415000000000006,
"eventListeners": 2381,
"totalBlockingTimeMs": 100,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "viewport-pan-sweep",
"durationMs": 8113.135999999997,
"styleRecalcs": 250,
"styleRecalcDurationMs": 25.516,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 3921.589,
"heapDeltaBytes": -356076,
"heapUsedBytes": 69824068,
"domNodes": -273,
"jsHeapTotalBytes": 6328320,
"scriptDurationMs": 1899.91,
"eventListeners": -130,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.670000000000012,
"p95FrameDurationMs": 16.799999999999272
},
{
"name": "viewport-pan-sweep",
"durationMs": 8101.518999999939,
"styleRecalcs": 250,
"styleRecalcDurationMs": 21.22,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 3756.772,
"heapDeltaBytes": 1352020,
"heapUsedBytes": 71595308,
"domNodes": -273,
"jsHeapTotalBytes": 6852608,
"scriptDurationMs": 1820.8629999999998,
"eventListeners": -130,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.66333333333332,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "vue-large-graph-idle",
"durationMs": 9475.826999999981,
"styleRecalcs": 0,
"styleRecalcDurationMs": 0,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 9468.693,
"heapDeltaBytes": -25352976,
"heapUsedBytes": 165915156,
"domNodes": -6548,
"jsHeapTotalBytes": 3731456,
"scriptDurationMs": 542.4599999999999,
"eventListeners": -7475,
"totalBlockingTimeMs": 0,
"frameDurationMs": 17.216666666666665,
"p95FrameDurationMs": 16.799999999999272
},
{
"name": "vue-large-graph-idle",
"durationMs": 9893.084999999928,
"styleRecalcs": 0,
"styleRecalcDurationMs": 0,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 9881.744,
"heapDeltaBytes": -30501352,
"heapUsedBytes": 165293708,
"domNodes": -6548,
"jsHeapTotalBytes": 1110016,
"scriptDurationMs": 559.504,
"eventListeners": -7473,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.66333333333332,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "vue-large-graph-pan",
"durationMs": 12609.27700000002,
"styleRecalcs": 65,
"styleRecalcDurationMs": 13.080000000000009,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 12597.436000000002,
"heapDeltaBytes": -33125420,
"heapUsedBytes": 159100420,
"domNodes": -6548,
"jsHeapTotalBytes": 2945024,
"scriptDurationMs": 941.5100000000001,
"eventListeners": -7473,
"totalBlockingTimeMs": 1,
"frameDurationMs": 17.223333333333358,
"p95FrameDurationMs": 16.799999999999272
},
{
"name": "vue-large-graph-pan",
"durationMs": 12565.977999999974,
"styleRecalcs": 66,
"styleRecalcDurationMs": 12.512999999999996,
"layouts": 0,
"layoutDurationMs": 0,
"taskDurationMs": 12536.035,
"heapDeltaBytes": -4111444,
"heapUsedBytes": 183747984,
"domNodes": -6548,
"jsHeapTotalBytes": 4431872,
"scriptDurationMs": 1022.154,
"eventListeners": -7471,
"totalBlockingTimeMs": 26,
"frameDurationMs": 16.66333333333326,
"p95FrameDurationMs": 16.700000000000728
},
{
"name": "workflow-execution",
"durationMs": 426.8680000000131,
"styleRecalcs": 16,
"styleRecalcDurationMs": 12.208,
"layouts": 2,
"layoutDurationMs": 0.33199999999999996,
"taskDurationMs": 77.644,
"heapDeltaBytes": -16185028,
"heapUsedBytes": 51722608,
"domNodes": 132,
"jsHeapTotalBytes": 7204864,
"scriptDurationMs": 7.029999999999999,
"eventListeners": 67,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.666666666666668,
"p95FrameDurationMs": 16.700000000000273
},
{
"name": "workflow-execution",
"durationMs": 431.34600000007595,
"styleRecalcs": 14,
"styleRecalcDurationMs": 12.116000000000001,
"layouts": 2,
"layoutDurationMs": 0.32300000000000006,
"taskDurationMs": 94.299,
"heapDeltaBytes": -15996656,
"heapUsedBytes": 51726580,
"domNodes": 121,
"jsHeapTotalBytes": 7467008,
"scriptDurationMs": 6.845000000000001,
"eventListeners": 67,
"totalBlockingTimeMs": 0,
"frameDurationMs": 16.66333333333332,
"p95FrameDurationMs": 16.700000000000273
}
]
} |
Held as WIP — the store-level duplicate assert is red on real
|
There was a problem hiding this comment.
🔍 Cursor Review — Consolidated panel
Triggered by @mattmillerai.
Found 6 finding(s).
| Severity | Count |
|---|---|
| 🟠 High | 2 |
| 🟡 Medium | 3 |
| 🟢 Low | 1 |
Panel: 8/8 reviewers contributed findings.
| node: LGraphNode | ||
| ): void { | ||
| const rootGraphId = graph.rootGraph.id | ||
| assert( |
There was a problem hiding this comment.
🟠 High — The cross-root guard is placed before the mutations, but assert (src/base/assert.ts) only throws in DEV — in production it logs/reports and returns, so execution falls through to reassign node._state.graphId and re-register under the new root, overwriting _graphId and stranding the original NodeState in the old bucket (memory leak plus a ghost node the old graph keeps rendering). Enforce the invariant with an early return on violation rather than relying on assert. Raised by 5 of 8 reviewers (gpt-5.6-sol-max adversarial, gpt-5.6-sol-max edge-case, claude-opus-4-8-thinking-max adversarial, claude-opus-4-8-thinking-max edge-case, kimi-k2.7-code adversarial).
| const claimantRenumbered = | ||
| claimant !== undefined && nodeKey(claimant) !== key | ||
|
|
||
| assert( |
There was a problem hiding this comment.
🟠 High — The duplicate-state guard runs before the index/bucket writes, but assert is non-fatal in production. If a duplicate ever slips past load-time dedup, prod continues past the assert, overwrites byNodeKey[key], and adds the second state via getGraphNodes().add(state), leaving two live NodeStates for the same (graphId, id); guard with an early return instead of a diagnostic-only assert. Raised by 3 of 8 reviewers (gpt-5.6-sol-max adversarial, gpt-5.6-sol-max edge-case, kimi-k2.7-code adversarial).
| const raw = toRaw(state) | ||
| const index = getNodeKeyIndex(rootGraphId) | ||
| const key = nodeKey(raw) | ||
| const claimant = index.byNodeKey.get(key) |
There was a problem hiding this comment.
🟡 Medium — The index is only updated when a state registers or is deleted, not when its id/graphId is mutated in place. After a live state is renumbered (e.g. 1→42) without being re-registered, byNodeKey.get('graph:42') returns undefined, so registering a different state at 42 sees no claimant and passes the assert — defeating the one-state-per-node invariant even in DEV. The claimantRenumbered branch also overwrites byNodeKey while leaving the renumbered state's stale keyOf entry behind. Raised by 4 of 8 reviewers (gpt-5.6-sol-max adversarial, gpt-5.6-sol-max edge-case, kimi-k2.7-code edge-case, claude-opus-4-8-thinking-max adversarial).
| useNodeDataStore().deleteNode(node._graphId, node._state) | ||
| const deleted = useNodeDataStore().deleteNode(node._graphId, node._state) | ||
| node._graphId = undefined | ||
| assert( |
There was a problem hiding this comment.
🟡 Medium — clearGraph()/LGraph.clear() deletes the bucket and its nodeKeyIndex but never clears _graphId on the nodes that lived there. A later unregisterNodeState on a retained node (e.g. tearing down a subgraph after the root was cleared) then gets deleted === false and trips this new identity drift assert as a false positive — throwing in DEV/tests (risking interruption of teardown) and reporting to Sentry in prod even though the state was already correctly gone. The symmetric case also false-fires the register guard at line 67 when a cleared node is reused under a new root; this teardown path is untested. Raised by 3 of 8 reviewers (claude-opus-4-8-thinking-max edge-case, gpt-5.6-sol-max edge-case, gemini-3.1-pro adversarial).
| if (!node._graphId) return | ||
| useNodeDataStore().deleteNode(node._graphId, node._state) | ||
| const deleted = useNodeDataStore().deleteNode(node._graphId, node._state) | ||
| node._graphId = undefined |
There was a problem hiding this comment.
🟡 Medium — On genuine identity drift, node._graphId is set to undefined before the assert(deleted), and the assert is non-fatal in production. So prod leaves the stale NodeState registered in the bucket (still rendered) while the node believes it is unregistered; every future unregisterNodeState early-returns at the if (!node._graphId) guard and can never remove it. Raised by 5 of 8 reviewers (gpt-5.6-sol-max adversarial, gpt-5.6-sol-max edge-case, kimi-k2.7-code adversarial, kimi-k2.7-code edge-case, claude-opus-4-8-thinking-max adversarial).
| } | ||
|
|
||
| function nodeKey(state: NodeState): string { | ||
| return `${state.graphId}:${state.id}` |
There was a problem hiding this comment.
🟢 Low — nodeKey joins graphId and id with a raw : and no escaping, so ids containing a colon can collide into one key and either mask a real duplicate or fire a false duplicate assert. Consider a delimiter-safe encoding (e.g. a JSON tuple or length-prefixing); note also that keying by graphId:id is finer-grained than the root-global node-id uniqueness the invariant targets. Raised by 2 of 8 reviewers (gpt-5.6-sol-max edge-case, gemini-3.1-pro adversarial).
950e26e to
7ca4449
Compare
|
Superseded by #14443, which carries the same BE-5048 assertions further: the invariants moved out of Closing rather than restacking — this branch was left stranded when |
STACKED — merging lands on
matt/be-5050-node-shell-state(owned by mattmillerai, PR #14257), NOTmain. #14257 extracts the registration lifecycle out ofLGraphNode.tsintosrc/core/graph/nodeShell/, which is exactly the code this PR asserts in, so this is stacked on it rather than reimplementing against the pre-move layout. It retargets tofeature/ecs-migrationautomatically once #14257 merges. Ultimate base isfeature/ecs-migration, notmain— none of this code exists onmain.ELI-5
The node data store is a bag of node states. Three ways a node could quietly go wrong: it could get put in a second bag while its old bag still holds it, it could be taken out with the wrong hand so the bag keeps the old copy, or two copies of the same node could sit in one bag. Nobody noticed any of these when they happened — the screen just drew a node that should not be there. Now each one shouts.
Summary
Turn three silent failure modes in the node-data-store registration lifecycle into assertions, so a regression surfaces at its cause rather than as a ghost node the renderer keeps drawing.
Changes
registerNodeStateasserts the node is not already registered under a different root graph. It overwrotenode._graphIdunconditionally, and because bucket membership is by state identity, nothing would ever remove the stranded entry from the old bucket.unregisterNodeStatecapturesdeleteNode's boolean and asserts it.falsemeans the bucket did not containnode._state— identity drift, e.g._statereassigned after registration — leaving a state the renderer keeps drawing._graphIdis cleared before the assert so the DEV throw still detaches the node instead of re-throwing on every later attempt.nodeDataStore.registerNodeasserts that no different state is already registered for the same(id, graphId). Buckets are identity-keyedSets, so duplicates coexist instead of overwriting. Perdocs/architecture/node-data-store.mdthis uniqueness is guaranteed upstream bysubgraphDeduplication.ts; the assert catches regressions of that guarantee.assertthrows in DEV and reports via the registered reporter otherwise, so production behaviour is unchanged.Review Focus
Why the store needs an index rather than a scan. Scanning the bucket per registration is O(n²) over a graph load, so each bucket carries a plain
Map<string, NodeState>keyed`${graphId}:${id}`, plus aMap<NodeState, string>reverse map. The reverse map exists becauseLGraphNode.idcan change after registration — the store's own doc calls out that "renumbering a registered node cannot strand its entry" precisely because membership is identity-based — sodeleteNodemust remove the index entry by state identity, not by recomputing the key from possibly-renumbered fields. Covered byunregisters a state that was renumbered after registration.The same renumbering leaves a stale forward entry pointing at a state whose id has moved on.
claimantRenumberedtreats that slot as vacant rather than a duplicate, so a later node legitimately taking the freed id does not trip a false assert (frees the id a renumbered state vacated).Why idempotent re-registration must not assert.
registerNodeStatere-wraps viareactive(), which returns the cached proxy, so re-registering the same state is an existing legitimate path (see the unregister→register sequences inuseNodeReplacement.ts).claimant === raw— compared aftertoRaw, matching how the reactiveSetitself compares — permits it. Covered byaccepts a state re-registering itselfandtolerates re-registration under the same root graph.The index is deliberately outside the reactive graph: no consumer reads it, it is only asserted against, so making it reactive would add tracking cost to every registration for nothing.
Tests
Added to
src/stores/nodeDataStore.test.tsandsrc/core/graph/nodeShell/nodeShellState.test.ts(the file #14257 moved theLGraphNode.nodeState.test.tslifecycle cases into): cross-root re-registration asserts, unregister after_statereassignment asserts, duplicate(id, graphId)distinct-state registration asserts, idempotent same-state re-registration does not assert, same id in a different owning graph does not assert, register→renumber→unregister stays clean, andclearGraphdrops the index with the bucket.Because
assertthrows in DEV, the existing suite is the false-positive net:pnpm test:unitandpnpm typecheckwere run in full.