Repository navigation
feat(nodeShell): assert node registration-identity invariants - #14443
mattmillerai merged 3 commits into
Conversation
|
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 |
📄 Knowledge reviewDosu skipped reviewing this PR because your organization has used its |
🎨 Storybook: ✅ Built — View Storybook🎭 Playwright: 🕵🏻 0 passed, 0 failed📊 Browser Reports
📦 Bundle Size
⚡ Performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## matt/be-5050-node-shell-state #14443 +/- ##
==============================================================
Coverage 81.03% 81.04%
==============================================================
Files 1899 1899
Lines 109786 109795 +9
Branches 34163 34167 +4
==============================================================
+ Hits 88969 88978 +9
Misses 20423 20423
Partials 394 394
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🔍 Cursor Review — Consolidated panel
Triggered by @mattmillerai.
Found 5 finding(s).
| Severity | Count |
|---|---|
| 🟠 High | 2 |
| 🟡 Medium | 2 |
| 🟢 Low | 1 |
Panel: 8/8 reviewers contributed findings.
|
STACKED — merging lands on Merge #14257 first, or this PR's commits land on that branch rather than the default branch. Review resolution pushed in c6e0242 — all five cursor-review threads addressed (1 code fix, 4 replies). Detail on the threads; the one code change: |
950e26e to
7ca4449
Compare
504ae1f to
789cc6f
Compare
7ca4449 to
af6567c
Compare
registerNodeState now refuses to re-register a node under a different root graph, and unregisterNodeState checks the store's delete result instead of discarding it.
assert throws only in DEV, so both invariant paths must leave the store consistent on their own. registerNodeState now drops the previous root's bucket entry before re-registering, instead of stranding a ghost the renderer keeps drawing in production builds.
Deleting the previous root's bucket entry without clearing _graphId left the node pointing at a bucket it no longer occupies, so a DEV throw could cascade into the unregister-side drift assert.
|
STACKED — merging lands on Rebased onto the latest #14257 tip ( Known blocker outside this PR's scope: the current base tree fails to build/test — |
789cc6f to
097d2b7
Compare
a80a5e1
into
matt/be-5050-node-shell-state
**STACKED — merging lands on `matt/be-5050-node-shell-state` (#14257, which itself targets `feature/ecs-migration`), NOT `main`.** ## ELI-5 When a node joins or leaves a graph, the app files its "shell state" into a store so the renderer can draw it. Two ways that filing can go wrong today fail silently: filing a node that is already filed under a *different* workflow strands the old entry, and un-filing a state the store never held leaves a ghost the renderer keeps drawing. Both now trip an assertion (throws in DEV, reports via the assert reporter in prod) instead of drifting quietly. No behavior changes when the invariants hold. ## What changed `src/core/graph/nodeShell/nodeShellState.ts` - `registerNodeState` asserts `node._graphId` is unset or already equals `graph.rootGraph.id` before overwriting it. Membership is by state identity, so a node re-registered under a second root graph leaves its first bucket entry behind with nothing to remove it. - `unregisterNodeState` captures `deleteNode`'s boolean instead of discarding it and asserts it. `false` means the bucket did not contain `node._state` — identity drift, e.g. `_state` reassigned after registration. Both messages name the node id. `_graphId` is cleared before the assertion so a failing teardown still leaves the node detached rather than half-registered. ## Deliberately not shipped: the duplicate-`NodeState` assertion The third invariant asked for — asserting the store never holds two distinct `NodeState` objects for one `(graphId, id)` — was implemented (an auxiliary forward `Map<string, NodeState>` plus a `Map<NodeState, string>` reverse map per bucket, so a renumbered node still de-indexes by identity) and then **reverted**, because it is not a regression net on this base: it fires on legitimate existing behavior. Evidence, all from the suite on this branch: - `LGraph.serialise.test.ts > can (de)serialise node / group titles` — `new LGraph(data)` (`LGraph.ts:476` → `configure:2636` → `add:1092`) keeps the *persisted* graph id, so a round-tripped copy shares a bucket with the graph it was serialised from and collides on every node id. - `LGraph.test.ts > Link serialization goldens` (4 tests) and `LGraph.test.ts > deduplicateSubgraphNodeIds (via configure) > warns when configuring a host with legacy proxyWidgets…` fail the same way. That is 6 tests, green on this base and green again with the assertion removed — so this is the assertion's premise being wrong, not a latent bug those tests were hiding. `subgraphDeduplication.ts` guarantees id-uniqueness *within* one root graph; it says nothing about two live `LGraph` instances that carry the same id. Making duplicate ids assertable means giving each `LGraph` instance its own bucket identity rather than keying buckets by graph id — a separate change with real blast radius (`getGraphNodesFor` callers, `clearGraph`, the `canvasStore.rootGraphId` readers), not a rider on this one. `docs/architecture/node-data-store.md` records both the two shipped invariants and this gap. ## Tests `nodeShellState.test.ts` gains the two cases; both are red without the production change (verified by stashing it). The cross-root case needs an explicit `second.id = createUuidv4()` — two fresh `LGraph`s both sit at `zeroUuid` until `configure`, so they share a bucket and the invariant genuinely holds. ## Verification Targeted: `nodeShellState.test.ts`, `nodeDataStore.test.ts`, `useNodeReplacement.test.ts`, `LGraph.test.ts`, `LGraph.serialise.test.ts` — 82 tests pass, 0 fail. `oxfmt --check` clean. Full `vitest run` was executed and is the reason the third assertion was reverted (it caught the 6 failures above). That run is **not** a clean-suite claim: this worktree borrows the parent clone's `node_modules`, which predates the `minisearch` dependency this branch adds, so 222 suites failed to resolve imports for reasons unrelated to the diff. Of the tests that did run, the only failures attributable to the diff were the 6 named above; the rest (`assetService`, `useAssetGridSelection`, `onboardingCloudRoutes`, …) are the same load-dependent set #14257 reported. A reviewer should treat repo-wide CI as the authority here, not this local run. Repo-wide `pnpm typecheck` was likewise not run locally — the diff is 11 lines of source plus tests, and both changed files typecheck under vitest's transform.
**STACKED — merging lands on `matt/be-5050-node-shell-state` (#14257, which itself targets `feature/ecs-migration`), NOT `main`.** ## ELI-5 When a node joins or leaves a graph, the app files its "shell state" into a store so the renderer can draw it. Two ways that filing can go wrong today fail silently: filing a node that is already filed under a *different* workflow strands the old entry, and un-filing a state the store never held leaves a ghost the renderer keeps drawing. Both now trip an assertion (throws in DEV, reports via the assert reporter in prod) instead of drifting quietly. No behavior changes when the invariants hold. ## What changed `src/core/graph/nodeShell/nodeShellState.ts` - `registerNodeState` asserts `node._graphId` is unset or already equals `graph.rootGraph.id` before overwriting it. Membership is by state identity, so a node re-registered under a second root graph leaves its first bucket entry behind with nothing to remove it. - `unregisterNodeState` captures `deleteNode`'s boolean instead of discarding it and asserts it. `false` means the bucket did not contain `node._state` — identity drift, e.g. `_state` reassigned after registration. Both messages name the node id. `_graphId` is cleared before the assertion so a failing teardown still leaves the node detached rather than half-registered. ## Deliberately not shipped: the duplicate-`NodeState` assertion The third invariant asked for — asserting the store never holds two distinct `NodeState` objects for one `(graphId, id)` — was implemented (an auxiliary forward `Map<string, NodeState>` plus a `Map<NodeState, string>` reverse map per bucket, so a renumbered node still de-indexes by identity) and then **reverted**, because it is not a regression net on this base: it fires on legitimate existing behavior. Evidence, all from the suite on this branch: - `LGraph.serialise.test.ts > can (de)serialise node / group titles` — `new LGraph(data)` (`LGraph.ts:476` → `configure:2636` → `add:1092`) keeps the *persisted* graph id, so a round-tripped copy shares a bucket with the graph it was serialised from and collides on every node id. - `LGraph.test.ts > Link serialization goldens` (4 tests) and `LGraph.test.ts > deduplicateSubgraphNodeIds (via configure) > warns when configuring a host with legacy proxyWidgets…` fail the same way. That is 6 tests, green on this base and green again with the assertion removed — so this is the assertion's premise being wrong, not a latent bug those tests were hiding. `subgraphDeduplication.ts` guarantees id-uniqueness *within* one root graph; it says nothing about two live `LGraph` instances that carry the same id. Making duplicate ids assertable means giving each `LGraph` instance its own bucket identity rather than keying buckets by graph id — a separate change with real blast radius (`getGraphNodesFor` callers, `clearGraph`, the `canvasStore.rootGraphId` readers), not a rider on this one. `docs/architecture/node-data-store.md` records both the two shipped invariants and this gap. ## Tests `nodeShellState.test.ts` gains the two cases; both are red without the production change (verified by stashing it). The cross-root case needs an explicit `second.id = createUuidv4()` — two fresh `LGraph`s both sit at `zeroUuid` until `configure`, so they share a bucket and the invariant genuinely holds. ## Verification Targeted: `nodeShellState.test.ts`, `nodeDataStore.test.ts`, `useNodeReplacement.test.ts`, `LGraph.test.ts`, `LGraph.serialise.test.ts` — 82 tests pass, 0 fail. `oxfmt --check` clean. Full `vitest run` was executed and is the reason the third assertion was reverted (it caught the 6 failures above). That run is **not** a clean-suite claim: this worktree borrows the parent clone's `node_modules`, which predates the `minisearch` dependency this branch adds, so 222 suites failed to resolve imports for reasons unrelated to the diff. Of the tests that did run, the only failures attributable to the diff were the 6 named above; the rest (`assetService`, `useAssetGridSelection`, `onboardingCloudRoutes`, …) are the same load-dependent set #14257 reported. A reviewer should treat repo-wide CI as the authority here, not this local run. Repo-wide `pnpm typecheck` was likewise not run locally — the diff is 11 lines of source plus tests, and both changed files typecheck under vitest's transform.
**STACKED — merging lands on `matt/be-5050-node-shell-state` (#14257, which itself targets `feature/ecs-migration`), NOT `main`.** ## ELI-5 When a node joins or leaves a graph, the app files its "shell state" into a store so the renderer can draw it. Two ways that filing can go wrong today fail silently: filing a node that is already filed under a *different* workflow strands the old entry, and un-filing a state the store never held leaves a ghost the renderer keeps drawing. Both now trip an assertion (throws in DEV, reports via the assert reporter in prod) instead of drifting quietly. No behavior changes when the invariants hold. ## What changed `src/core/graph/nodeShell/nodeShellState.ts` - `registerNodeState` asserts `node._graphId` is unset or already equals `graph.rootGraph.id` before overwriting it. Membership is by state identity, so a node re-registered under a second root graph leaves its first bucket entry behind with nothing to remove it. - `unregisterNodeState` captures `deleteNode`'s boolean instead of discarding it and asserts it. `false` means the bucket did not contain `node._state` — identity drift, e.g. `_state` reassigned after registration. Both messages name the node id. `_graphId` is cleared before the assertion so a failing teardown still leaves the node detached rather than half-registered. ## Deliberately not shipped: the duplicate-`NodeState` assertion The third invariant asked for — asserting the store never holds two distinct `NodeState` objects for one `(graphId, id)` — was implemented (an auxiliary forward `Map<string, NodeState>` plus a `Map<NodeState, string>` reverse map per bucket, so a renumbered node still de-indexes by identity) and then **reverted**, because it is not a regression net on this base: it fires on legitimate existing behavior. Evidence, all from the suite on this branch: - `LGraph.serialise.test.ts > can (de)serialise node / group titles` — `new LGraph(data)` (`LGraph.ts:476` → `configure:2636` → `add:1092`) keeps the *persisted* graph id, so a round-tripped copy shares a bucket with the graph it was serialised from and collides on every node id. - `LGraph.test.ts > Link serialization goldens` (4 tests) and `LGraph.test.ts > deduplicateSubgraphNodeIds (via configure) > warns when configuring a host with legacy proxyWidgets…` fail the same way. That is 6 tests, green on this base and green again with the assertion removed — so this is the assertion's premise being wrong, not a latent bug those tests were hiding. `subgraphDeduplication.ts` guarantees id-uniqueness *within* one root graph; it says nothing about two live `LGraph` instances that carry the same id. Making duplicate ids assertable means giving each `LGraph` instance its own bucket identity rather than keying buckets by graph id — a separate change with real blast radius (`getGraphNodesFor` callers, `clearGraph`, the `canvasStore.rootGraphId` readers), not a rider on this one. `docs/architecture/node-data-store.md` records both the two shipped invariants and this gap. ## Tests `nodeShellState.test.ts` gains the two cases; both are red without the production change (verified by stashing it). The cross-root case needs an explicit `second.id = createUuidv4()` — two fresh `LGraph`s both sit at `zeroUuid` until `configure`, so they share a bucket and the invariant genuinely holds. ## Verification Targeted: `nodeShellState.test.ts`, `nodeDataStore.test.ts`, `useNodeReplacement.test.ts`, `LGraph.test.ts`, `LGraph.serialise.test.ts` — 82 tests pass, 0 fail. `oxfmt --check` clean. Full `vitest run` was executed and is the reason the third assertion was reverted (it caught the 6 failures above). That run is **not** a clean-suite claim: this worktree borrows the parent clone's `node_modules`, which predates the `minisearch` dependency this branch adds, so 222 suites failed to resolve imports for reasons unrelated to the diff. Of the tests that did run, the only failures attributable to the diff were the 6 named above; the rest (`assetService`, `useAssetGridSelection`, `onboardingCloudRoutes`, …) are the same load-dependent set #14257 reported. A reviewer should treat repo-wide CI as the authority here, not this local run. Repo-wide `pnpm typecheck` was likewise not run locally — the diff is 11 lines of source plus tests, and both changed files typecheck under vitest's transform.
STACKED — merging lands on
matt/be-5050-node-shell-state(#14257, which itself targetsfeature/ecs-migration), NOTmain.ELI-5
When a node joins or leaves a graph, the app files its "shell state" into a store so the renderer can draw it. Two ways that filing can go wrong today fail silently: filing a node that is already filed under a different workflow strands the old entry, and un-filing a state the store never held leaves a ghost the renderer keeps drawing. Both now trip an assertion (throws in DEV, reports via the assert reporter in prod) instead of drifting quietly. No behavior changes when the invariants hold.
What changed
src/core/graph/nodeShell/nodeShellState.tsregisterNodeStateassertsnode._graphIdis unset or already equalsgraph.rootGraph.idbefore overwriting it. Membership is by state identity, so a node re-registered under a second root graph leaves its first bucket entry behind with nothing to remove it.unregisterNodeStatecapturesdeleteNode's boolean instead of discarding it and asserts it.falsemeans the bucket did not containnode._state— identity drift, e.g._statereassigned after registration.Both messages name the node id.
_graphIdis cleared before the assertion so a failing teardown still leaves the node detached rather than half-registered.Deliberately not shipped: the duplicate-
NodeStateassertionThe third invariant asked for — asserting the store never holds two distinct
NodeStateobjects for one(graphId, id)— was implemented (an auxiliary forwardMap<string, NodeState>plus aMap<NodeState, string>reverse map per bucket, so a renumbered node still de-indexes by identity) and then reverted, because it is not a regression net on this base: it fires on legitimate existing behavior.Evidence, all from the suite on this branch:
LGraph.serialise.test.ts > can (de)serialise node / group titles—new LGraph(data)(LGraph.ts:476→configure:2636→add:1092) keeps the persisted graph id, so a round-tripped copy shares a bucket with the graph it was serialised from and collides on every node id.LGraph.test.ts > Link serialization goldens(4 tests) andLGraph.test.ts > deduplicateSubgraphNodeIds (via configure) > warns when configuring a host with legacy proxyWidgets…fail the same way.That is 6 tests, green on this base and green again with the assertion removed — so this is the assertion's premise being wrong, not a latent bug those tests were hiding.
subgraphDeduplication.tsguarantees id-uniqueness within one root graph; it says nothing about two liveLGraphinstances that carry the same id. Making duplicate ids assertable means giving eachLGraphinstance its own bucket identity rather than keying buckets by graph id — a separate change with real blast radius (getGraphNodesForcallers,clearGraph, thecanvasStore.rootGraphIdreaders), not a rider on this one.docs/architecture/node-data-store.mdrecords both the two shipped invariants and this gap.Tests
nodeShellState.test.tsgains the two cases; both are red without the production change (verified by stashing it). The cross-root case needs an explicitsecond.id = createUuidv4()— two freshLGraphs both sit atzeroUuiduntilconfigure, so they share a bucket and the invariant genuinely holds.Verification
Targeted:
nodeShellState.test.ts,nodeDataStore.test.ts,useNodeReplacement.test.ts,LGraph.test.ts,LGraph.serialise.test.ts— 82 tests pass, 0 fail.oxfmt --checkclean.Full
vitest runwas executed and is the reason the third assertion was reverted (it caught the 6 failures above). That run is not a clean-suite claim: this worktree borrows the parent clone'snode_modules, which predates theminisearchdependency this branch adds, so 222 suites failed to resolve imports for reasons unrelated to the diff. Of the tests that did run, the only failures attributable to the diff were the 6 named above; the rest (assetService,useAssetGridSelection,onboardingCloudRoutes, …) are the same load-dependent set #14257 reported. A reviewer should treat repo-wide CI as the authority here, not this local run. Repo-widepnpm typecheckwas likewise not run locally — the diff is 11 lines of source plus tests, and both changed files typecheck under vitest's transform.