Skip to content

fix: clear widget-order and preview-exposure entries on node teardown - #14276

Merged
mattmillerai merged 2 commits into
matt/be-5050-node-shell-statefrom
matt/be-5137-node-teardown-stores
Aug 18, 2026
Merged

mattmillerai merged 2 commits into
matt/be-5050-node-shell-statefrom
matt/be-5137-node-teardown-stores

Conversation

@mattmillerai

Copy link
Copy Markdown
Member

STACKED — merging lands on matt/be-5050-node-shell-state (owned by @mattmillerai), NOT main. That branch is itself based on feature/ecs-migration, where src/core/graph/nodeShell/ lives. Do not merge before its parent lands; GitHub retargets this PR as the stack unwinds.

ELI-5

When a node joins a graph we write it into three places: its shell state, its widget bindings, and its widget ordering (plus preview exposures accumulate against the same bucket). When a node left, we only erased the first one. The leftovers piled up in a bucket shared by the whole workflow and stayed there until the entire graph was thrown away. This adds the missing "undo" for the other two and points every teardown path at it.

Summary

attachNodeToStores registers three things; every teardown path only undid one, so widget-order and preview-exposure entries orphaned in the shared root-graph bucket. This adds detachNodeFromStores as its exact inverse and routes the teardown paths through it.

Changes

  • What: New detachNodeFromStores(graph, node, mode) in nodeShellLifecycle.ts — unregisters the shell state, removes each getWidgetIds(node.widgets) entry from the widget order, and clears the node's preview exposures (String(node.id) host locator, the same key promotionUtils/SubgraphNode write under). unregisterAllNodeStates moves out of nodeShellState.ts and becomes detachAllNodesFromStores in the same module — it needs the root graph to reach those buckets, so it now takes the graph (which carries rootGraph) rather than just _nodes/_subgraphs. Call sites: LGraph.remove (both the per-node teardown and the released-subgraph-definition walk) and releaseGraphStores's non-root branch.
  • Breaking: none — unregisterAllNodeStates had exactly one external caller (LGraph.ts), and no behavior the extension surface can observe changes.

Reachability the leak had (all three are load-bearing, not theoretical)

  • Subgraphs always take the non-root else branch of releaseGraphStores, and LGraph.configure calls clear() first — so re-configuring a subgraph orphaned its nodes' entries.
  • clear() sets id = zeroUuid on exit, so a root graph whose serialized data carries no id keeps taking the else branch for the rest of the session.
  • Plain LGraph.remove(node) leaked per-node on every branch, since it never removed the widget order it added.

Review Focus

The judgment call the ticket left open — deleteWidget vs removeNodeWidgetOrder — is decided per call site, and both are covered by tests. LGraph.remove(node) drops only the ordering and keeps the stored widget values: a single node removal feeds undo/redo and a node moved between graphs (remove then add) must not lose its values. Graph and subgraph-definition teardown (detachAllNodesFromStores) discards them, which is what the root branch already does one line up — clearGraph on widgetValueStore wipes that graph's widget states wholesale, so the non-root path was the inconsistent one.

Riskiest line: deleteWidget in the discard path, because it is the one edit that removes data rather than an index. It is safe because deleteWidget only drops the store's map entry — the widget instance's _state object is untouched, so a widget that survives the clear still reads its own value, and re-registration (setNodeId → registerWidget) writes it back from the widget/serialized data rather than from store leftovers. Without this, a re-configure would silently reuse the stale store value: registerWidget returns the existing state when the type matches and ignores the incoming init.value.

Deliberately not routed through the new helper: useNodeReplacement.replaceWithMapping. It calls unregisterNodeState/registerNodeState for an in-place swap where the new node inherits the same id and re-registers the same widgets — clearing exposures there would drop a replaced host node's promoted previews. It is a replacement, not a teardown.

Deviation from the ticket's sketch: preview exposures are cleared with setExposures(rootGraphId, locator, []) (guarded by a getExposures(...).length read) rather than a removeExposure per name. Same result, one write instead of N, and the guard keeps the reactive exposures ref from being touched on every ordinary node deletion.

Verification

New src/core/graph/nodeShell/nodeShellLifecycle.test.ts covers all three: widget order dropped and values kept on subgraph.remove(node); exposures dropped when a host SubgraphNode is removed; order, values and exposures all released when a zero-uuid root graph is cleared. All three fail on the base branch (verified by stashing the source change and re-running — expected [ Array(1) ] to deeply equal []).

vitest run src/lib/litegraph src/core/graph src/platform/nodeReplacement src/stores/widgetValueStore.test.ts src/composables/node — 1591 passed. pnpm typecheck, pnpm knip, eslint and oxfmt on the changed files: clean.

@mattmillerai mattmillerai added cursor-review Trigger multi-model Cursor agent review on this PR agent-coded Opened by the agent-work code loop labels Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 491fc58d-db15-45ce-8e40-fbfc554bc598

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@mattmillerai
mattmillerai marked this pull request as ready for review July 29, 2026 17:44
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 29, 2026
@dosubot

dosubot Bot commented Jul 29, 2026

Copy link
Copy Markdown

📄 Knowledge review

Dosu skipped reviewing this PR because your organization has used its 200 included credits for the month. Your usage will reset on 2026-08-01. To have Dosu review this PR before then, ask your organization admin to upgrade to a pro account.


Leave Feedback Ask Dosu about ComfyUI_frontend Add Dosu to your team

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

🎨 Storybook: ✅ Built — View Storybook

Details

⏰ Completed at: 08/15/2026, 11:46:40 PM UTC

Links

🎭 Playwright: ✅ 1824 passed, 0 failed · 2 flaky

