Skip to content

shared-node-store: apply skip-while-editing guard to OCC direct-hydration path - #2071

Merged
mstomar125 merged 1 commit into
mainfrom
issue-2068-occ-direct-hydration-guard
Aug 14, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-2068-occ-direct-hydration-guard

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

updateNode()'s OCC-conflict catch handler has two hydration paths:

  1. Direct: hydrate straight from occError.conflictData.current_node when the daemon embeds it in the conflict response (this.nodesSet(nodeId, currentNode)).
  2. Fallback: resyncNodeFromServer(), used when the daemon didn't embed current_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-free nodesSet(), 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 embed current_node.

Fix

Route the direct-hydration branch through the identical decideRemoteUpdate check resyncNodeFromServer() already applies, with hasPending hardcoded to false — for the same reason resyncNodeFromServer's own direct call keeps it false (see that method's comment): this fires from inside the failing write's own catch handler, before its executingOperations entry has cleared, so a real PersistenceCoordinator.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 unconditional conflictNotifications.add() after the if/else already covers this call site's conflict notification, so no separate notify is added on skip (this call site, unlike resyncNodeFromServer'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.ts under a new OCC direct-hydration guard (#2068) block, mirroring the existing resyncNodeFromServer guard block's structure:

  • Clobber prevented while the node is focused (content + version untouched)
  • persistedNodeIds still updated on a guard-skip
  • Normal application for a non-focused, non-pending node — confirms the direct path is exercised (not the fallback resync: asserts backendAdapter.getNode is never called)
  • Exactly one conflict notification raised on a guard-skip (no duplicate)

Full suite: bun run test — 203 test files, 4610 tests passed, cold cache (fresh worktree, no prior vitest cache). bun run quality:fix clean (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 to updateNode()); will file a separate follow-up issue.

Closes #2068

🤖 Generated with Claude Code

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

Copy link
Copy Markdown
Contributor Author

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:

  • Diff is scoped to exactly the two intended files (shared-node-store.svelte.ts + its skip-while-editing test file); confirmed no unrelated changes (an unrelated pre-existing cargo-fmt drift in nodes.rs was caught and reverted before commit).
  • Full frontend suite: bun run test — 203 test files, 4610 tests passed, cold cache (fresh worktree).
  • bun run quality:fix clean: eslint 0 errors/warnings, tsc --noEmit clean, cargo fmt + cargo clippy --all-targets -D warnings clean.
  • Pre-push gate passed in full: test:all, cargo build --bin nodespaced, test:e2e, cargo test -p nodespace-app (incl. Tauri-seam integration suite).

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 hasPending: false hardcode is genuinely justified (not just asserted-by-comment), and confirmed the apply-branch is byte-for-byte equivalent to the old unconditional code. No blocking issues found. One nitpick (PR description slightly overstates "regression tests" — 3 of 4 are characterization tests for the new skip branch, still valid coverage) and one inherited-limitation discussion point (not introduced by this PR, matches the precedent already shipped in resyncNodeFromServer's direct call) — neither blocking.

Merging.

@mstomar125
mstomar125 merged commit 99030cd into main Aug 14, 2026
@mstomar125
mstomar125 deleted the issue-2068-occ-direct-hydration-guard branch August 14, 2026 05:59
mstomar125 added a commit that referenced this pull request Aug 14, 2026
… 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]>
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: OCC direct-hydration branch needs the same skip-while-editing guard as resyncNodeFromServer

1 participant