Repository navigation
shared-node-store: fix updateTaskNode()'s unconditional failure-rollback clobbering a queued write - #2095
Merged
Conversation
…ack clobbering a queued write updateTaskNode()'s catch handler unconditionally called this.nodesSet(nodeId, existingNode) on ANY write failure (OCC or not), where existingNode is the snapshot captured before THIS call's own optimistic update. If a second updateTaskNode() call for the same node landed and applied its own optimistic update while the first was still executing, and the first then failed, this line overwrote the store with the first write's stale pre-edit snapshot — discarding the second write's optimistic value (or, for the OCC direct-hydration branch, defeating the hasPending-aware skip-while- editing guard that runs immediately afterward, since the clobber had already happened before that guard's decision even executed). updateNode()'s sibling catch handler doesn't have this problem: it calls rollbackUpdate(), which only rewinds bookkeeping (the pending- update list, the version counter) and re-notifies with whatever the store CURRENTLY holds — it never calls nodesSet() and never touches node content. Fixed updateTaskNode()'s catch handler to match: instead of force- reverting to existingNode, it now notifies subscribers with whatever the store currently holds. updateTaskNode() doesn't track a NodeUpdate/pendingUpdates entry the way updateNode() does, so rollbackUpdate() itself isn't directly reusable here; the fix mirrors its no-op-on-content behavior directly. Added updatetasknode-rollback-clobber-regression.test.ts, verified to fail against the pre-fix code: a queued second write's still-in-flight optimistic value survives the first write's non-OCC failure, and an isolated non-OCC failure leaves the optimistic edit in place (matching updateNode()'s design) instead of reverting it. Also fixed shared-node-store-skip-while-editing.test.ts's updateTaskNode OCC direct-hydration guard (#2072) suite: one test's assertions/comment described the old unconditional-revert behavior as expected; updated to assert the optimistic edit is preserved. Filled in the it.todo() that PR left as an explicit placeholder for this fix, with a real regression test proving a queued write's value survives both the failure-path handling and the direct-hydration guard's own skip decision. Closes #2088 Co-Authored-By: Claude <[email protected]>
…ation The isolated-failure test's title and only comment claimed it verified "surfaces the generic write-failure notification" for a non-OCC failure, but its assertions only checked the test-only error-tracking array and the preserved optimistic value — it never asserted on conflictNotifications. updateTaskNode() actually has no code path that raises a user-facing write-failure notification for a non-OCC failure at all (a separate, pre-existing gap, out of scope here). Retitled and added a comment clarifying what the test actually verifies, so it doesn't overpromise coverage it doesn't have. Co-Authored-By: Claude <[email protected]>
Contributor
Author
|
APPROVE Independently re-verified:
Merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
updateTaskNode()'s catch handler unconditionally calledthis.nodesSet(nodeId, existingNode)on any write failure (OCC or not), whereexistingNodeis the snapshot captured before this specific call's own optimistic update. If a secondupdateTaskNode()call for the same node landed and applied its own optimistic update while the first was still executing, and the first then failed, this line overwrote the store with the first write's stale pre-edit snapshot — discarding the second write's still-queued optimistic value.updateNode()'s sibling catch handler doesn't have this problem: it callsrollbackUpdate(), which only rewinds bookkeeping (the pending-update list, the version counter) and re-notifies with whatever the store currently holds — it never callsnodesSet()and never touches node content.Fix
updateTaskNode()'s catch handler now notifies subscribers with whatever the store currently holds instead of force-reverting toexistingNode.updateTaskNode()doesn't track aNodeUpdate/pendingUpdatesentry the wayupdateNode()does, sorollbackUpdate()itself isn't directly reusable here — the fix mirrors its no-op-on-content behavior directly.Tests
updatetasknode-rollback-clobber-regression.test.ts: verified to fail against the pre-fix code.updateNode()'s design, instead of reverting it.shared-node-store-skip-while-editing.test.ts'supdateTaskNode OCC direct-hydration guard (#2072)suite:it.todo()that PR shared-node-store: apply skip-while-editing guard to updateTaskNode's OCC direct-hydration path #2089 left as an explicit placeholder for this exact fix, with a real regression test proving a queued write's value survives both the failure-path handling and the direct-hydration guard's own skip decision.Full suite run cold (cache cleared) — all files green except two flaky, unrelated pre-existing tests (
core-plugins.test.tsviewer-resolution timeout,model-store.test.tsfake-timer loop) that reproduce independently of this change and pass in isolation and on repeat full runs.Closes #2088
🤖 Generated with Claude Code