📊 Browser Reports
  • chromium: View Report (✅ 1803 / ❌ 0 / ⚠️ 2 / ⏭️ 5)
  • chromium-2x: View Report (✅ 2 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • chromium-0.5x: View Report (✅ 1 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • mobile-chrome: View Report (✅ 18 / ❌ 0 / ⚠️ 0 / ⏭️ 0)

📦 Bundle Size

⏳ Size data collection in progress…

⚡ Performance Report

canvas-idle: · 60.0 avg FPS · 59.9 P5 FPS ✅ (target: ≥52) · 0ms TBT · 70.8 MB heap
canvas-mouse-sweep: · 60.0 avg FPS · 59.7 P5 FPS ✅ (target: ≥52) · 0ms TBT · 60.4 MB heap
canvas-zoom-sweep: · 60.0 avg FPS · 59.7 P5 FPS ✅ (target: ≥52) · 0ms TBT · 73.6 MB heap
dom-widget-clipping: · 60.0 avg FPS · 59.9 P5 FPS ✅ (target: ≥52) · 0ms TBT · 62.1 MB heap
large-graph-idle: · 60.0 avg FPS · 59.9 P5 FPS ✅ (target: ≥52) · 0ms TBT · 65.3 MB heap
large-graph-pan: · 60.0 avg FPS · 59.7 P5 FPS ✅ (target: ≥52) · 0ms TBT · 66.8 MB heap
large-graph-zoom: · 60.0 avg FPS · 59.9 P5 FPS ✅ (target: ≥52) · 0ms TBT · 71.9 MB heap
legacy-node-drag: · 60.0 avg FPS · 59.9 P5 FPS ✅ (target: ≥52) · 0ms TBT · 59.0 MB heap
minimap-idle: · 60.0 avg FPS · 59.7 P5 FPS ✅ (target: ≥52) · 0ms TBT · 64.6 MB heap
subgraph-dom-widget-clipping: · 60.0 avg FPS · 59.5 P5 FPS ✅ (target: ≥52) · 0ms TBT · 61.1 MB heap
subgraph-idle: · 60.0 avg FPS · 59.7 P5 FPS ✅ (target: ≥52) · 0ms TBT · 71.6 MB heap
subgraph-mouse-sweep: · 60.0 avg FPS · 59.5 P5 FPS ✅ (target: ≥52) · 0ms TBT · 53.0 MB heap
subgraph-transition-enter: · 60.0 avg FPS · 59.5 P5 FPS ✅ (target: ≥52) · 117ms TBT · 72.8 MB heap
viewport-pan-sweep: · 60.0 avg FPS · 59.7 P5 FPS ✅ (target: ≥52) · 0ms TBT · 55.5 MB heap
vue-large-graph-idle: · 56.3 avg FPS · 59.7 P5 FPS ✅ (target: ≥52) · 0ms TBT · 157.4 MB heap
vue-large-graph-pan: · 56.3 avg FPS · 59.5 P5 FPS ✅ (target: ≥52) · 131ms TBT · 157.7 MB heap
workflow-execution: · 60.0 avg FPS · 59.7 P5 FPS ✅ (target: ≥52) · 0ms TBT · 59.1 MB heap

ℹ️ No baseline found — significance unavailable.

Absolute values
Metric Value
canvas-idle: avg frame time 17ms
canvas-idle: p95 frame time 17ms
canvas-idle: layout duration 0ms
canvas-idle: style recalc duration 6ms
canvas-idle: layout count 0
canvas-idle: style recalc count 7
canvas-idle: task duration 507ms
canvas-idle: script duration 9ms
canvas-idle: TBT 0ms
canvas-idle: heap used 70.8 MB
canvas-idle: DOM nodes 14
canvas-idle: event listeners 4
canvas-mouse-sweep: avg frame time 17ms
canvas-mouse-sweep: p95 frame time 17ms
canvas-mouse-sweep: layout duration 4ms
canvas-mouse-sweep: style recalc duration 49ms
canvas-mouse-sweep: layout count 12
canvas-mouse-sweep: style recalc count 82
canvas-mouse-sweep: task duration 1279ms
canvas-mouse-sweep: script duration 147ms
canvas-mouse-sweep: TBT 0ms
canvas-mouse-sweep: heap used 60.4 MB
canvas-mouse-sweep: DOM nodes -282
canvas-mouse-sweep: event listeners -156
canvas-zoom-sweep: avg frame time 17ms
canvas-zoom-sweep: p95 frame time 17ms
canvas-zoom-sweep: layout duration 1ms
canvas-zoom-sweep: style recalc duration 16ms
canvas-zoom-sweep: layout count 6
canvas-zoom-sweep: style recalc count 31
canvas-zoom-sweep: task duration 374ms
canvas-zoom-sweep: script duration 11ms
canvas-zoom-sweep: TBT 0ms
canvas-zoom-sweep: heap used 73.6 MB
canvas-zoom-sweep: DOM nodes 76
canvas-zoom-sweep: event listeners 19
dom-widget-clipping: avg frame time 17ms
dom-widget-clipping: p95 frame time 17ms
dom-widget-clipping: layout duration 0ms
dom-widget-clipping: style recalc duration 6ms
dom-widget-clipping: layout count 0
dom-widget-clipping: style recalc count 10
dom-widget-clipping: task duration 431ms
dom-widget-clipping: script duration 33ms
dom-widget-clipping: TBT 0ms
dom-widget-clipping: heap used 62.1 MB
dom-widget-clipping: DOM nodes 15
dom-widget-clipping: event listeners 2
large-graph-idle: avg frame time 17ms
large-graph-idle: p95 frame time 17ms
large-graph-idle: layout duration 0ms
large-graph-idle: style recalc duration 4ms
large-graph-idle: layout count 0
large-graph-idle: style recalc count 6
large-graph-idle: task duration 549ms
large-graph-idle: script duration 30ms
large-graph-idle: TBT 0ms
large-graph-idle: heap used 65.3 MB
large-graph-idle: DOM nodes -282
large-graph-idle: event listeners -154
large-graph-pan: avg frame time 17ms
large-graph-pan: p95 frame time 17ms
large-graph-pan: layout duration 0ms
large-graph-pan: style recalc duration 12ms
large-graph-pan: layout count 0
large-graph-pan: style recalc count 66
large-graph-pan: task duration 2274ms
large-graph-pan: script duration 757ms
large-graph-pan: TBT 0ms
large-graph-pan: heap used 66.8 MB
large-graph-pan: DOM nodes -284
large-graph-pan: event listeners -151
large-graph-zoom: avg frame time 17ms
large-graph-zoom: p95 frame time 17ms
large-graph-zoom: layout duration 9ms
large-graph-zoom: style recalc duration 14ms
large-graph-zoom: layout count 60
large-graph-zoom: style recalc count 68
large-graph-zoom: task duration 2342ms
large-graph-zoom: script duration 750ms
large-graph-zoom: TBT 0ms
large-graph-zoom: heap used 71.9 MB
large-graph-zoom: DOM nodes -120
large-graph-zoom: event listeners -86
legacy-node-drag: avg frame time 17ms
legacy-node-drag: p95 frame time 17ms
legacy-node-drag: layout duration 0ms
legacy-node-drag: style recalc duration 7ms
legacy-node-drag: layout count 0
legacy-node-drag: style recalc count 43
legacy-node-drag: task duration 2184ms
legacy-node-drag: script duration 244ms
legacy-node-drag: TBT 0ms
legacy-node-drag: heap used 59.0 MB
legacy-node-drag: DOM nodes -286
legacy-node-drag: event listeners -148
minimap-idle: avg frame time 17ms
minimap-idle: p95 frame time 17ms
minimap-idle: layout duration 0ms
minimap-idle: style recalc duration 4ms
minimap-idle: layout count 0
minimap-idle: style recalc count 4
minimap-idle: task duration 631ms
minimap-idle: script duration 34ms
minimap-idle: TBT 0ms
minimap-idle: heap used 64.6 MB
minimap-idle: DOM nodes -284
minimap-idle: event listeners -169
subgraph-dom-widget-clipping: avg frame time 17ms
subgraph-dom-widget-clipping: p95 frame time 17ms
subgraph-dom-widget-clipping: layout duration 0ms
subgraph-dom-widget-clipping: style recalc duration 11ms
subgraph-dom-widget-clipping: layout count 0
subgraph-dom-widget-clipping: style recalc count 46
subgraph-dom-widget-clipping: task duration 562ms
subgraph-dom-widget-clipping: script duration 144ms
subgraph-dom-widget-clipping: TBT 0ms
subgraph-dom-widget-clipping: heap used 61.1 MB
subgraph-dom-widget-clipping: DOM nodes 17
subgraph-dom-widget-clipping: event listeners 8
subgraph-idle: avg frame time 17ms
subgraph-idle: p95 frame time 17ms
subgraph-idle: layout duration 0ms
subgraph-idle: style recalc duration 7ms
subgraph-idle: layout count 0
subgraph-idle: style recalc count 9
subgraph-idle: task duration 472ms
subgraph-idle: script duration 11ms
subgraph-idle: TBT 0ms
subgraph-idle: heap used 71.6 MB
subgraph-idle: DOM nodes 17
subgraph-idle: event listeners 4
subgraph-mouse-sweep: avg frame time 17ms
subgraph-mouse-sweep: p95 frame time 17ms
subgraph-mouse-sweep: layout duration 5ms
subgraph-mouse-sweep: style recalc duration 38ms
subgraph-mouse-sweep: layout count 16
subgraph-mouse-sweep: style recalc count 78
subgraph-mouse-sweep: task duration 1101ms
subgraph-mouse-sweep: script duration 103ms
subgraph-mouse-sweep: TBT 0ms
subgraph-mouse-sweep: heap used 53.0 MB
subgraph-mouse-sweep: DOM nodes -297
subgraph-mouse-sweep: event listeners -203
subgraph-transition-enter: avg frame time 17ms
subgraph-transition-enter: p95 frame time 17ms
subgraph-transition-enter: layout duration 12ms
subgraph-transition-enter: style recalc duration 30ms
subgraph-transition-enter: layout count 15
subgraph-transition-enter: style recalc count 19
subgraph-transition-enter: task duration 1014ms
subgraph-transition-enter: script duration 23ms
subgraph-transition-enter: TBT 117ms
subgraph-transition-enter: heap used 72.8 MB
subgraph-transition-enter: DOM nodes 13671
subgraph-transition-enter: event listeners 2383
viewport-pan-sweep: avg frame time 17ms
viewport-pan-sweep: p95 frame time 17ms
viewport-pan-sweep: layout duration 0ms
viewport-pan-sweep: style recalc duration 40ms
viewport-pan-sweep: layout count 0
viewport-pan-sweep: style recalc count 247
viewport-pan-sweep: task duration 8138ms
viewport-pan-sweep: script duration 2584ms
viewport-pan-sweep: TBT 0ms
viewport-pan-sweep: heap used 55.5 MB
viewport-pan-sweep: DOM nodes -284
viewport-pan-sweep: event listeners -127
vue-large-graph-idle: avg frame time 18ms
vue-large-graph-idle: p95 frame time 17ms
vue-large-graph-idle: layout duration 0ms
vue-large-graph-idle: style recalc duration 0ms
vue-large-graph-idle: layout count 0
vue-large-graph-idle: style recalc count 0
vue-large-graph-idle: task duration 17594ms
vue-large-graph-idle: script duration 238ms
vue-large-graph-idle: TBT 0ms
vue-large-graph-idle: heap used 157.4 MB
vue-large-graph-idle: DOM nodes -6548
vue-large-graph-idle: event listeners -7469
vue-large-graph-pan: avg frame time 18ms
vue-large-graph-pan: p95 frame time 17ms
vue-large-graph-pan: layout duration 0ms
vue-large-graph-pan: style recalc duration 22ms
vue-large-graph-pan: layout count 0
vue-large-graph-pan: style recalc count 173
vue-large-graph-pan: task duration 22121ms
vue-large-graph-pan: script duration 771ms
vue-large-graph-pan: TBT 131ms
vue-large-graph-pan: heap used 157.7 MB
vue-large-graph-pan: DOM nodes -6548
vue-large-graph-pan: event listeners -7465
workflow-execution: avg frame time 17ms
workflow-execution: p95 frame time 17ms
workflow-execution: layout duration 1ms
workflow-execution: style recalc duration 24ms
workflow-execution: layout count 4
workflow-execution: style recalc count 14
workflow-execution: task duration 138ms
workflow-execution: script duration 9ms
workflow-execution: TBT 0ms
workflow-execution: heap used 59.1 MB
workflow-execution: DOM nodes 121
workflow-execution: event listeners 97
Raw data
{
  "timestamp": "2026-08-15T23:58:02.557Z",
  "gitSha": "924dc50468b7a0e5576da3b02859356b22be0b71",
  "branch": "matt/be-5137-node-teardown-stores",
  "measurements": [
    {
      "name": "canvas-idle",
      "durationMs": 2021.4220000000296,
      "styleRecalcs": 8,
      "styleRecalcDurationMs": 5.958000000000001,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 457.03400000000005,
      "heapDeltaBytes": 5638632,
      "heapUsedBytes": 74168616,
      "domNodes": 16,
      "jsHeapTotalBytes": 21495808,
      "scriptDurationMs": 7.739000000000001,
      "eventListeners": 4,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "canvas-idle",
      "durationMs": 2034.9979999999732,
      "styleRecalcs": 6,
      "styleRecalcDurationMs": 5.661000000000003,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 556.9759999999999,
      "heapDeltaBytes": 5712428,
      "heapUsedBytes": 74330900,
      "domNodes": 12,
      "jsHeapTotalBytes": 20971520,
      "scriptDurationMs": 9.650000000000002,
      "eventListeners": 4,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "canvas-mouse-sweep",
      "durationMs": 2250.655999999992,
      "styleRecalcs": 82,
      "styleRecalcDurationMs": 51.066,
      "layouts": 12,
      "layoutDurationMs": 4.156,
      "taskDurationMs": 1277.004,
      "heapDeltaBytes": -4647612,
      "heapUsedBytes": 63981316,
      "domNodes": -282,
      "jsHeapTotalBytes": 21860352,
      "scriptDurationMs": 144.791,
      "eventListeners": -157,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.699999999999818
    },
    {
      "name": "canvas-mouse-sweep",
      "durationMs": 2274.811999999997,
      "styleRecalcs": 82,
      "styleRecalcDurationMs": 47.772999999999996,
      "layouts": 12,
      "layoutDurationMs": 4.149,
      "taskDurationMs": 1280.2930000000001,
      "heapDeltaBytes": -5779392,
      "heapUsedBytes": 62730952,
      "domNodes": -282,
      "jsHeapTotalBytes": 20287488,
      "scriptDurationMs": 149.114,
      "eventListeners": -155,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.66999999999998,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "canvas-zoom-sweep",
      "durationMs": 1738.5140000000092,
      "styleRecalcs": 31,
      "styleRecalcDurationMs": 14.885,
      "layouts": 6,
      "layoutDurationMs": 0.6539999999999999,
      "taskDurationMs": 364.433,
      "heapDeltaBytes": 8605564,
      "heapUsedBytes": 77196620,
      "domNodes": 77,
      "jsHeapTotalBytes": 21495808,
      "scriptDurationMs": 10.668000000000001,
      "eventListeners": 19,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.670000000000012,
      "p95FrameDurationMs": 16.800000000000182
    },
    {
      "name": "canvas-zoom-sweep",
      "durationMs": 1742.260999999985,
      "styleRecalcs": 30,
      "styleRecalcDurationMs": 17.131,
      "layouts": 6,
      "layoutDurationMs": 0.727,
      "taskDurationMs": 384.50600000000003,
      "heapDeltaBytes": 8560152,
      "heapUsedBytes": 77142516,
      "domNodes": 75,
      "jsHeapTotalBytes": 21495808,
      "scriptDurationMs": 10.866,
      "eventListeners": 19,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "dom-widget-clipping",
      "durationMs": 737.7349999999865,
      "styleRecalcs": 11,
      "styleRecalcDurationMs": 7.146,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 423.09200000000004,
      "heapDeltaBytes": -3860052,
      "heapUsedBytes": 64646696,
      "domNodes": 18,
      "jsHeapTotalBytes": 22282240,
      "scriptDurationMs": 32.102,
      "eventListeners": 2,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.699999999999818
    },
    {
      "name": "dom-widget-clipping",
      "durationMs": 719.2380000000185,
      "styleRecalcs": 8,
      "styleRecalcDurationMs": 4.735999999999999,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 438.31499999999994,
      "heapDeltaBytes": -3082472,
      "heapUsedBytes": 65493600,
      "domNodes": 12,
      "jsHeapTotalBytes": 21757952,
      "scriptDurationMs": 33.612,
      "eventListeners": 2,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.699999999999818
    },
    {
      "name": "large-graph-idle",
      "durationMs": 2033.6189999999874,
      "styleRecalcs": 7,
      "styleRecalcDurationMs": 5.117999999999999,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 538.8870000000002,
      "heapDeltaBytes": 6724228,
      "heapUsedBytes": 69612436,
      "domNodes": -282,
      "jsHeapTotalBytes": -1736704,
      "scriptDurationMs": 29.068000000000005,
      "eventListeners": -155,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "large-graph-idle",
      "durationMs": 2039.4680000000562,
      "styleRecalcs": 5,
      "styleRecalcDurationMs": 3.6850000000000027,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 559.359,
      "heapDeltaBytes": 4398164,
      "heapUsedBytes": 67295612,
      "domNodes": -282,
      "jsHeapTotalBytes": -1998848,
      "scriptDurationMs": 30.186000000000003,
      "eventListeners": -153,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.670000000000012,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "large-graph-pan",
      "durationMs": 3204.272000000003,
      "styleRecalcs": 65,
      "styleRecalcDurationMs": 11.181,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 2235.8879999999995,
      "heapDeltaBytes": 10159732,
      "heapUsedBytes": 74018684,
      "domNodes": -285,
      "jsHeapTotalBytes": 3174400,
      "scriptDurationMs": 737.369,
      "eventListeners": -151,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.66333333333335,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "large-graph-pan",
      "durationMs": 3200.1430000000255,
      "styleRecalcs": 66,
      "styleRecalcDurationMs": 11.892,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 2311.257,
      "heapDeltaBytes": 2407880,
      "heapUsedBytes": 66119708,
      "domNodes": -283,
      "jsHeapTotalBytes": 2387968,
      "scriptDurationMs": 776.32,
      "eventListeners": -151,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "large-graph-zoom",
      "durationMs": 4197.289000000012,
      "styleRecalcs": 68,
      "styleRecalcDurationMs": 13.679,
      "layouts": 60,
      "layoutDurationMs": 8.249,
      "taskDurationMs": 2226.989,
      "heapDeltaBytes": 21425072,
      "heapUsedBytes": 88743160,
      "domNodes": 28,
      "jsHeapTotalBytes": 4718592,
      "scriptDurationMs": 730.94,
      "eventListeners": 12,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "large-graph-zoom",
      "durationMs": 4416.111000000001,
      "styleRecalcs": 68,
      "styleRecalcDurationMs": 14.793999999999999,
      "layouts": 60,
      "layoutDurationMs": 8.819,
      "taskDurationMs": 2456.067,
      "heapDeltaBytes": -5581616,
      "heapUsedBytes": 61976564,
      "domNodes": -267,
      "jsHeapTotalBytes": 2195456,
      "scriptDurationMs": 769.359,
      "eventListeners": -183,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "legacy-node-drag",
      "durationMs": 3195.0120000000197,
      "styleRecalcs": 42,
      "styleRecalcDurationMs": 6.662000000000001,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 2015.5069999999998,
      "heapDeltaBytes": -336900,
      "heapUsedBytes": 67793336,
      "domNodes": -286,
      "jsHeapTotalBytes": 6807552,
      "scriptDurationMs": 214.61300000000003,
      "eventListeners": -156,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "legacy-node-drag",
      "durationMs": 3509.0450000000146,
      "styleRecalcs": 43,
      "styleRecalcDurationMs": 7.456,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 2352.43,
      "heapDeltaBytes": -7747044,
      "heapUsedBytes": 55841468,
      "domNodes": -286,
      "jsHeapTotalBytes": 5865472,
      "scriptDurationMs": 272.895,
      "eventListeners": -139,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "minimap-idle",
      "durationMs": 2019.0620000000195,
      "styleRecalcs": 4,
      "styleRecalcDurationMs": 3.057999999999998,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 551.9859999999999,
      "heapDeltaBytes": 4680912,
      "heapUsedBytes": 68395688,
      "domNodes": -282,
      "jsHeapTotalBytes": -2523136,
      "scriptDurationMs": 33.17700000000001,
      "eventListeners": -155,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.66333333333332,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "minimap-idle",
      "durationMs": 2016.1500000000387,
      "styleRecalcs": 4,
      "styleRecalcDurationMs": 3.962999999999998,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 709.7789999999999,
      "heapDeltaBytes": 2657256,
      "heapUsedBytes": 67036404,
      "domNodes": -286,
      "jsHeapTotalBytes": 1409024,
      "scriptDurationMs": 35.22999999999999,
      "eventListeners": -183,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "subgraph-dom-widget-clipping",
      "durationMs": 777.6569999999765,
      "styleRecalcs": 46,
      "styleRecalcDurationMs": 13.152,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 577.9730000000001,
      "heapDeltaBytes": -5413364,
      "heapUsedBytes": 63923540,
      "domNodes": 18,
      "jsHeapTotalBytes": 22020096,
      "scriptDurationMs": 145.51600000000002,
      "eventListeners": 8,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "subgraph-dom-widget-clipping",
      "durationMs": 773.3729999999923,
      "styleRecalcs": 45,
      "styleRecalcDurationMs": 9.286,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 546.261,
      "heapDeltaBytes": -4942740,
      "heapUsedBytes": 64299964,
      "domNodes": 16,
      "jsHeapTotalBytes": 22282240,
      "scriptDurationMs": 141.66899999999998,
      "eventListeners": 8,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.800000000000182
    },
    {
      "name": "subgraph-idle",
      "durationMs": 1994.436999999948,
      "styleRecalcs": 8,
      "styleRecalcDurationMs": 5.7459999999999996,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 433.37499999999994,
      "heapDeltaBytes": 5743164,
      "heapUsedBytes": 75191784,
      "domNodes": 16,
      "jsHeapTotalBytes": 20709376,
      "scriptDurationMs": 6.572000000000002,
      "eventListeners": 4,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.66999999999998,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "subgraph-idle",
      "durationMs": 2050.591999999938,
      "styleRecalcs": 9,
      "styleRecalcDurationMs": 7.827000000000001,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 511.05999999999995,
      "heapDeltaBytes": 5746968,
      "heapUsedBytes": 75066688,
      "domNodes": 18,
      "jsHeapTotalBytes": 20971520,
      "scriptDurationMs": 15.262999999999998,
      "eventListeners": 4,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "subgraph-mouse-sweep",
      "durationMs": 1872.4970000000098,
      "styleRecalcs": 78,
      "styleRecalcDurationMs": 36.57,
      "layouts": 16,
      "layoutDurationMs": 4.594,
      "taskDurationMs": 1081.226,
      "heapDeltaBytes": -13746564,
      "heapUsedBytes": 55384284,
      "domNodes": -296,
      "jsHeapTotalBytes": 20418560,
      "scriptDurationMs": 97.176,
      "eventListeners": -203,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.800000000000182
    },
    {
      "name": "subgraph-mouse-sweep",
      "durationMs": 1880.4470000000038,
      "styleRecalcs": 77,
      "styleRecalcDurationMs": 38.86600000000001,
      "layouts": 16,
      "layoutDurationMs": 4.965,
      "taskDurationMs": 1121.7540000000001,
      "heapDeltaBytes": -13383640,
      "heapUsedBytes": 55807028,
      "domNodes": -298,
      "jsHeapTotalBytes": 20942848,
      "scriptDurationMs": 109.318,
      "eventListeners": -203,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.800000000000182
    },
    {
      "name": "subgraph-transition-enter",
      "durationMs": 1402.5270000000774,
      "styleRecalcs": 19,
      "styleRecalcDurationMs": 29.659999999999993,
      "layouts": 15,
      "layoutDurationMs": 11.515,
      "taskDurationMs": 1014.229,
      "heapDeltaBytes": -9515000,
      "heapUsedBytes": 76330812,
      "domNodes": 13671,
      "jsHeapTotalBytes": 9961472,
      "scriptDurationMs": 22.60799999999999,
      "eventListeners": 2383,
      "totalBlockingTimeMs": 117,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "viewport-pan-sweep",
      "durationMs": 12219.30999999995,
      "styleRecalcs": 247,
      "styleRecalcDurationMs": 40.01,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 7670.727,
      "heapDeltaBytes": -4578300,
      "heapUsedBytes": 57954256,
      "domNodes": -282,
      "jsHeapTotalBytes": 3506176,
      "scriptDurationMs": 2455.447,
      "eventListeners": -127,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "viewport-pan-sweep",
      "durationMs": 12422.674999999912,
      "styleRecalcs": 246,
      "styleRecalcDurationMs": 40.856,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 8604.331999999999,
      "heapDeltaBytes": -4448456,
      "heapUsedBytes": 58483820,
      "domNodes": -285,
      "jsHeapTotalBytes": 2719744,
      "scriptDurationMs": 2712.305,
      "eventListeners": -127,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "vue-large-graph-idle",
      "durationMs": 18507.50300000004,
      "styleRecalcs": 0,
      "styleRecalcDurationMs": 0,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 17738.677,
      "heapDeltaBytes": -25968640,
      "heapUsedBytes": 165926444,
      "domNodes": -6548,
      "jsHeapTotalBytes": 3727360,
      "scriptDurationMs": 246.31499999999997,
      "eventListeners": -7471,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 17.780000000000047,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "vue-large-graph-idle",
      "durationMs": 18055.366999999933,
      "styleRecalcs": 0,
      "styleRecalcDurationMs": 0,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 17448.775,
      "heapDeltaBytes": -42701324,
      "heapUsedBytes": 164113252,
      "domNodes": -6548,
      "jsHeapTotalBytes": 1368064,
      "scriptDurationMs": 230.337,
      "eventListeners": -7467,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 17.77333333333336,
      "p95FrameDurationMs": 16.700000000000728
    },
    {
      "name": "vue-large-graph-pan",
      "durationMs": 22342.284000000007,
      "styleRecalcs": 171,
      "styleRecalcDurationMs": 22.32600000000001,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 22080.069000000003,
      "heapDeltaBytes": -3396104,
      "heapUsedBytes": 175231176,
      "domNodes": -6548,
      "jsHeapTotalBytes": 2347008,
      "scriptDurationMs": 771.828,
      "eventListeners": -7465,
      "totalBlockingTimeMs": 90,
      "frameDurationMs": 17.776666666666763,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "vue-large-graph-pan",
      "durationMs": 22545.338000000014,
      "styleRecalcs": 175,
      "styleRecalcDurationMs": 21.417999999999992,
      "layouts": 0,
      "layoutDurationMs": 0,
      "taskDurationMs": 22162.836,
      "heapDeltaBytes": -37241032,
      "heapUsedBytes": 155456032,
      "domNodes": -6548,
      "jsHeapTotalBytes": 1892352,
      "scriptDurationMs": 769.302,
      "eventListeners": -7465,
      "totalBlockingTimeMs": 172,
      "frameDurationMs": 17.776666666666642,
      "p95FrameDurationMs": 16.799999999999272
    },
    {
      "name": "workflow-execution",
      "durationMs": 467.7649999999858,
      "styleRecalcs": 13,
      "styleRecalcDurationMs": 23.226,
      "layouts": 4,
      "layoutDurationMs": 1.5399999999999998,
      "taskDurationMs": 140.727,
      "heapDeltaBytes": -14005104,
      "heapUsedBytes": 52156608,
      "domNodes": 120,
      "jsHeapTotalBytes": 10223616,
      "scriptDurationMs": 8.991000000000003,
      "eventListeners": 97,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.666666666666668,
      "p95FrameDurationMs": 16.699999999999818
    },
    {
      "name": "workflow-execution",
      "durationMs": 483.56200000000626,
      "styleRecalcs": 15,
      "styleRecalcDurationMs": 24.166,
      "layouts": 3,
      "layoutDurationMs": 0.803,
      "taskDurationMs": 135.034,
      "heapDeltaBytes": 5367932,
      "heapUsedBytes": 71759256,
      "domNodes": 121,
      "jsHeapTotalBytes": 5505024,
      "scriptDurationMs": 9.708000000000002,
      "eventListeners": 97,
      "totalBlockingTimeMs": 0,
      "frameDurationMs": 16.670000000000012,
      "p95FrameDurationMs": 16.800000000000182
    }
  ]
}

@codecov

codecov Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/core/graph/nodeShell/nodeShellLifecycle.ts 94.11% 1 Missing ⚠️
@@                       Coverage Diff                        @@
##             matt/be-5050-node-shell-state   #14276   +/-   ##
================================================================
  Coverage                                 ?   81.96%           
================================================================
  Files                                    ?     1902           
  Lines                                    ?   116021           
  Branches                                 ?    33354           
================================================================
  Hits                                     ?    95100           
  Misses                                   ?    20474           
  Partials                                 ?      447           
Flag Coverage Δ
unit 73.23% <96.29%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/core/graph/nodeShell/nodeShellState.ts 100.00% <ø> (ø)
src/lib/litegraph/src/LGraph.ts 81.45% <ø> (ø)
src/stores/widgetValueStore.ts 100.00% <100.00%> (ø)
src/core/graph/nodeShell/nodeShellLifecycle.ts 95.65% <94.11%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Cursor Review — Consolidated panel

Triggered by @mattmillerai.

Found 6 finding(s).

Severity Count
🟠 High 1
🟡 Medium 2
🟢 Low 3

Panel: 8/8 reviewers contributed findings.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 29, 2026
@mattmillerai

Copy link
Copy Markdown
Member Author

STACKED — merging lands on matt/be-5050-node-shell-state (PR #14257, mattmillerai), NOT main. That base itself targets feature/ecs-migration, so land the chain bottom-up.

Review pass on the 6 cursor-review findings:

Fixed (0a9ee19) — widget release now reads the node's order record in widgetValueStore instead of the live node.widgets. The two diverge: PrimitiveNode._removeWidgets empties the array without unregistering (widgetInputs.ts:397), so removing that node orphaned exactly the entries this PR closes. Regression test verified failing on the previous commit. As a side effect no id round-trips through parseWidgetId any more, so an un-keyable projection id can no longer throw mid-teardown and strand a partially-detached node.

Not changed, with evidence on each thread — the zero-uuid cross-graph delete (only two new LGraph( sites in product code, and the non-app one passes an explicit uuid), the two keep-values asymmetries (both need a bare remove → re-add of the same node object; undo is a full loadGraphData, and convertToSubgraph re-creates from serialized data, so configure always re-registers/re-hydrates), and path-qualified host locators (every writer keys on String(node.id); nesting is resolved at read time).

No follow-ups filed — the unreachable findings would be hardening against cases current code can't produce.

@mattmillerai
mattmillerai force-pushed the matt/be-5050-node-shell-state branch from 950e26e to 7ca4449 Compare August 12, 2026 21:41
@mattmillerai
mattmillerai force-pushed the matt/be-5137-node-teardown-stores branch from b7423a4 to a2f0cb3 Compare August 12, 2026 21:41
@mattmillerai
mattmillerai force-pushed the matt/be-5050-node-shell-state branch from 7ca4449 to af6567c Compare August 15, 2026 10:45
attachNodeToStores registers a node's shell state, widget bindings and
widget order, but every teardown path only undid the shell state, so
widget-order and preview-exposure entries orphaned in the shared root
bucket until the whole root graph was wiped.

Add detachNodeFromStores as the exact inverse of attachNodeToStores and
route LGraph.remove and the graph-wide walk through it. Single-node
removal keeps stored widget values (it may be undone); a graph or
subgraph-definition teardown discards them, matching the whole-bucket
wipe a root graph already performs.
releaseNodeWidgets derived the ids to clean from node.widgets, which
diverges from what the store tracks: PrimitiveNode empties its widget
array (widgetInputs._removeWidgets) without unregistering, so removing
that node left its order and value entries behind — the leak this change
set out to close.

Move the release into widgetValueStore, keyed by the node's own order
record, which registerWidget keeps authoritative. Ids no longer round-trip
through parseWidgetId either, so an un-keyable id can't throw mid-teardown.
@mattmillerai

Copy link
Copy Markdown
Member Author

STACKED — merging lands on matt/be-5050-node-shell-state (owned by #14257, mattmillerai), NOT main.

Rebased onto the current tip of #14257 to resolve the merge conflict (that branch was force-pushed/rebased after this PR branched off it). Also fixed: #14257's own rebase left LGraph.ts with 5 undefined store references (useLinkStore, usePreviewExposureStore, useWidgetValueStore, useRerouteStore, useNodeDataStore — missing imports, confirmed failing #14257's own CI typecheck), and its independent clear() refactor (teardownOwnedGraphs) reintroduced the exact widget-order/preview-exposure leak this PR fixes on a path this PR's commits never touched — closed that gap too, with this PR's existing tests now covering it.

@mattmillerai
mattmillerai force-pushed the matt/be-5137-node-teardown-stores branch from a2f0cb3 to b5efa00 Compare August 15, 2026 23:44
@github-actions github-actions Bot added the risk:R3 PR risk grade (advisory shadow check; grader-owned) label Aug 15, 2026
@mattmillerai
mattmillerai merged commit 6ae10d9 into matt/be-5050-node-shell-state Aug 18, 2026
65 of 66 checks passed
@mattmillerai
mattmillerai deleted the matt/be-5137-node-teardown-stores branch August 18, 2026 20:32
mattmillerai added a commit that referenced this pull request Aug 20, 2026
…#14276)

**STACKED — merging lands on `matt/be-5050-node-shell-state` (owned by
@mattmillerai), NOT `main`.** That branch is itself based on
`feature/ecs-migration`, where `src/core/graph/nodeShell/` lives. Do not
merge before its parent lands; GitHub retargets this PR as the stack
unwinds.

## ELI-5

When a node joins a graph we write it into three places: its shell
state, its widget bindings, and its widget ordering (plus preview
exposures accumulate against the same bucket). When a node left, we only
erased the first one. The leftovers piled up in a bucket shared by the
whole workflow and stayed there until the entire graph was thrown away.
This adds the missing "undo" for the other two and points every teardown
path at it.

## Summary

`attachNodeToStores` registers three things; every teardown path only
undid one, so widget-order and preview-exposure entries orphaned in the
shared root-graph bucket. This adds `detachNodeFromStores` as its exact
inverse and routes the teardown paths through it.

## Changes

- **What**: New `detachNodeFromStores(graph, node, mode)` in
`nodeShellLifecycle.ts` — unregisters the shell state, removes each
`getWidgetIds(node.widgets)` entry from the widget order, and clears the
node's preview exposures (`String(node.id)` host locator, the same key
`promotionUtils`/`SubgraphNode` write under). `unregisterAllNodeStates`
moves out of `nodeShellState.ts` and becomes `detachAllNodesFromStores`
in the same module — it needs the root graph to reach those buckets, so
it now takes the graph (which carries `rootGraph`) rather than just
`_nodes`/`_subgraphs`. Call sites: `LGraph.remove` (both the per-node
teardown and the released-subgraph-definition walk) and
`releaseGraphStores`'s non-root branch.
- **Breaking**: none — `unregisterAllNodeStates` had exactly one
external caller (`LGraph.ts`), and no behavior the extension surface can
observe changes.

## Reachability the leak had (all three are load-bearing, not
theoretical)

- Subgraphs always take the non-root `else` branch of
`releaseGraphStores`, and `LGraph.configure` calls `clear()` first — so
re-configuring a subgraph orphaned its nodes' entries.
- `clear()` sets `id = zeroUuid` on exit, so a root graph whose
serialized data carries no id keeps taking the `else` branch for the
rest of the session.
- Plain `LGraph.remove(node)` leaked per-node on every branch, since it
never removed the widget order it added.

## Review Focus

**The judgment call the ticket left open — `deleteWidget` vs
`removeNodeWidgetOrder` — is decided per call site, and both are covered
by tests.** `LGraph.remove(node)` drops only the ordering and **keeps**
the stored widget values: a single node removal feeds undo/redo and a
node moved between graphs (`remove` then `add`) must not lose its
values. Graph and subgraph-definition teardown
(`detachAllNodesFromStores`) **discards** them, which is what the root
branch already does one line up — `clearGraph` on `widgetValueStore`
wipes that graph's widget states wholesale, so the non-root path was the
inconsistent one.

**Riskiest line: `deleteWidget` in the discard path**, because it is the
one edit that removes data rather than an index. It is safe because
`deleteWidget` only drops the store's map entry — the widget instance's
`_state` object is untouched, so a widget that survives the clear still
reads its own value, and re-registration (`setNodeId` →
`registerWidget`) writes it back from the widget/serialized data rather
than from store leftovers. Without this, a re-configure would silently
reuse the *stale* store value: `registerWidget` returns the existing
state when the type matches and ignores the incoming `init.value`.

**Deliberately not routed through the new helper:**
`useNodeReplacement.replaceWithMapping`. It calls
`unregisterNodeState`/`registerNodeState` for an in-place swap where the
new node inherits the same id and re-registers the same widgets —
clearing exposures there would drop a replaced host node's promoted
previews. It is a replacement, not a teardown.

**Deviation from the ticket's sketch:** preview exposures are cleared
with `setExposures(rootGraphId, locator, [])` (guarded by a
`getExposures(...).length` read) rather than a `removeExposure` per
name. Same result, one write instead of N, and the guard keeps the
reactive `exposures` ref from being touched on every ordinary node
deletion.

## Verification

New `src/core/graph/nodeShell/nodeShellLifecycle.test.ts` covers all
three: widget order dropped and values kept on `subgraph.remove(node)`;
exposures dropped when a host `SubgraphNode` is removed; order, values
and exposures all released when a zero-uuid root graph is cleared. **All
three fail on the base branch** (verified by stashing the source change
and re-running — `expected [ Array(1) ] to deeply equal []`).

`vitest run src/lib/litegraph src/core/graph
src/platform/nodeReplacement src/stores/widgetValueStore.test.ts
src/composables/node` — 1591 passed. `pnpm typecheck`, `pnpm knip`,
eslint and oxfmt on the changed files: clean.
DrJKL pushed a commit that referenced this pull request Aug 22, 2026
…#14276)

**STACKED — merging lands on `matt/be-5050-node-shell-state` (owned by
@mattmillerai), NOT `main`.** That branch is itself based on
`feature/ecs-migration`, where `src/core/graph/nodeShell/` lives. Do not
merge before its parent lands; GitHub retargets this PR as the stack
unwinds.

## ELI-5

When a node joins a graph we write it into three places: its shell
state, its widget bindings, and its widget ordering (plus preview
exposures accumulate against the same bucket). When a node left, we only
erased the first one. The leftovers piled up in a bucket shared by the
whole workflow and stayed there until the entire graph was thrown away.
This adds the missing "undo" for the other two and points every teardown
path at it.

## Summary

`attachNodeToStores` registers three things; every teardown path only
undid one, so widget-order and preview-exposure entries orphaned in the
shared root-graph bucket. This adds `detachNodeFromStores` as its exact
inverse and routes the teardown paths through it.

## Changes

- **What**: New `detachNodeFromStores(graph, node, mode)` in
`nodeShellLifecycle.ts` — unregisters the shell state, removes each
`getWidgetIds(node.widgets)` entry from the widget order, and clears the
node's preview exposures (`String(node.id)` host locator, the same key
`promotionUtils`/`SubgraphNode` write under). `unregisterAllNodeStates`
moves out of `nodeShellState.ts` and becomes `detachAllNodesFromStores`
in the same module — it needs the root graph to reach those buckets, so
it now takes the graph (which carries `rootGraph`) rather than just
`_nodes`/`_subgraphs`. Call sites: `LGraph.remove` (both the per-node
teardown and the released-subgraph-definition walk) and
`releaseGraphStores`'s non-root branch.
- **Breaking**: none — `unregisterAllNodeStates` had exactly one
external caller (`LGraph.ts`), and no behavior the extension surface can
observe changes.

## Reachability the leak had (all three are load-bearing, not
theoretical)

- Subgraphs always take the non-root `else` branch of
`releaseGraphStores`, and `LGraph.configure` calls `clear()` first — so
re-configuring a subgraph orphaned its nodes' entries.
- `clear()` sets `id = zeroUuid` on exit, so a root graph whose
serialized data carries no id keeps taking the `else` branch for the
rest of the session.
- Plain `LGraph.remove(node)` leaked per-node on every branch, since it
never removed the widget order it added.

## Review Focus

**The judgment call the ticket left open — `deleteWidget` vs
`removeNodeWidgetOrder` — is decided per call site, and both are covered
by tests.** `LGraph.remove(node)` drops only the ordering and **keeps**
the stored widget values: a single node removal feeds undo/redo and a
node moved between graphs (`remove` then `add`) must not lose its
values. Graph and subgraph-definition teardown
(`detachAllNodesFromStores`) **discards** them, which is what the root
branch already does one line up — `clearGraph` on `widgetValueStore`
wipes that graph's widget states wholesale, so the non-root path was the
inconsistent one.

**Riskiest line: `deleteWidget` in the discard path**, because it is the
one edit that removes data rather than an index. It is safe because
`deleteWidget` only drops the store's map entry — the widget instance's
`_state` object is untouched, so a widget that survives the clear still
reads its own value, and re-registration (`setNodeId` →
`registerWidget`) writes it back from the widget/serialized data rather
than from store leftovers. Without this, a re-configure would silently
reuse the *stale* store value: `registerWidget` returns the existing
state when the type matches and ignores the incoming `init.value`.

**Deliberately not routed through the new helper:**
`useNodeReplacement.replaceWithMapping`. It calls
`unregisterNodeState`/`registerNodeState` for an in-place swap where the
new node inherits the same id and re-registers the same widgets —
clearing exposures there would drop a replaced host node's promoted
previews. It is a replacement, not a teardown.

**Deviation from the ticket's sketch:** preview exposures are cleared
with `setExposures(rootGraphId, locator, [])` (guarded by a
`getExposures(...).length` read) rather than a `removeExposure` per
name. Same result, one write instead of N, and the guard keeps the
reactive `exposures` ref from being touched on every ordinary node
deletion.

## Verification

New `src/core/graph/nodeShell/nodeShellLifecycle.test.ts` covers all
three: widget order dropped and values kept on `subgraph.remove(node)`;
exposures dropped when a host `SubgraphNode` is removed; order, values
and exposures all released when a zero-uuid root graph is cleared. **All
three fail on the base branch** (verified by stashing the source change
and re-running — `expected [ Array(1) ] to deeply equal []`).

`vitest run src/lib/litegraph src/core/graph
src/platform/nodeReplacement src/stores/widgetValueStore.test.ts
src/composables/node` — 1591 passed. `pnpm typecheck`, `pnpm knip`,
eslint and oxfmt on the changed files: clean.

Amp-Thread-ID: https://ampcode.com/threads/T-01a027af-1c32-7532-84f9-b94aa90620fa
DrJKL pushed a commit that referenced this pull request Aug 22, 2026
…#14276)

**STACKED — merging lands on `matt/be-5050-node-shell-state` (owned by
@mattmillerai), NOT `main`.** That branch is itself based on
`feature/ecs-migration`, where `src/core/graph/nodeShell/` lives. Do not
merge before its parent lands; GitHub retargets this PR as the stack
unwinds.

## ELI-5

When a node joins a graph we write it into three places: its shell
state, its widget bindings, and its widget ordering (plus preview
exposures accumulate against the same bucket). When a node left, we only
erased the first one. The leftovers piled up in a bucket shared by the
whole workflow and stayed there until the entire graph was thrown away.
This adds the missing "undo" for the other two and points every teardown
path at it.

## Summary

`attachNodeToStores` registers three things; every teardown path only
undid one, so widget-order and preview-exposure entries orphaned in the
shared root-graph bucket. This adds `detachNodeFromStores` as its exact
inverse and routes the teardown paths through it.

## Changes

- **What**: New `detachNodeFromStores(graph, node, mode)` in
`nodeShellLifecycle.ts` — unregisters the shell state, removes each
`getWidgetIds(node.widgets)` entry from the widget order, and clears the
node's preview exposures (`String(node.id)` host locator, the same key
`promotionUtils`/`SubgraphNode` write under). `unregisterAllNodeStates`
moves out of `nodeShellState.ts` and becomes `detachAllNodesFromStores`
in the same module — it needs the root graph to reach those buckets, so
it now takes the graph (which carries `rootGraph`) rather than just
`_nodes`/`_subgraphs`. Call sites: `LGraph.remove` (both the per-node
teardown and the released-subgraph-definition walk) and
`releaseGraphStores`'s non-root branch.
- **Breaking**: none — `unregisterAllNodeStates` had exactly one
external caller (`LGraph.ts`), and no behavior the extension surface can
observe changes.

