Repository navigation
Description
Found during
Implementing #2072 (updateTaskNode's OCC direct-hydration skip-while-editing guard). Adding a test mirroring #2069's "does not discard a genuinely queued second write" coverage (which locks in updateNode()'s equivalent guarantee) for updateTaskNode() failed, and the failure is unrelated to the direct-hydration branch #2072 fixed.
The bug
updateTaskNode()'s catch handler (packages/desktop-app/src/lib/services/shared-node-store.svelte.ts, in the PersistenceCoordinator.getInstance().persist(...) closure) does this on any write failure, OCC or not:
} catch (dbError) {
...
// Rollback the optimistic update
this.nodesSet(nodeId, existingNode);
this.notifySubscribers(nodeId, existingNode, source);
// If this is an OCC error, hydrate from authoritative current_node and notify
if (occError) {
...existingNode is the node snapshot captured at the start of this specific updateTaskNode() call, before its own optimistic write. Unconditionally writing it back into the store on failure means: if a second updateTaskNode() call (write B) landed and applied its own optimistic update while write A was still in flight, and write A then fails, this line overwrites the store with write A's own stale pre-edit snapshot — discarding write B's optimistic value (and, if B's real persist attempt resolves before A's catch runs, potentially discarding B's confirmed server state too).
updateNode()'s sibling catch handler avoids this entirely: it calls this.rollbackUpdate(nodeId, update), which only does bookkeeping (removes the failed update from pendingUpdates, rolls back the versions map entry, notifies subscribers with whatever is currently in the store) — it never calls nodesSet() and never touches node content. That is precisely why updateNode()'s OCC-related regression tests (#2069, does not discard a genuinely queued second write...) pass: there is no unconditional content rollback for a later write to race against.
Repro (removed from the #2072 PR, see that PR's test file history for the original draft)
- Seed a persisted task node.
- Write A:
updateTaskNode(id, { status: 'in-progress' }, ...)— optimistic apply, persist starts executing (mode:'immediate'), mockedbackendAdapter.updateTaskNodedelayed then rejects with a version-conflict error. - Write B:
updateTaskNode(id, { status: 'done' }, ...)submitted while A is still executing — collapses intoqueuedOperations, applies its own optimistic value (status: 'done') immediately. - Wait for both to settle.
- Expected: the node ends up reflecting write B (queued write must not be silently discarded — same guarantee
updateNode()already has). Observed: the node reverts to'todo'(write A's own pre-editexistingNodesnapshot), discarding write B's outcome.
Suggested fix
Make updateTaskNode()'s failure-rollback mirror updateNode()'s: stop calling this.nodesSet(nodeId, existingNode) unconditionally in the catch handler. Either route it through rollbackUpdate() (if compatible with updateTaskNode()'s update-tracking shape) or make it a no-op on content the same way, notifying subscribers with whatever the store currently holds rather than force-reverting to this call's own captured pre-edit snapshot. Add a regression test mirroring updateNode()'s #2069 coverage once fixed.
Scope note
Out of scope for #2072, which is specifically about the OCC direct-hydration branch (if (currentNode) { this.nodesSet(nodeId, currentNode); ... }) gaining the same decideRemoteUpdate skip-while-editing guard updateNode()'s equivalent branch has (#2071). This finding is about the unconditional rollback line that runs before that branch is even reached, on every failure (OCC or not) — a different code path, same store method.
Activity
Address adversarial review: it.todo stub for the deferred queued-writ…
shared-node-store: apply skip-while-editing guard to updateTaskNode's…
mstomar125 commentedon Aug 14, 2026
Fixed in #2095.
updateTaskNode()'s catch handler no longer unconditionally doesthis.nodesSet(nodeId, existingNode)on failure — it now notifies subscribers with whatever the store currently holds instead, mirroringupdateNode()'srollbackUpdate()(which never touches node content on failure).Added a regression test (verified to fail against the pre-fix code) proving a genuinely queued second write's still-in-flight optimistic value survives the first write's failure. Also fixed a pre-existing test in
shared-node-store-skip-while-editing.test.tswhose assertions/comment had documented the old unconditional-revert behavior as expected, and filled in theit.todo()PR #2089 left as an explicit placeholder for this fix.shared-node-store: fix updateTaskNode()'s unconditional failure-rollb…
shared-node-store: fix updateTaskNode() surfacing zero notification o…
Address review: count quoted-title refs, list matching lines on failure
Address review: count quoted-title refs, list matching lines on failure
Count bare #NNNN issue references in the code-reference check (closes #…