Repository navigation
shared-node-store: distinguish dependency-wait cancellation propagation from direct cancellation - #2079
Conversation
SimplePersistenceCoordinator's dependency-wait loop (runOperation, via persist()'s dependencies option -- fed by persistenceDependencies and afterSiblingId) let a dependency's promise rejection reach a dependent write as a raw error, indistinguishable from the dependent being cancelled directly. Every one of the 5 persist()-caller .catch sites in this file treats `err instanceof OperationCancelledError` as "I was personally cancelled -- a newer write for the SAME node supersedes me, ignore this." That is true when cancelPending()/clearQueued()/the queued-operation overwrite rejects an operation's own promise directly. It is NOT true when the rejection belongs to a DIFFERENT node this operation depended on: the dependent's own op() (its actual backend RPC) never even ran, and nothing else is going to retry it -- so a propagated OperationCancelledError from a cancelled dependency was silently swallowed as "expected," discarding the dependent write with no trace and nothing surfaced to the user. This was latent before #2050/PR#2056 fixed cancelPending() to actually reject a superseded write's promise (previously left unsettled forever, so nothing propagated through the dependency-wait loop at all) -- fixing that exposed this as a live bug. Add DependencyFailedError, thrown by the dependency-wait loop (for both node-id and lambda dependencies) instead of letting the dependency's raw rejection propagate. It wraps the original cause and is deliberately NOT a subclass of OperationCancelledError, so every existing `.catch(err => err instanceof OperationCancelledError ...)` site correctly falls through to its "not a cancellation, surface it" branch instead of silently swallowing it. Of the 5 catch sites, updateNode(), setNode(), and persistBatchedChanges() already surface non-cancellation failures via a write-failure conflict notification and needed no changes -- they automatically benefit from the new type distinction. deleteNode()'s catch site previously swallowed EVERY non-cancellation error silently (the comment claiming "real errors are logged by PersistenceCoordinator" was not actually true -- nothing surfaced to the user either way); fixed to match the established write-failure notification pattern, since deleteNode() also declares real dependencies (nodes that must persist first to avoid a FOREIGN KEY violation) and was the call site most directly exposed to this bug. updateTaskNode()'s catch site is unchanged: it never declares dependencies, so it isn't exposed to this specific propagation bug -- its separate, pre-existing gap (silently swallowing genuine non-cancellation task-update failures) is a different bug class, left out of scope here. Audited resetInstance() for the same unsettled-promise-plus-live-timer defect class cancelPending()/the queue-overwrite had before #2050: no production call path exists (every call site across the codebase is test setup/teardown), so left as documented rather than fixed, per the issue's own conditional acceptance criterion. Regression tests (dependency-wait-cancellation-propagation.test.ts): - Coordinator-level: a cancelled dependency's rejection reaches the dependent as DependencyFailedError, not a raw OperationCancelledError; the dependent's own op() never runs; DependencyFailedError carries the dependency id and original cause; a genuine (non-cancellation) dependency failure, both already-settled and still-in-flight when the dependent starts waiting, is also wrapped. - End-to-end via SharedNodeStore.updateNode()'s persistenceDependencies: reproduces the concrete sequence (node A's debounced write cancelled by a superseding edit before it fires, node B depends on A) and asserts B's backend RPC never fires AND a write-failure notification surfaces for B -- verified this fails against the pre-fix code (no notification, B silently vanishes) and passes after the fix. A second test locks in that an ordinary same-node cancellation (no dependency involved) still raises no spurious notification. Full existing OCC/resync/serial-writer/delete test suites re-verified green. Closes #2057 Co-authored-by: Claude <[email protected]>
…surfacing Adversarial review of this PR found a real regression in the deleteNode() catch-site fix: a subtree-access-denied refusal already raises its own specific notification (showSubtreeAccessDenied) inside the persist closure's own catch, before re-throwing to mark the coordinator operation failed. The new outer handle.promise.catch()'s generic write-failure surfacing had no guard against this, so a refusal now produced BOTH notifications for the same event. The straightforward fix (checking isSubtreeAccessDenied(err) on the outer catch's error, mirroring the isVersionConflict guard at other call sites) does not work: the closure re-throws `error` (`dbError instanceof Error ? dbError : new Error(String(dbError))`), and the real command errors crossing the Tauri/gRPC boundary are plain objects, not Error instances -- so `error` is always a freshly-wrapped generic Error by the time it reaches the outer catch, having already lost the `.code`/`.conflictData` shape isSubtreeAccessDenied checks for. Confirmed this empirically: the naive isSubtreeAccessDenied(err) guard left the regression test failing identically to no guard at all. Fixed instead with a boolean captured in deleteNode()'s enclosing scope (subtreeAccessDeniedAlreadyNotified), set from inside the closure at the same point the specific notification is raised, and read directly by the outer catch -- avoiding the error-shape-stripping problem entirely. While investigating this, confirmed (via a throwaway reproduction, not included) that the SAME error-shape-stripping bug already exists, independently of this PR, at updateNode()'s and setNode()'s outer catch sites: an OCC (version-conflict) failure's outer isVersionConflict(err) guard is equally ineffective there, producing a spurious duplicate write-failure notification alongside the correct version-mismatch one. That is a distinct, pre-existing bug unrelated to dependency-wait cancellation propagation -- filed separately as a follow-up rather than fixed here. Extends subtree-access-denied-restore.test.ts: the refusal test now asserts zero write-failure notifications alongside the existing subtree-access-denied assertions (verified failing without the fix, passing with it); the non-refusal test now asserts exactly one write-failure notification, locking in the deleteNode() fix's intended behavior for a genuine deletion failure. Co-authored-by: Claude <[email protected]>
|
Addressed a real finding from adversarial review, plus discovered and filed a related pre-existing bug. Review finding: my `deleteNode()` fix (surfacing a generic write-failure notification for non-cancellation errors) had no guard against a subtree-access-denied refusal, which already raises its own specific notification inside the persist closure. Result: a refusal now produced BOTH notifications for the same event. Root cause, found while fixing it: the straightforward fix (`isSubtreeAccessDenied(err)` on the outer catch, mirroring the existing `isVersionConflict` pattern) doesn't actually work — confirmed empirically. The closure re-throws `error = dbError instanceof Error ? dbError : new Error(String(dbError))`, and real command errors crossing the Tauri/gRPC boundary are plain objects, not `Error` instances — so `error` is always a freshly-wrapped generic `Error` by the time it reaches the outer catch, having already lost the `.code`/`.conflictData` shape `isSubtreeAccessDenied` checks for. Fixed (commit `18ac7843`) with a boolean captured in `deleteNode()`'s enclosing scope (`subtreeAccessDeniedAlreadyNotified`), set inside the closure at the same point the specific notification fires, read directly by the outer catch — sidestepping the error-shape-stripping problem entirely. Verified empirically: reverted just the guard, confirmed the extended regression test fails identically to having no guard; restored it, confirmed it passes. Also discovered: the same error-shape-stripping bug already exists, independently of this PR, at `updateNode()`'s and `setNode()`'s outer catch sites — an OCC (version-conflict) failure's `isVersionConflict(err)` guard is equally ineffective there, producing a spurious duplicate write-failure notification alongside the correct version-mismatch one. Reproduced with a throwaway test (not included). This is a distinct, pre-existing bug unrelated to dependency-wait cancellation propagation — filed separately as #2080 rather than fixed here, to keep this PR scoped to #2057. Extended `subtree-access-denied-restore.test.ts`: the refusal test now asserts zero write-failure notifications; the non-refusal test now asserts exactly one, locking in the deleteNode() fix's intended behavior. Full suite re-verified green (205 files, 4619 tests), quality:fix clean, pre-push gate passed in full on the follow-up push (one retry needed due to an unrelated timestamp-precision flake in text-node.test.ts, resource-contention under load, unrelated to this diff). |
|
APPROVE Independent final verification (GitHub blocks formal self-review approval of one's own PR, recording this as a comment):
Merging. |
…notification in updateNode() (#2091) * shared-node-store: fix OCC error-shape stripping causing a duplicate 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]> * Address adversarial review: fix a misleading test comment, file a follow-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]> --------- Co-authored-by: Claude <[email protected]>
Summary
SimplePersistenceCoordinator's dependency-wait loop (runOperation, viapersist()'sdependenciesoption — fed bypersistenceDependenciesandafterSiblingId) let a dependency's promise rejection reach a dependent write as a raw error, indistinguishable from the dependent being cancelled directly.Every one of the 5
persist()-caller.catchsites in this file treatserr instanceof OperationCancelledErroras "I was personally cancelled — a newer write for the SAME node supersedes me, ignore this." That's true whencancelPending()/clearQueued()/the queued-operation overwrite rejects an operation's own promise directly. It is not true when the rejection belongs to a DIFFERENT node this operation depended on: the dependent's ownop()(its actual backend RPC) never even ran, and nothing else is going to retry it — so a propagatedOperationCancelledErrorfrom a cancelled dependency was silently swallowed as "expected," discarding the dependent write with no trace and nothing surfaced to the user.This was latent before #2050/#2056 fixed
cancelPending()to actually reject a superseded write's promise (previously left unsettled forever, so nothing propagated through the dependency-wait loop at all) — fixing that exposed this as a live bug.Fix
DependencyFailedError, thrown by the dependency-wait loop (for both node-id and lambda dependencies) instead of letting the dependency's raw rejection propagate. Wraps the original cause; deliberately not a subclass ofOperationCancelledError, so every existing.catch(err => err instanceof OperationCancelledError ...)site correctly falls through to its "not a cancellation, surface it" branch.updateNode(),setNode(), andpersistBatchedChanges()already surface non-cancellation failures via a write-failure notification and needed no changes — they automatically benefit from the new type distinction.deleteNode()'s catch site previously swallowed every non-cancellation error silently (the comment claiming "real errors are logged by PersistenceCoordinator" wasn't actually true) — fixed to match the established write-failure notification pattern, sincedeleteNode()also declares real dependencies and was the call site most directly exposed to this bug.updateTaskNode()'s catch site is unchanged — it never declares dependencies, so it isn't exposed to this specific propagation bug; its separate pre-existing gap (silently swallowing genuine non-cancellation failures) is a different bug class, left out of scope.resetInstance()for the same unsettled-promise-plus-live-timer defect classcancelPending()/the queue-overwrite had before PersistenceCoordinator leaves superseded write promises unsettled on two of three supersede paths #2050: no production call path exists (every call site across the codebase is test setup/teardown) — documented rather than fixed, per the issue's own conditional acceptance criterion.Testing
New
dependency-wait-cancellation-propagation.test.ts:SimplePersistenceCoordinatortests, mirroringpersistence-coordinator-supersede-settlement.test.ts's style): a cancelled dependency's rejection reaches the dependent asDependencyFailedError, not a rawOperationCancelledError; the dependent's ownop()never runs;DependencyFailedErrorcarries the dependency id and original cause; a genuine (non-cancellation) dependency failure — both already-settled and still-in-flight when the dependent starts waiting — is also wrapped.SharedNodeStore.updateNode()'spersistenceDependencies: reproduces the concrete sequence from the issue (node A's debounced write cancelled by a superseding edit before it fires, node B depends on A) and asserts B's backend RPC never fires AND a write-failure notification surfaces for B. Verified this fails against the pre-fix code (temporarily stashed the source fix — B's write silently vanishes, no notification) and passes after the fix. A second test locks in that an ordinary same-node cancellation (no dependency involved) still raises no spurious notification.Ran the broader regression suite most likely to be sensitive to this change (416 tests across
shared-node-store-extended,shared-node-store-coverage,reactive-node-service,subtree-access-denied-restore,header-inheritance,shared-node-store,persistence-coordinator-supersede-settlement,persistence-serial-writer-regression,resync-direct-call-queued-write-regression,shared-node-store-skip-while-editing,ai-chat-occ-conflict-regression) — all green, includingsubtree-access-denied-restore.test.ts's delete-failure coverage (confirming thedeleteNodecatch-site fix doesn't disturb the subtree-access-denied handling, which happens inside the persist closure's own try/catch before re-throwing).Full suite:
bun run test— 205 files, 4619 tests passed.bun run quality:fixclean. Pre-push gate (test:all+cargo build --bin nodespaced+test:e2e+cargo test -p nodespace-app) passed in full.Scope note
Per the issue's own escape hatch ("if #2057 turns out to need a genuinely large redesign... it's fine to land a real, tested, narrower fix for the concrete failure sequence... and file a tighter follow-up for anything larger"): the acceptance criteria's three related findings (dependency-wait propagation,
resetInstance(), and the "duplication, lower priority" refactor note) are addressed as scoped — the first fixed, the second audited with no production path found, and the third (a shared helper de-duplicating the "settle before drop" and cancellation-.catchpatterns) is explicitly flagged in the issue itself as "disproportionate scope for a targeted bugfix, reasonable for a follow-up refactor" and left as such.Closes #2057
🤖 Generated with Claude Code