Repository navigation
Description
Overview
SharedNodeStore keeps the daemon-confirmed value of a node and this client's unacknowledged edits in one object. Every asynchronous reply and every remote event therefore needs a hand-written merge policy, and the store decides whether to accept data by asking the UI which node is focused. ADR-049 named this separation as deferred work that its reactive-source fix would make possible. This issue does it.
This is a design decision, not a routine fix. The design below is a proposal from a code-reading review that read roughly 800 of the store's 5,554 lines, and none of reactive-node-service.svelte.ts's bodies, the optimistic operation manager, or the tests. The first step of the work is to read the rest, then write and agree the ADR. Treat every specific below as a lead to verify, not as established.
Problem Statement
- One object for two kinds of state. Because optimistic and confirmed values share an object, each reply is merged field by field against a snapshot taken before the call (
shared-node-store.svelte.ts, around lines 2909-2960), with per-field sequence numbers (around 954-1000), a pending-typed-field set (around 958-963), captured non-content fields, andhadQueuedWritecaptured beforeclearQueued()because a live read is described in the code as self-referential and racy (around 2509-2520). The store also carriesversions,persistedNodeIds,pendingUpdates,typedFieldWriteSeq,pendingTypedFields,nodeGenerationand batches alongside the nodes. - The store reads UI focus to decide data acceptance. It imports
focusManager(line 29) and drops a remote update for a focused or pending node (around lines 2521, 2753-2797, 3172, 3595, 4667; policy inremote-update-policy.ts). The review found no refetch on blur, andresyncNodeFromServeris called only from conflict paths, so a dropped update may leave the store stale until the next write conflicts. This staleness was not reproduced and the unread part of the file may handle it. - Version rule vs docs.
frontend-state-and-persistence.mdsays an incoming event with an equal or older version is ignored;decideRemoteUpdateapplies any database update to a node that is not being edited, whatever its version.batchSetNodeswas not checked. - Size. The file is 5,554 lines and braids node data, version and concurrency state, and persistence coordination, the three concerns ADR-049 says must eventually be separated.
Proposed Solution
- Two maps.
confirmedis written only from daemon replies and events, and only when the incoming version is newer.pendingholds this client's unacknowledged patches per node, dropped on acknowledgement or failure. getNode(id)returns confirmed overlaid with pending, as a per-key reactive read.- Remote updates always apply to
confirmed. Rollback is "drop the patch". A conflict is "confirmed changed a field that has a pending patch". - The store stops importing
focusManager. Whether a remote change may alter text the user is typing is decided by the edit session, not by the store. - Split the file into data, persistence and eviction modules as part of the change.
Expected removals, to be confirmed against the full file: the skip-while-editing branches, typedFieldWriteSeq, pendingTypedFields, the snapshot-compare merges and the captured fields.
Documentation
- ADR-049 "Why this is the precondition for untangling persistence" and Negative consequence 4 - the separation of node data, version/concurrency state and persistence coordination is deferred, not abandoned. This issue is that separation.
- ADR-026, including its amendment making the daemon the concurrency adjudicator - the version-conflict pipeline the store's replies come from. Partially superseded; follow its chain to the current decision before designing.
- ADR-042 - delete-wins, which the pending/confirmed model must preserve.
- ADR-068 and Conflict Journal and Resolution - what a conflict is and where it is recorded.
- ADR-077 - client-computed fields and self-echo, a merge case the new model must cover.
- Frontend State & Persistence - the store's layers, node operation lifecycles and the ten listed race mitigations, most of which this changes.
- Updates: a new ADR for the confirmed/pending model (below) and a rewrite of the affected sections of
frontend-state-and-persistence.md, in the same change as the code.
Architecture Impact
- Carries out the separation ADR-049 deferred. No existing ADR records how confirmed and optimistic state are structured; the search found none.
- May change behaviour ADR-026 and the state doc describe: today a remote update to a node being edited is dropped; under this design it is applied to confirmed state and reconciled against the pending patch. If that changes any conflict outcome a user can see, the ADR must say so.
- A companion nodespace-docs change is required and comes first: a new ADR recording the model (what writes each map, the version rule, how a conflict is detected and surfaced, how delete-wins and client-computed fields fit), pushed to nodespace-docs
mainbefore implementation.
Acceptance Criteria
- The whole of
shared-node-store.svelte.ts,reactive-node-service.svelte.ts, the optimistic operation manager,remote-update-policy.tsand their tests are read, and the problem statement above is corrected where the unread code contradicts it - An ADR for the confirmed/pending model is written, agreed and on nodespace-docs
mainbefore implementation - Confirmed state is written only from daemon replies and events, under one version rule stated in the ADR
- Pending patches are held separately and dropped on acknowledgement or failure; rollback restores the confirmed value without a snapshot comparison
- The store does not import
focusManagerand no branch in it tests whether a node is being edited - A remote update to a node with a pending patch is applied to confirmed state, and a conflicting field is surfaced as a conflict, not silently dropped
- A test shows a node updated remotely while focused is current after blur, with no further write needed
- The per-field sequence numbers, pending-typed-field set and pre-call snapshot merges are deleted, or each survivor is justified in the ADR
- The store is split into data, persistence and eviction modules, each with its own tests
- The existing store tests pass or are replaced by tests of the same behaviour;
bun run test:changedandbun run test:dbpass;bun run quality:fixis clean -
frontend-state-and-persistence.mddescribes the new model and its statements match the code
Technical Specifications
Files to Modify
packages/desktop-app/src/lib/services/shared-node-store.svelte.tspackages/desktop-app/src/lib/services/remote-update-policy.tspackages/desktop-app/src/lib/services/tauri-sync-listener.tspackages/desktop-app/src/lib/services/reactive-node-service.svelte.ts- the optimistic operation manager and the persistence coordinator
Implementation Details
- Keep what the review found already sound: database-switch epochs in the sync listener (around lines 149-179), per-node write serialization, same-origin echo suppression at the daemon, and multi-viewer reads of one key.
SvelteMap.setis a no-op for the same reference; the store stores a fresh shallow copy today (around lines 1593-1607). The overlay read must stay reactive per key.- No compatibility path and no dual mode: replace the single-object model and delete it in the same change.
- This is pure store logic; test it in Happy-DOM without components. Use real multi-step sequences (write, remote event, reply out of order) rather than timing assertions.
Dependencies
- An explicit edit session owns a focused node's draft and caret, replacing the timer-arbitrated editor bridge #4380 (the edit session takes over deciding what a remote change does to text being typed, which is what lets the store stop reading focus)
Related Issues
- Outline rows read their node from the store by id, with callback props instead of dispatched events #4379
- Remove dead editor workarounds and state-writing effects that ADR-049 forbids #4378
Non-Goals
- Any change to the daemon's concurrency adjudication or to the Rust side.
- Sync semantics; core holds no sync code.
Activity
malibio commentedon Nov 28, 2026
Moved to NodeSpace: the task "Separate confirmed and pending node state in the shared node store so remote updates always apply" (
b6913fa1-79a9-47c1-a3bf-d9c2c08920c1) in the NodeSpace workspace. The team's work is tracked there, so this GitHub copy is closed to keep its status in one place.