Skip to content

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

Closed

Description

@malibio

Problem

When a persistence operation completes and there is a queued successor, there is a brief window where hasPending(nodeId) returns false. During this gap, a WatchNodes database-echo event can bypass the skip-while-editing guard in setNode() and clobber optimistic state written by the user.

Observed symptom: selecting 'Built-in model' in the AI chat provider picker has no visible effect — the provider property written optimistically gets overwritten by the stale database echo before the queued operation runs.

Root Cause

In PersistenceCoordinator.persist()'s finally block:

  1. pendingOperations.delete(nodeId) — node removed from pending
  2. Queued op found → setTimeout(() => persist(...)) scheduled
  3. executingOperations.delete(nodeId) — node removed from executing

Between steps 2 and 3, and until the setTimeout callback fires and registers the queued op in pendingOperations, hasPending() returns false.

Fix

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

Files

  • packages/desktop-app/src/lib/services/shared-node-store.svelte.ts

Activity

  1. added
    bug
    on Jun 3, 2026
  2. added a commit that references this issue on Jun 4, 2026
    6a00eac
  3. added a commit that references this issue on Jun 22, 2026
    24cfd80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugui

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions