Skip to content

Prime own-echo baseline on node hydration to stop false conflict toasts (#1586) - #1587

Merged
mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:issue-1586-false-conflict-toast
Jul 9, 2026
Merged

mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:issue-1586-false-conflict-toast

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

Editing a freshly-loaded node in a single-writer session reliably fired a "Your edit conflicted with a remote change" toast even with no other writer. This fixes the false positive at its root.

Root cause

setNode's skip-while-editing guard raises a version-mismatch conflict notification whenever a database-source broadcast for an actively-edited node is not recognised as this client's own echo. Recognition (isPlausibleOwnEcho) compares the incoming content against lastPersistedContent, which was only populated after the first local edit. So a node's first daemon echo after the WatchNodes subscription opens — the daemon streaming the node's current (unchanged) state — had no baseline, was misclassified as a foreign write, and fired a spurious toast. The function's own doc comment already flagged this "no last-sent record ⇒ reports false for all broadcasts, including legitimate own-echoes after load" trade-off; in practice it fired on effectively every edit of a loaded node.

Fix

Prime lastPersistedContent with the server-confirmed content whenever a node is accepted from the daemon broadcast or hydrated from the backend — the setNode and batchSetNodes accept paths (initial tree load goes through batchSetNodes), gated on shouldMarkAsPersisted (true iff the content equals the backend's). Factored into a single primeOwnEchoBaseline() helper so the rationale lives in one place.

  • The first echo of unchanged content now matches → silent.
  • A genuinely different foreign write still fails the equality check → conflict still surfaces.
  • The guarded, actively-edited early-return path is deliberately left un-primed so it can never adopt a foreign write as the baseline (that would defeat foreign-write detection).

On the hypothesised broadcast-vs-persistence race

Investigated and dismissed for a node's own edits: lastPersistedContent.set() on the persistence path runs synchronously right before the UpdateNode RPC, which strictly precedes the daemon's echo — so a node's own C1 echo always finds lastPersistedContent = C1. The false positives came from unprimed (never-locally-edited) nodes, which this change addresses.

Tests

Added two regression tests that drive the real hydration path (no __test_setLastPersistedContent backdoor):

  • does NOT notify on a load-echo of a backend-hydrated node (real path, no backdoor)
  • still notifies on a genuine foreign write after real-path priming (no backdoor)

Verification:

  • shared-node-store-skip-while-editing: 20/20 pass (18 existing + 2 new; existing foreign-write/own-echo/dedup tests unchanged).
  • All shared-node-store suites: 251/251.
  • Full frontend unit suite: 3952/3952, 150 files.
  • bun run --cwd packages/desktop-app quality:fix: eslint 0 errors, svelte-check 0 errors/0 warnings.

Acceptance criteria

  • Editing a node's content in a single-writer session does not produce the false conflict toast
  • Regression test exercises the real (non-backdoor) hydration path and asserts no false notification
  • Genuine foreign-write conflicts still raise the notification (existing + new test)
  • Broadcast-vs-persistence race investigated and dismissed with rationale
  • quality:fix clean; no new frontend test failures

Closes #1586

The skip-while-editing guard raises a "Your edit conflicted with a remote
change" version-mismatch notification whenever a database broadcast for an
actively-edited node is not recognised as this client's own echo. Recognition
depends on lastPersistedContent, which was only populated after the first local
edit. So a node's first daemon echo after the WatchNodes subscription opens
(the daemon streaming the node's current state) had no baseline and was
misclassified as a foreign write, firing a spurious toast on effectively every
edit of a freshly loaded node.

Prime lastPersistedContent with the server-confirmed content whenever a node is
accepted from the daemon broadcast or hydrated from the backend — the setNode
and batchSetNodes accept paths, gated on shouldMarkAsPersisted (true iff the
content equals the backend's). The first echo of unchanged content now matches
and stays silent; a genuinely different foreign write still fails the equality
check and correctly raises the conflict. The guarded, actively-edited early
return is deliberately left un-primed so it can never adopt a foreign write as
the baseline.

Add regression tests that drive the real hydration path with no __test_
backdoor: a load-echo of a backend-hydrated node raises no notification, and a
real foreign write after priming still does.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Verified against shared-node-store.svelte.ts at 3f00ca0 — the fix is correct and, crucially, preserves foreign-write detection:

  • Root cause is right. isPlausibleOwnEcho compares the incoming broadcast against lastPersistedContent, which was only set after the first local edit — so the first daemon echo of a freshly-hydrated node had no baseline and was misread as a foreign write, firing the false toast.
  • The priming can't hide a real conflict — the key invariant. Both primeOwnEchoBaseline(node) calls sit inside if (shouldMarkAsPersisted) on the accept paths (setNode :1602, batchSetNodes :1917) — i.e. server-confirmed content on a node that was not caught by the skip-while-editing guard. The guarded, actively-edited branch early-returns before those blocks, so it's never primed. Therefore while a node is being edited, the baseline stays frozen at the last server-confirmed value, and a genuinely different foreign write still fails the equality check and raises the conflict. Priming only ever adopts content the backend confirmed for a non-actively-edited node.
  • Tests exercise the real path and both directions. does NOT notify on a load-echo… proves the own-echo is now silent; still notifies on a genuine foreign write after real-path priming proves detection survives — and it also asserts getNode('hydrated2').content === 'hello world', i.e. the foreign write isn't applied over the in-progress edit. No __test_setLastPersistedContent backdoor. 20/20 skip-while-editing, 251/251 store, 3952/3952 frontend.
  • Nice touch: the broadcast-vs-persistence race is investigated and dismissed with rationale (own edits set lastPersistedContent synchronously before the UpdateNode RPC, which precedes the echo).

CI green (test:all + test:e2e). Correct, minimal, well-covered — closes #1586.

@mstomar125
mstomar125 merged commit 8bed199 into NodeSpaceAI:main Jul 9, 2026
2 checks passed
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.

Editing a node fires a false 'Your edit conflicted with a remote change' toast on first edit

1 participant