Repository navigation
shared-node-store: apply skip-while-editing guard to OCC direct-hydration path - #2071
Conversation
updateNode()'s OCC-conflict catch handler has two hydration paths: a direct one that writes occError.conflictData.current_node straight into the store via nodesSet() when the daemon embeds it, and a fallback (resyncNodeFromServer()) when it doesn't. PR #2066 added the skip-while-editing guard (decideRemoteUpdate) to the fallback path only, leaving the direct path free to clobber a node's in-progress optimistic edit whenever the daemon's conflict response happened to include current_node. Route the direct-hydration branch through the same decideRemoteUpdate check resyncNodeFromServer already applies, with hasPending hardcoded to false for the same reason resyncNodeFromServer's direct call keeps it false: this fires from inside the failing write's own catch handler, before its executingOperations entry clears, so a real PersistenceCoordinator.hasPending() read would just see that same write's own not-yet-cleared bookkeeping. On a guard-skip, mark the node persisted (the conflict response still proves server-side existence) without touching content or version, mirroring resyncNodeFromServer's skip branch. The existing unconditional conflictNotifications.add() after the if/else already covers this call site's notification, so no separate notify is added on skip. Adds regression coverage to shared-node-store-skip-while-editing.test.ts covering: clobber prevented while focused, persisted bookkeeping still updated on skip, normal application for a non-focused/non-pending node (direct path, not the fallback resync), and exactly one conflict notification raised on skip. Closes #2068 Co-authored-by: Claude <[email protected]>
|
APPROVE Self-review + independent verification, plus an adversarial review sub-agent pass (no blocking findings). (GitHub blocks formal self-review approval of one's own PR, so recording this as a comment per repo convention.) Verified independently:
Adversarial review sub-agent additionally: cloned the branch, ran the new tests against both pre-fix and post-fix source to empirically confirm which are true regression tests vs. characterization tests, traced PersistenceCoordinator's executingOperations/finally lifecycle to confirm the Merging. |
… OCC direct-hydration path (#2089) * shared-node-store: apply skip-while-editing guard to updateTaskNode's OCC direct-hydration path updateTaskNode()'s OCC-conflict catch handler had the identical unguarded direct-hydration shape updateNode() had before #2071: when the daemon's version-conflict response embeds current_node, it wrote straight into the store via nodesSet() with no decideRemoteUpdate skip-while-editing check. A conflict response landing while the user is actively editing (focused, or a different write genuinely queued behind this one) could silently advance the node's version/status out from under that edit. Apply the same fix #2071 applied to updateNode(): route the direct- hydration branch through decideRemoteUpdate, using hadQueuedWrite (already captured before clearQueued() in this handler) for hasPending, for the same self-referential-race reason updateNode()'s branch uses it. Skip the nodesSet/version overwrite when the decision says not to apply, but still mark the node persisted. Added a task-node counterpart to the "OCC direct-hydration guard (#2068)" test block, covering: the daemon's conflicting snapshot does not apply while focused, persisted-marking still happens on a guard-skip, the non-focused/non-pending case still applies normally, and exactly one conflict notification is raised on a skip. Note: updateTaskNode()'s catch handler unconditionally reverts to the pre-edit existingNode snapshot on ANY failure (OCC or not) before this guard ever runs, unlike updateNode()'s no-op-on-content rollbackUpdate(). That means the guard here protects against the daemon's conflicting snapshot landing on the already-reverted state, not the user's specific optimistic edit value surviving — a real behavioral difference from updateNode(), and the root cause of a separate bug (a later queued write's result can be clobbered by an earlier write's failure) filed as its own follow-up rather than folded into this fix. Closes #2072 Co-Authored-By: Claude <[email protected]> * Address adversarial review: it.todo stub for the deferred queued-write case, file follow-up for a success-path observation Review of #2089 found no BLOCKER/IMPORTANT issues — the guard, hadQueuedWrite wiring, decideRemoteUpdate inputs, and the rollback-asymmetry explanation all traced correctly against the actual code and passing tests. Two MINOR items addressed: - Replaced the trailing comment about the deliberately-omitted "queued second write" test with an it.todo() referencing #2088, so it stays visible in verbose test output rather than only in a comment. - Filed #2090 for a distinct, unverified observation the reviewer raised: updateTaskNode()'s SUCCESS path does Object.assign() on whatever this.nodes.get(nodeId) currently holds, which could be a different concurrently-resolving write's object rather than this write's own — a different code path from #2088's failure-path rollback, flagged as needing a repro before anyone spends a fix cycle on it. Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Summary
updateNode()'s OCC-conflict catch handler has two hydration paths:occError.conflictData.current_nodewhen the daemon embeds it in the conflict response (this.nodesSet(nodeId, currentNode)).resyncNodeFromServer(), used when the daemon didn't embedcurrent_node.PR #2066 added the skip-while-editing guard (
decideRemoteUpdate) to the fallback path only. The direct path wrote straight into the store via the same guard-freenodesSet(), so an OCC conflict on a node the user is actively editing could still silently clobber the optimistic content whenever the daemon's response happened to embedcurrent_node.Fix
Route the direct-hydration branch through the identical
decideRemoteUpdatecheckresyncNodeFromServer()already applies, withhasPendinghardcoded tofalse— for the same reasonresyncNodeFromServer's own direct call keeps itfalse(see that method's comment): this fires from inside the failing write's own catch handler, before itsexecutingOperationsentry has cleared, so a realPersistenceCoordinator.hasPending()read here would just see that same write's own not-yet-cleared bookkeeping and read it as "an edit is pending" every time.On a guard-skip: mark the node persisted (the conflict response still proves server-side existence), but don't touch content or version — mirrors
resyncNodeFromServer's skip branch exactly. The existing unconditionalconflictNotifications.add()after the if/else already covers this call site's conflict notification, so no separate notify is added on skip (this call site, unlikeresyncNodeFromServer's queued-follow-up case, always has an external caller raising its own notification).Testing
Added 4 regression tests to
shared-node-store-skip-while-editing.test.tsunder a newOCC direct-hydration guard (#2068)block, mirroring the existingresyncNodeFromServer guardblock's structure:persistedNodeIdsstill updated on a guard-skipbackendAdapter.getNodeis never called)Full suite:
bun run test— 203 test files, 4610 tests passed, cold cache (fresh worktree, no prior vitest cache).bun run quality:fixclean (eslint, tsc, cargo fmt, cargo clippy --all-targets). Pre-push gate (test:all+cargo build --bin nodespaced+test:e2e+cargo test -p nodespace-app) passed in full.Scope note
Found the identical bug pattern in
updateTaskNode()'s OCC catch handler (same file, ~line 2390) — it has the same direct-hydration-without-guard shape. Out of scope for this issue (#2068 is explicitly scoped toupdateNode()); will file a separate follow-up issue.Closes #2068
🤖 Generated with Claude Code