## Reachability the leak had (all three are load-bearing, not
theoretical)

- Subgraphs always take the non-root `else` branch of
`releaseGraphStores`, and `LGraph.configure` calls `clear()` first — so
re-configuring a subgraph orphaned its nodes' entries.
- `clear()` sets `id = zeroUuid` on exit, so a root graph whose
serialized data carries no id keeps taking the `else` branch for the
rest of the session.
- Plain `LGraph.remove(node)` leaked per-node on every branch, since it
never removed the widget order it added.

## Review Focus

**The judgment call the ticket left open — `deleteWidget` vs
`removeNodeWidgetOrder` — is decided per call site, and both are covered
by tests.** `LGraph.remove(node)` drops only the ordering and **keeps**
the stored widget values: a single node removal feeds undo/redo and a
node moved between graphs (`remove` then `add`) must not lose its
values. Graph and subgraph-definition teardown
(`detachAllNodesFromStores`) **discards** them, which is what the root
branch already does one line up — `clearGraph` on `widgetValueStore`
wipes that graph's widget states wholesale, so the non-root path was the
inconsistent one.

**Riskiest line: `deleteWidget` in the discard path**, because it is the
one edit that removes data rather than an index. It is safe because
`deleteWidget` only drops the store's map entry — the widget instance's
`_state` object is untouched, so a widget that survives the clear still
reads its own value, and re-registration (`setNodeId` →
`registerWidget`) writes it back from the widget/serialized data rather
than from store leftovers. Without this, a re-configure would silently
reuse the *stale* store value: `registerWidget` returns the existing
state when the type matches and ignores the incoming `init.value`.

