Skip to content

shared-node-store: close updateTaskNode() same-field concurrent-write clobber window - #2099

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2097-same-field-clobber
Aug 17, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2097-same-field-clobber

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

  • Closes updateTaskNode(): same-field concurrent writes can still transiently clobber each other (self-correcting, low severity) #2097 — updateTaskNode()'s success-path field-scoping (from shared-node-store: fix updateTaskNode()'s success-path field clobber via shared-reference mutation #2096) stops a write's response from clobbering a concurrently-resolving write's different field, but did not close the analogous same-field case: if write A and write B both change (say) status while A's RPC is still in flight, A's response can transiently overwrite B's still-in-flight optimistic value with A's own stale (pre-B) confirmed value, until B's own write later resolves.
  • Adds a per-node, per-field write-sequence counter (taskFieldWriteSeq / bumpTaskFieldSeq() / getTaskFieldSeq()). updateTaskNode() bumps the sequence for each field it touches at optimistic-apply time (synchronously, before the RPC is even queued) and captures the number. When the RPC resolves, it only applies its confirmed value for a field if the sequence hasn't moved on since — i.e. no newer same-field write raced in ahead of it. A newer write's own RPC (queued behind the first, since PersistenceCoordinator serializes real RPCs per node) still applies its own confirmed value when it resolves, so the store converges either way; this just closes the transient wrong-value window in between.
  • Field-scoped, not node-scoped: a same-field race on status does not suppress an unrelated, non-racing field like priority from applying its own confirmed value.
  • Cleans up the new tracking map alongside the existing versions/pendingUpdates maps in deleteNode() and clearAll().

Test plan

  • New regression test updatetasknode-samefield-clobber-regression.test.ts (3 cases): reproduces the exact same-field race described in updateTaskNode(): same-field concurrent writes can still transiently clobber each other (self-correcting, low severity) #2097, confirmed to fail pre-fix (reverted the source change locally and re-ran — asserted 'in-progress' instead of the expected 'done') and pass post-fix; a second case proves the store still converges to the correct final value once the second write's own RPC completes (i.e. the pre-existing self-correcting behavior isn't broken); a third case proves field-scoping is preserved (a non-racing field on the same write still applies normally).
  • Existing sibling regression tests (updatetasknode-success-clobber-regression.test.ts, updatetasknode-rollback-clobber-regression.test.ts) still pass unchanged — the different-field fix from shared-node-store: fix updateTaskNode()'s success-path field clobber via shared-reference mutation #2096 is untouched.
  • Full frontend suite: bun run test → 211 files / 4661 tests passed.
  • bun run quality:fix clean (eslint, tsc, cargo fmt, cargo clippy -D warnings).

Closes #2097

Field-scoping (from #2096) stops a write's response from clobbering a
concurrently-resolving write's DIFFERENT field, but a write's own
confirmed value for a field it DID change can still transiently
overwrite a newer optimistic write for that SAME field, since the
response reflects the server's state as of this write's own request
and predates the newer write.

Add a per-node, per-field write-sequence counter: updateTaskNode()
bumps it for each field at optimistic-apply time and captures the
number; when its RPC resolves, it only applies its confirmed value
for a field if the sequence hasn't moved on since (no newer same-
field write raced in). The newer write's own RPC still applies its
own confirmed value when it resolves, so the store converges either
way - this just closes the transient wrong-value window in between.

Co-Authored-By: Claude <[email protected]>
Address review finding on #2099: deleteNode()'s optimistic removal wipes
a node's per-field write-sequence map, but the subtree-access-denied
refusal path only restored versions/persistedNodeIds, not this map -
leaving a resurrected node's field sequences silently reset to zero.
Not currently reachable (updateTaskNode() no-ops on a missing node, and
the success handler already gates on the node still being present), but
it broke the restore symmetry with versions/persistedNodeIds and would
become a live gap under a future change to either guard. Capture and
restore the map the same way removedVersion is handled.

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Adversarial review requested via subagent — verdict REQUEST CHANGES, addressed.

Confirmed valid finding: deleteNode()'s optimistic removal wipes taskFieldWriteSeq for the node, but the subtree-access-denied refusal restore path only restored versions/persistedNodeIds (both explicitly captured-and-restored), not taskFieldWriteSeq — breaking the mirror this PR's own commit message claimed. Fixed in 46da26e: capture the node's field-sequence sub-map alongside removedVersion/wasPersisted before the optimistic delete, and restore it the same way in the refusal branch.

On my own re-trace I don't believe this was actually reachable today — updateTaskNode() no-ops on a node not currently in the store, and the success handler already gates on this.nodes.get(nodeId) being present, so no write can straddle the delete-then-restore window to actually exploit a reset counter. But it's a real asymmetry vs. the established pattern and a cheap fix, so applying it removes any doubt and closes the gap against future changes to either guard rather than leaving a latent trap.

Everything else in the review — sequence-counter correctness across 2+ and N+ concurrent writes, the version field staying intentionally ungated, test quality/non-flakiness, and scope discipline — checked out with no changes needed (reviewer independently re-ran the tests against a source revert and confirmed the pre-fix-fails/post-fix-passes claim).

Full suite (211 files / 4661 tests) and quality:fix both green after the fix; pushed and pre-push gate passed.

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Independently re-verified after the adversarial review round:

  • Full diff vs origin/main: exactly 2 files (shared-node-store.svelte.ts, new test file), 410 insertions / 7 deletions — no drift into packages/agent, nlp-engine, skills, eval, playbook, ai-chat, or unrelated Rust formatting.
  • Re-read the complete source diff line by line: the per-field write-sequence guard is correctly field-scoped, version is correctly left unconditional, and the delete-refusal restore symmetry fix (46da26e) correctly captures/restores the same Map reference with no risk of discarding an interim write (none can occur — updateTaskNode() no-ops on a missing node).
  • Fresh full test run: bun run test → 211 files / 4661 tests passed.
  • bun run quality:fix clean (eslint, tsc, cargo fmt, cargo clippy -D warnings).
  • Pre-push gate (test:all + cargo build + e2e) passed on both pushes.

Merging.

@mstomar125
mstomar125 merged commit 98172c1 into main Aug 17, 2026
@mstomar125
mstomar125 deleted the issue-2097-same-field-clobber branch August 17, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

updateTaskNode(): same-field concurrent writes can still transiently clobber each other (self-correcting, low severity)

1 participant