Skip to content

shared-node-store: apply skip-while-editing guard to updateTaskNode's OCC direct-hydration path - #2089

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2072-updatetasknode-occ-guard
Aug 14, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2072-updatetasknode-occ-guard

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

Follow-up from #2068 (fixed in #2071). 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 a task property (or a different write genuinely queued behind this one) could silently advance the node's version/status out from under that edit.

Fix

Mirrors #2071's structure exactly: the direct-hydration branch now routes through decideRemoteUpdate, using hadQueuedWrite (already captured in this handler before clearQueued(), for the identical self-referential-race reason updateNode()'s branch uses it) for hasPending. When the decision says not to apply, the nodesSet/version overwrite is skipped but the node is still marked persisted — same as the apply branch would.

A behavioral nuance worth flagging (not fixed here, filed as #2088)

updateTaskNode()'s catch handler unconditionally does this.nodesSet(nodeId, existingNode) on any failure (OCC or not) before this guard is ever reached — unlike updateNode(), whose rollbackUpdate() never touches node content (bookkeeping only). This meant my first draft of the regression tests, mirroring #2068's exact assertions ("the optimistic edit survives"), failed — not because the guard is wrong, but because updateTaskNode()'s own unconditional pre-guard rollback already discards the optimistic edit regardless of what this fix does. What the guard here actually protects is the daemon's conflicting snapshot landing on top of that already-reverted state while the node is being edited — the version/status must not silently jump to the daemon's conflicting values mid-edit.

While chasing this down I also found that the same unconditional rollback line can clobber a different, later, genuinely queued write's result (the updateNode() sibling has an existing regression test, #2069, locking in that it can't — updateTaskNode() has no equivalent protection, and it's a separate code path from the one this issue asked me to fix). Filed as #2088 rather than folding a second, structurally different fix into this PR.

Testing

  • New updateTaskNode OCC direct-hydration guard (#2072) block in shared-node-store-skip-while-editing.test.ts, task-node counterpart to the existing OCC direct-hydration guard (#2068) block: daemon's conflicting snapshot doesn't apply while focused, node still marked persisted on a guard-skip, non-focused/non-pending case still applies normally (regression check), exactly one conflict notification on a skip.
  • bun run test:all — all 207 files / 4647 tests pass via the pre-push gate (no flakiness this run — the previously-observed model-store.test.ts/core-plugins.test.ts cross-file leak issues, unrelated to this change, didn't reproduce this pass).
  • bun run quality:fix — clean (eslint, tsc --noEmit, cargo clippy --all-targets -D warnings).

Closes #2072

… 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]>
…e 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]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Adversarial review complete. No BLOCKER/IMPORTANT findings — the reviewer independently traced the guard, the `hadQueuedWrite` wiring, the `decideRemoteUpdate` inputs, and the rollback-asymmetry explanation against the actual code and confirmed they all check out (including hand-tracing the focused-OCC path to confirm the test assertions reflect real behavior, not a reverse-engineered test).

Two MINOR items addressed:

Pushed in 53fc968.

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (self-review — GitHub blocks a native self-approval on your own PR)

Independent re-verification: diff touches exactly the 2 intended files (shared-node-store.svelte.ts, shared-node-store-skip-while-editing.test.ts). Fix mirrors #2071's current (post-evolution) pattern, using hadQueuedWrite rather than the older hardcoded-false version. Adversarial review found no BLOCKER/IMPORTANT issues; both MINOR items addressed. Full suite + quality:fix clean via the pre-push gate on both pushes.

Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shared-node-store: updateTaskNode()'s OCC direct-hydration path also needs the skip-while-editing guard

1 participant