**Deliberately not routed through the new helper:**
`useNodeReplacement.replaceWithMapping`. It calls
`unregisterNodeState`/`registerNodeState` for an in-place swap where the
new node inherits the same id and re-registers the same widgets —
clearing exposures there would drop a replaced host node's promoted
previews. It is a replacement, not a teardown.

**Deviation from the ticket's sketch:** preview exposures are cleared
with `setExposures(rootGraphId, locator, [])` (guarded by a
`getExposures(...).length` read) rather than a `removeExposure` per
name. Same result, one write instead of N, and the guard keeps the
reactive `exposures` ref from being touched on every ordinary node
deletion.

## Verification

New `src/core/graph/nodeShell/nodeShellLifecycle.test.ts` covers all
three: widget order dropped and values kept on `subgraph.remove(node)`;
exposures dropped when a host `SubgraphNode` is removed; order, values
and exposures all released when a zero-uuid root graph is cleared. **All
three fail on the base branch** (verified by stashing the source change
and re-running — `expected [ Array(1) ] to deeply equal []`).

`vitest run src/lib/litegraph src/core/graph
src/platform/nodeReplacement src/stores/widgetValueStore.test.ts
src/composables/node` — 1591 passed. `pnpm typecheck`, `pnpm knip`,
eslint and oxfmt on the changed files: clean.

Amp-Thread-ID: https://ampcode.com/threads/T-01a027af-1c32-7532-84f9-b94aa90620fa
@huang47 huang47 added the risk:xhigh PR risk grade (advisory shadow check; grader-owned) label Sep 2, 2026 — with ChatGPT Codex Connector
@huang47 huang47 removed the risk:R3 PR risk grade (advisory shadow check; grader-owned) label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-coded Opened by the agent-work code loop cursor-review Trigger multi-model Cursor agent review on this PR risk:xhigh PR risk grade (advisory shadow check; grader-owned) size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants