Skip to content

shared-node-store: fix OCC error-shape stripping causing a duplicate notification in updateNode() - #2091

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2080-occ-error-shape-guard
Aug 14, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2080-occ-error-shape-guard

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

Found during #2057's review (fixed in #2079, which fixed the identical bug for deleteNode()). updateNode()'s PersistenceCoordinator.persist() closure re-throws dbError instanceof Error ? dbError : new Error(String(dbError)) on any failure. Real command errors crossing the Tauri/gRPC boundary (VERSION_CONFLICT, SUBTREE_ACCESS_DENIED) are plain objects, not instanceof Error, so an OCC conflict got wrapped in a fresh generic Error before re-throwing — losing its .code/.conflictData shape entirely.

The outer handle.promise.catch((err) => { if (isVersionConflict(err)) return; ...generic write-failure notification... }) then checked isVersionConflict on this already-stripped err, which could never match. The guard silently failed, so every OCC conflict on updateNode() produced BOTH the specific version-mismatch notification the inner closure already raised AND a spurious duplicate generic write-failure notification from the outer catch.

Fix

Same pattern #2079 already applied to deleteNode(): a boolean (occConflictAlreadyNotified) captured inside the closure, set at the point the specific notification is raised, checked by the outer catch instead of re-deriving the classification from the already-stripped err.

setNode() — investigated, presumed bug does not reproduce

The issue presumed setNode()'s "equivalent OCC handling (same error/dbError pattern, same outer-catch guard shape)... has the identical bug — not independently reproduced with a test." I wrote a probe test before assuming that and confirmed empirically it does not: setNode()'s persist closure has no OCC-specific catch branch at all (no rollback-to-current_node hydration, no specific version-mismatch notification) — it treats every failure generically. With no earlier specific notification, there's nothing for the outer catch's generic write-failure fallback to duplicate; an OCC failure via setNode() already correctly surfaces exactly one notification today.

The outer catch's isVersionConflict(err) check there was therefore dead code (never matched, for the same error-stripping reason) rather than an active duplicate-notification bug — removed as misleading dead code (it implied OCC gets special treatment it doesn't) rather than "fixed" with an unnecessary captured flag that would never be set.

Testing

  • New occ-notification-dedup.test.ts: updateNode() raises exactly one version-mismatch notification on an OCC conflict (verified the test actually catches the bug — temporarily reverted the fix locally and confirmed it fails with 2 notifications, as the issue described). setNode() raises exactly one generic notification for an OCC conflict (regression-lock for the confirmed-correct existing behavior). Both methods' non-OCC failure paths covered too, confirming the fix didn't change that behavior.
  • bun run test:all — all 208 files / 4652 tests (4651 pass + 1 pre-existing it.todo) pass via the pre-push gate.
  • bun run quality:fix — clean (eslint, tsc --noEmit, cargo clippy --all-targets -D warnings; no Rust files touched by this PR — the diff-only-includes-frontend claim is enforced by the pre-push gate's own build step, which succeeded).

Closes #2080

…notification in updateNode()

updateNode()'s persist() closure re-throws `dbError instanceof Error ?
dbError : new Error(String(dbError))` on any failure. Real command
errors crossing the Tauri/gRPC boundary (VERSION_CONFLICT,
SUBTREE_ACCESS_DENIED) are plain objects, not instanceof Error, so an
OCC conflict got wrapped in a fresh generic Error before re-throwing —
losing its `.code`/`.conflictData` shape entirely.

The outer `handle.promise.catch((err) => { if (isVersionConflict(err))
return; ...generic write-failure notification... })` then checked
isVersionConflict on this already-stripped err, which could never
match. The guard silently failed, so every OCC conflict produced BOTH
the specific version-mismatch notification the inner closure already
raised AND a spurious duplicate generic write-failure notification
from the outer catch.

Fixed the same way #2079 fixed the identical bug for deleteNode(): a
boolean (occConflictAlreadyNotified) captured inside the closure, set
at the point the specific notification is raised, checked by the
outer catch instead of re-deriving the classification from the
already-stripped err.

Investigated setNode()'s presumed identical bug (per the issue, "not
independently reproduced with a test") and confirmed empirically it
does NOT reproduce: setNode()'s persist() closure has no OCC-specific
catch branch at all, so there is no earlier specific notification for
the outer catch's write-failure fallback to duplicate — an OCC failure
there already correctly surfaces exactly one (generic) notification.
The outer catch's isVersionConflict(err) check was dead code (never
matched, for the same error-stripping reason) rather than an active
duplicate-notification bug, so removed it as misleading dead code
instead of "fixing" it with an unnecessary captured flag.

Added occ-notification-dedup.test.ts covering both methods: updateNode()
raises exactly one version-mismatch notification on an OCC conflict
(not two); setNode() raises exactly one generic notification (not
zero, not two). Both files' non-OCC failure paths are covered too, as
regression checks that the fix didn't change that behavior.

Closes #2080

Co-Authored-By: Claude <[email protected]>
…low-up for updateTaskNode's silent-failure gap

Review of #2091 found no BLOCKER/functional bugs — the updateNode() fix,
the setNode() investigation, and scope discipline all independently
verified correct (including the reviewer's own scratch test confirming
setNode()'s seeding/gating behavior).

One MINOR fix applied: occ-notification-dedup.test.ts's comment on
updateNode()'s persist-mode gating described setNode()'s formula
(`source.type !== 'viewer' || isNewNode`) as if it applied to
updateNode() too. Corrected to describe updateNode()'s actual gate
(structural/property/nodeType/type-specific change -> immediate mode
regardless of source) and clarified why setNode()'s tests specifically
need a non-viewer source.

The review also surfaced a real, more serious gap: updateTaskNode()'s
outer handle.promise.catch() has no fallback write-failure notification
at all for a non-OCC failure (unlike updateNode()/deleteNode()/
setNode(), which all correctly surface one) — a task status/priority/
due-date edit that fails outside an OCC conflict silently reverts with
zero user-visible signal. Out of scope for this PR (about deduplicating
a notification, not adding a missing one) — filed as #2092.

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Adversarial review complete. No BLOCKER/functional bugs found — the reviewer independently traced the `occConflictAlreadyNotified` scoping/ordering (confirmed no race, flag always set before the throw), independently re-verified the `setNode()` investigation (checked every function it calls on the persisted path, confirmed no alternate notification route), confirmed the test's `mcp-server`-source case genuinely reaches `backendAdapter.updateNode` not `createNode`, and confirmed the 5th persist-catch site (`persistBatchedChanges`) is unaffected and correctly out of scope.

One MINOR fix applied: corrected a test comment that mis-described `updateNode()`'s persist-mode gating formula (it had described `setNode()`'s formula instead).

The review also surfaced a real, more serious gap unrelated to this PR: `updateTaskNode()`'s outer catch has no fallback notification at all for a non-OCC failure — silently reverts with zero user-visible signal. Filed as #2092.

Pushed in d099acb.

@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. Fix mirrors #2079's merged pattern for the confirmed updateNode() duplicate; setNode()'s presumed twin bug was empirically disproven before touching it (probe test + comment cleanup, not an unverified assumption). Adversarial review found no BLOCKER/functional issues; the one MINOR item addressed, one out-of-scope finding filed separately (#2092). Full suite + quality:fix clean via the pre-push gate on both pushes.

Merging.

@mstomar125
mstomar125 merged commit 92f72be into main Aug 14, 2026
@mstomar125
mstomar125 deleted the issue-2080-occ-error-shape-guard branch August 14, 2026 09:27
mstomar125 added a commit that referenced this pull request Aug 14, 2026
…n a non-OCC write failure (#2098)

updateTaskNode()'s outer handle.promise.catch((err) => {...}) only
checked err instanceof OperationCancelledError and returned early for
that case. Unlike updateNode()'s, deleteNode()'s, and setNode()'s
outer catches, it had no fallback conflictNotifications.add({
conflictType: 'write-failure', ... }) for the general case.

An OCC (version-conflict) failure was already handled correctly — the
inner closure's own occError branch raises its own version-mismatch
notification. But a non-OCC failure (network error, daemon offline,
validation error) was NOT handled anywhere: the inner catch logs,
tracks the error for tests, rolls back bookkeeping, and re-throws, but
nothing downstream ever added a notification for this case. Since
updateTaskNode() is called fire-and-forget (void-returning) from every
UI call site, a user changing a task's status/priority/due date during
a network blip saw zero toast, zero error, nothing — the UI just
reverted (or, post-#2088's fix, silently kept the optimistic value)
with no explanation.

Fixed the same way #2091 fixed the equivalent duplicate-notification
bug for updateNode(): a captured boolean (occConflictAlreadyNotified),
set at the point the specific version-mismatch notification is raised
inside the closure, checked by the outer catch instead of re-deriving
the classification from the already-shape-stripped err. The outer
catch now falls back to the same generic write-failure notification
updateNode()/deleteNode()/setNode() already raise.

Extended occ-notification-dedup.test.ts with an updateTaskNode()
describe block mirroring its existing updateNode()/setNode() coverage:
exactly one version-mismatch notification on an OCC conflict (not a
duplicate), and exactly one write-failure notification on a non-OCC
failure (verified to fail against the pre-fix code: 0 notifications,
matching the reported bug, before this fix; 1 after).

Also fixed a now-stale comment in updatetasknode-rollback-clobber-
regression.test.ts (#2088) that described this exact gap as
unaddressed.

Closes #2092

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

1 participant