You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PersistenceCoordinator leaves superseded write promises unsettled on two of three supersede paths #2050
SimplePersistenceCoordinator in packages/desktop-app/src/lib/services/shared-node-store.svelte.ts hands every persist() caller a promise, then drops that promise unsettled on two of the three paths that supersede a write.
1. cancelPending (:311-323) clears the timer and deletes the entry, but never settles pending.promise:
clearTimeout(pending.timeoutId);this.pendingOperations.delete(nodeId);// pending.promise settles never
2. The queued-operation overwrite in persist() (:145-151) replaces an already-queued operation via Map.set, discarding the previous entry — and with it that entry's resolve/reject:
A burst of keystrokes during an in-flight write leaves one orphaned promise per superseded edit.
Why this is inconsistent with the file's own rule
clearQueued (:325-347) is the third path, and its doc comment states the rule the other two break:
CRITICAL: Must settle the queued op's promise and drop its pendingOperations placeholder here. […] without this, discarding the queue entry mid-flight leaves that promise unsettled forever and hasPending(nodeId) stuck true.
clearQueued does it correctly — it calls queued.reject(new OperationCancelledError(…)). The other two sites do not.
Impact
Currently contained rather than severe: all four persist() call sites only attach handle.promise.catch(…) for logging (:1510, :1895, :2114, :2287), and none awaits completion, so nothing hangs today. What leaks is one never-settled promise (and its .catch handler) per superseded write — and, more importantly, a trap for the next caller who does await a persist() handle, since two of three supersede paths will never settle it.
Unlike the clearQueued case, hasPending does not get stuck: the replacement entry re-registers the node.
Suggested fix
Settle on supersede, matching clearQueued:
cancelPending: pending.reject(new OperationCancelledError('Superseded by a newer write')) before deleting.
persist()'s queue overwrite: read the existing entry first and reject it before set.
OperationCancelledError already exists (:527) and callers already tolerate it.
Acceptance criteria
Every persist() promise settles exactly once, on all supersede paths
Superseded writes reject with OperationCancelledError, not a generic error
Tests: debounced write superseded before firing; two writes queued behind one in-flight write
Fixed both supersede paths (cancelPending + the queued-op Map.set overwrite in persist()) to reject with OperationCancelledError before dropping/replacing the entry, mirroring clearQueued's existing pattern. Also fixed a 5th persist() call site (persistBatchedChanges) that never captured its handle, which the cancelPending fix would otherwise have turned into an unhandled promise rejection.
Added persistence-coordinator-supersede-settlement.test.ts covering both acceptance-criteria scenarios directly against SimplePersistenceCoordinator (exported for this purpose): a debounced write superseded before it fires, and two writes queued behind one in-flight write.
Verification: bun run test 202/4576 passed (baseline was 201/4574), bun run test:all all green (coverage+scripts+skill+full Rust workspace), quality:fix clean, pre-push gate green.
Activity
mstomar125 commentedon Aug 13, 2026
Baseline (frontend): 201 test files passed, 4574 tests passed. Duration 58.83s. Starting implementation.
mstomar125 commentedon Aug 13, 2026
PR opened: #2056
Fixed both supersede paths (cancelPending + the queued-op Map.set overwrite in persist()) to reject with OperationCancelledError before dropping/replacing the entry, mirroring clearQueued's existing pattern. Also fixed a 5th persist() call site (persistBatchedChanges) that never captured its handle, which the cancelPending fix would otherwise have turned into an unhandled promise rejection.
Added persistence-coordinator-supersede-settlement.test.ts covering both acceptance-criteria scenarios directly against SimplePersistenceCoordinator (exported for this purpose): a debounced write superseded before it fires, and two writes queued behind one in-flight write.
Verification: bun run test 202/4576 passed (baseline was 201/4574), bun run test:all all green (coverage+scripts+skill+full Rust workspace), quality:fix clean, pre-push gate green.
shared-node-store: distinguish dependency-wait cancellation propagati…