Repository navigation
shared-node-store: close updateTaskNode() same-field concurrent-write clobber window - #2099
Conversation
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]>
|
Adversarial review requested via subagent — verdict REQUEST CHANGES, addressed. Confirmed valid finding: On my own re-trace I don't believe this was actually reachable today — Everything else in the review — sequence-counter correctness across 2+ and N+ concurrent writes, the Full suite (211 files / 4661 tests) and |
|
APPROVE Independently re-verified after the adversarial review round:
Merging. |
Summary
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)statuswhile 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.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, sincePersistenceCoordinatorserializes 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.statusdoes not suppress an unrelated, non-racing field likepriorityfrom applying its own confirmed value.versions/pendingUpdatesmaps indeleteNode()andclearAll().Test plan
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).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.bun run test→ 211 files / 4661 tests passed.bun run quality:fixclean (eslint, tsc, cargo fmt, cargo clippy-D warnings).Closes #2097