Repository navigation
Description
Overview
resyncNodeFromServer's direct (non-queued) call path hardcodes hasPending: false instead of consulting PersistenceCoordinator, which lets it silently overwrite a second write that is genuinely still queued for the same node — discarding that write's optimistic value even though it may go on to persist successfully moments later.
This is a follow-up from the #2066 (#1985) review — a distinct finding from #2068 (a sibling gap in the other branch of the same OCC-conflict handling).
Problem Statement
resyncNodeFromServer(nodeId, _isQueuedFollowUp) in shared-node-store.svelte.ts is invoked two ways: directly, from inside a failing write's own OCC-conflict catch handler, and as a queued follow-up when a second resync request arrives while one is already in flight. Only the queued-follow-up call reads PersistenceCoordinator.getInstance().hasPending(nodeId) for real; the direct call hardcodes hasPending: false.
Concrete failure sequence:
- Write A is executing for node X (any
PersistenceCoordinator.persist()caller — a Kanban drag, a debounced content edit, etc.). - Write B, for the same node, is submitted while A is executing.
PersistenceCoordinator.persist()'sisExecutingbranch collapses B into its single-slotqueuedOperationsmap — B's optimistic value is already applied to the local store at this point. - Write A fails with an OCC conflict whose response does not embed
current_node.updateNode()'s OCC-conflict handling falls back toresyncNodeFromServer(nodeId)— the direct call, not the queued-follow-up one. - If node X is not focused,
decideRemoteUpdateis evaluated withisFocused: false, hasPending: false(hardcoded) —decision.applyistrue, and the resync overwrites the store with the fetched server row. - That fetched row reflects state from before B was ever attempted (the server has no knowledge of B — it hasn't been sent yet). B's still-pending optimistic value is silently discarded.
This is the same class of "two rapid writes to the same card must not stomp each other" bug that chainOrigin was added to #2066's Kanban moveCard to prevent, but the OCC-conflict path routes through resyncNodeFromServer directly, bypassing chainOrigin/onPersistError entirely, and has no equivalent protection or test coverage.
This was flagged during #2066's review, with the reviewer's own recommendation to fix it before merge, but #2066 merged before it was addressed — noted there as real but broader application-wide debt worth its own follow-up rather than blocking that PR further.
Why a direct swap to real hasPending is not safe
The direct call was hardcoded to false in the first place for a specific, empirically-confirmed reason (from #2066's review history): hasPending() ORs pendingOperations/executingOperations/queuedOperations together, and at the moment the failing write's own catch handler runs, that same write's executingOperations entry for the node was believed to still be present (its own finally block "hasn't cleared it yet") — so a naive hasPending check there was found, empirically, to read the failing write's own bookkeeping as "something is pending" almost every time, defeating the resync for its single most common case (an isolated failure, nothing else in flight). This was hit directly during #2066's review: wiring in a real hasPending check broke 3 existing tests, including the pre-existing OCC-hydration regression suite.
Whoever picks this up should verify the actual call/microtask ordering with a real regression test rather than reasoning about it in the abstract — do not assume either this issue's failure scenario or the round-1 empirical finding without re-confirming both against current code. In particular, confirm empirically:
- Whether
runOperation'sfinallyblock (which clearsexecutingOperationsand promotes a queued write intopendingOperations) has actually completed by the time the failing write's own catch-triggered call intoresyncNodeFromServerruns, given howupdateNode()awaits the write's promise. If it has,hasPending()at that point would already reflect a genuinely-different queued write B, not the failing write's own residue — which would change the fix needed here. - The exact scenario in this issue (write B genuinely queued behind failing write A) against a written-first, verified-to-fail regression test.
Proposed Solution
One of, pending the verification above:
- Add a
PersistenceCoordinatorpredicate that answers "is there a queued/pending write for this node other than the one currently failing" — e.g. by passing the failing operation's own identity/token so it can be excluded from the check. - Or, if verification shows
finallygenuinely completes before the direct call's catch handler runs, simply route the direct call through the same realhasPending()check the queued-follow-up path already uses, and re-verify the previously-broken tests to confirm whether the round-1 finding still applies to the current code shape. - Or a narrower check against
queuedOperationsspecifically (where a genuinely-different write B lives while A is still executing), rather thanhasPending()'s coarser OR of three sets.
Acceptance Criteria
- A regression test reproduces the failure sequence above (write A executing, write B queued behind it for the same node, A fails with an OCC conflict with no embedded
current_node, node not focused) and is verified to fail against the current code (B's optimistic value gets clobbered) before any fix is applied. - The same test passes after the fix, with B's optimistic value preserved.
- The existing OCC-hydration regression suite (and the 3 tests referenced as having broken in Kanban: cap column rendering and add browser drag-and-drop tests #2066's round 1 when
hasPendingwas first tried) still pass — confirming the fix does not reintroduce the self-referential false-positive. -
bun run test:allhas no new failures. -
bun run quality:fixis clean.
Technical Specifications
Reference Files
packages/desktop-app/src/lib/services/shared-node-store.svelte.ts:resyncNodeFromServer(direct-callhasPendinghardcode) andPersistenceCoordinator(hasPending(),queuedOperations,executingOperations,persist()'sisExecutingbranch) — all in this one file.packages/desktop-app/src/lib/services/remote-update-policy.ts:decideRemoteUpdate— consumes thehasPending/isFocusedinputs this issue is about.
Architecture Context
Reviewed against decisions/026-write-flow-conflict-resolution.md (ADR-026), which documents the OCC version-conflict pipeline and the resyncNodeFromServer fallback this issue concerns — this is an implementation gap within that documented design, not a reversal of it. No companion nodespace-docs change is expected; the fix operates entirely within ADR-026's existing decision.
Related Issues
- Kanban: cap column rendering and add browser drag-and-drop tests #2066 (source PR)
- Kanban view: bound large boards (pagination/virtualization) + browser DnD tests #1985 (source issue)
- shared-node-store: OCC direct-hydration branch needs the same skip-while-editing guard as resyncNodeFromServer #2068 (sibling follow-up — the other branch of the same OCC-conflict handling)
Activity
mstomar125 commentedon Aug 14, 2026
Fixed in #2076. Empirically confirmed (before designing the fix) that the naive "just swap in a live PersistenceCoordinator.hasPending() read" approach flagged as unsafe in this issue really is unsafe: at resyncNodeFromServer's decision point, executingOperations still has the failing write's own entry (its runOperation hasn't reached finally yet), so a live hasPending() read is true almost every time regardless of whether anything else is genuinely queued — reproduced the exact false-positive from #2066's round-1 finding (an isolated failure with nothing else queued would wrongly skip the resync).
Also found, empirically, that the issue's own literal
queuedOperations-based framing needed one more layer: both OCC handlers callPersistenceCoordinator.clearQueued(nodeId)unconditionally (to stop the failing write's own stale-version retry) immediately before either hydration branch runs — which removes a genuinely-queued second write fromqueuedOperationsbefore resyncNodeFromServer's decision point is ever reached. So the fix capturesPersistenceCoordinator.isQueued(nodeId)(a new, self-reference-free predicate) BEFOREclearQueued()runs, and threads that captured value intoresyncNodeFromServerasdirectCallHadQueuedWrite.Regression test reproduces the concrete race (write A executing, write B collapsed into queuedOperations, A fails OCC with no current_node, node unfocused) and is verified to fail against the pre-fix code before the fix, and pass after. A second test locks in the #2066 round-1 finding (isolated failure still resyncs normally). Both direct call sites of resyncNodeFromServer (updateNode and updateTaskNode) are fixed, since they share the identical bug via the same shared function.
Wire hadQueuedWrite into the OCC direct-hydration branch's hasPending…