Skip to content

Fix PersistenceCoordinator race: hasPending gap allows WatchNodes echo to clobber optimistic state - #1315

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1314-fix-persistence-coordinator-race
Jun 4, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1314-fix-persistence-coordinator-race

Conversation

@malibio

@malibio malibio commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Closes #1314

Michael Libio and others added 2 commits June 3, 2026 09:34
…tate (closes #1314)

When a queued op fires via setTimeout after the executing op completes,
there was a brief window where hasPending() returned false. WatchNodes
setNode arriving in that window bypassed the skip-while-editing guard
and overwrote the just-written optimistic value (e.g. provider='native').

Fix: re-register the queued op in pendingOperations as a placeholder
before clearing executingOperations, so hasPending() stays true
throughout the transition.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… $state

Under vite-plugin-svelte v6 + Svelte 5.56, class getters in .svelte.ts
files are compiled via compileModule which routes through the Svelte
runtime. A compound `&&` expression returning a plain boolean in a
getter with a reactive _creationSource was being mis-evaluated — the
compiled output ignored the right-hand false operand and returned a
reactive/truthy value instead.

Two changes:
1. Cache `plugin.pattern.canRevert` as a plain boolean field
   `_pluginCanRevert` at construction/mutation time, avoiding deep
   reactive proxy traversal of the plugin object in the getter.
2. Rewrite `canRevert` getter as an early-return guard instead of a
   single compound `&&` expression — the compiler handles simple `if`
   guards correctly.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@malibio
malibio merged commit 6a00eac into main Jun 4, 2026
@malibio
malibio deleted the worktree-issue-1314-fix-persistence-coordinator-race branch June 4, 2026 07:53
malibio added a commit that referenced this pull request Jun 22, 2026
…o to clobber optimistic state (#1315)

* Fix PersistenceCoordinator race: hasPending gap clobbers optimistic state (closes #1314)

When a queued op fires via setTimeout after the executing op completes,
there was a brief window where hasPending() returned false. WatchNodes
setNode arriving in that window bypassed the skip-while-editing guard
and overwrote the just-written optimistic value (e.g. provider='native').

Fix: re-register the queued op in pendingOperations as a placeholder
before clearing executingOperations, so hasPending() stays true
throughout the transition.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* Fix PatternState.canRevert: avoid compound && in getter with reactive $state

Under vite-plugin-svelte v6 + Svelte 5.56, class getters in .svelte.ts
files are compiled via compileModule which routes through the Svelte
runtime. A compound `&&` expression returning a plain boolean in a
getter with a reactive _creationSource was being mis-evaluated — the
compiled output ignored the right-hand false operand and returned a
reactive/truthy value instead.

Two changes:
1. Cache `plugin.pattern.canRevert` as a plain boolean field
   `_pluginCanRevert` at construction/mutation time, avoiding deep
   reactive proxy traversal of the plugin object in the getter.
2. Rewrite `canRevert` getter as an early-return guard instead of a
   single compound `&&` expression — the compiler handles simple `if`
   guards correctly.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[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.

Fix PersistenceCoordinator race: hasPending gap allows WatchNodes echo to clobber optimistic state

1 participant