Skip to content

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

Closed

Description

@malibio

Overview

Editing a node's content in a single-user, single-writer session reliably fires the "Your edit conflicted with a remote change" toast (version-mismatch conflict notification), even though there is no other writer and no real conflict. Reported as happening on effectively every content edit.

Problem Statement

User Experience:

  1. User edits a node's content (e.g. types in a text node).
  2. The daemon persists the change and its broadcast echoes back to the client.
  3. The client misclassifies its own echo as a foreign write and shows a conflict toast, even though nothing else modified the node.

Evidence:

  • The toast text matches CONFLICT_MESSAGE['version-mismatch'] = "Your edit conflicted with a remote change" in packages/desktop-app/src/lib/services/shared-node-store.svelte.ts.
  • VersionConflictModal (packages/desktop-app/src/lib/components/version-conflict-modal.svelte) is dead code — not imported/rendered anywhere — so the actual UI surface is the toast (conflict-toast.svelte) fed by conflictNotifications (packages/desktop-app/src/lib/stores/conflict-notifications.svelte.ts), not the modal.

Root Cause

Location: packages/desktop-app/src/lib/services/shared-node-store.svelte.ts, isPlausibleOwnEcho() (~line 713) and its call site in setNode()'s skip-while-editing guard (~line 1529-1550, added by #1437).

isPlausibleOwnEcho(local, incoming) returns true only when incoming.content exactly matches lastPersistedContent.get(incoming.id) — the content this client most recently sent to the backend, recorded by the persistence path immediately before the UpdateNode RPC fires (~line 1667). If there is no entry yet for a node in lastPersistedContent, the function returns false unconditionally — the code's own doc comment (~line 705) calls this out explicitly as a known trade-off:

"a client that has never persisted this node before (initial-load path, no edits) reports false for all broadcasts — including legitimate own-echoes from the daemon's first confirmation after load."

When isPlausibleOwnEcho returns false, setNode()'s guard treats the broadcast as a foreign write to an actively-edited node and fires the version-mismatch conflictNotification (~line 1540-1550) — even when the "foreign" write is actually this same client's own first-ever echo for that node.

Why it happens on effectively every edit, not just the very first: lastPersistedContent is an in-memory Map on the SharedNodeStore singleton with no eviction logic visible other than being populated on write — so it should persist across edits within a session for nodes already edited once. The frequency reported ("every time I change content of a node") suggests either: (a) most day-to-day edits are to nodes not yet edited this session (freshly created/loaded nodes), and/or (b) a race where the database broadcast for a given edit can arrive and be processed before the lastPersistedContent.set() write on the persistence path completes for that same edit, re-triggering the false-negative on nodes that have prior entries too. Both possibilities should be investigated.

Why this wasn't caught by tests

packages/desktop-app/src/tests/services/shared-node-store-skip-while-editing.test.ts, describe block 'foreign-write conflict signal (#1437)' (~line 359), has three tests covering this mechanism, including one explicitly named 'does NOT notify for an own-echo broadcast' (~line 378). However, all three tests call the test-only helper store.__test_setLastPersistedContent(nodeId, content) before simulating the broadcast — manually pre-populating lastPersistedContent so the guard is never exercised in its empty/cold state. No test simulates the real-world sequence where a node's first-ever edit's broadcast arrives with no prior lastPersistedContent entry — which is exactly the gap the function's own doc comment identifies as a known false-negative case. The test suite validates the mechanism works when primed, but never validates (or asserts the accepted trade-off of) the un-primed path, which is what's firing in normal use.

Proposed Solution

Investigate whether the "no record = false = treat as foreign" trade-off is actually acceptable given how often nodes are edited for the first time in a session (every newly created/loaded node). Options to evaluate:

  • Populate lastPersistedContent at node hydration/load time (from the node's loaded content), not only after the first local edit, so first-edit echoes have a baseline to match against.
  • Add a test that exercises the real (non-test-backdoor) sequence: create/load a node, edit it once via the real persistence path, and assert no false conflict notification fires when its own broadcast echoes back — without calling __test_setLastPersistedContent.
  • Re-examine whether a race exists between the broadcast handler and the lastPersistedContent.set() write on the persistence path for nodes with existing entries.

Acceptance Criteria

  • Editing a node's content in a single-writer session does not produce a "Your edit conflicted with a remote change" toast
  • A regression test exercises the real (non-backdoor) persistence path for a node's first edit and asserts no false conflict notification
  • Genuine foreign-write conflicts (a different writer's change to a focused node) still correctly raise the notification (existing test 'raises a version-mismatch notification when a foreign broadcast hits a focused node' continues to pass)
  • Investigate and either fix or explicitly document/dismiss the possible broadcast-vs-persistence-write race for nodes with existing lastPersistedContent entries
  • Code passes bun run quality:fix
  • No new failures in bun run test:all

Technical Specifications

Reference Files

  • packages/desktop-app/src/lib/services/shared-node-store.svelte.ts — isPlausibleOwnEcho() (~line 713), lastPersistedContent map (~line 601), guard call site (~line 1529-1550), persistence-path write to lastPersistedContent (~line 1667)
  • packages/desktop-app/src/lib/stores/conflict-notifications.svelte.ts — notification store
  • packages/desktop-app/src/lib/components/conflict-toast.svelte — toast UI rendering the notification
  • packages/desktop-app/src/tests/services/shared-node-store-skip-while-editing.test.ts — existing (backdoored) test coverage, 'foreign-write conflict signal (#1437)' describe block (~line 359)

Unrelated dead-code note

packages/desktop-app/src/lib/components/version-conflict-modal.svelte is not imported or rendered anywhere in the app — confirmed via repo-wide search. Worth a separate cleanup pass (not in scope here) to either wire it up or delete it, since its existence could mislead someone investigating this area into thinking it's the active conflict UI.

Related Issues

Activity

  1. added
    bug
    on Jul 8, 2026
  2. mstomar125 commented on Jul 9, 2026

    @mstomar125
    Contributor

    Fixed in #1587.

    Root cause: the skip-while-editing guard's isPlausibleOwnEcho had no lastPersistedContent baseline for a never-locally-edited node, so the daemon's first echo after the WatchNodes subscription opens (streaming the node's current, unchanged state) was misclassified as a foreign write and fired the version-mismatch toast — on effectively every edit of a freshly loaded node.

    Fix: prime lastPersistedContent from the server-confirmed content on the setNode and batchSetNodes accept paths (gated on shouldMarkAsPersisted; initial tree load flows through batchSetNodes). The first echo of unchanged content now matches and is silent; a genuinely different foreign write still fails the equality check and raises the conflict. The actively-edited guarded early-return is deliberately left un-primed so it can't adopt a foreign write as the baseline.

    Race check: the hypothesised broadcast-vs-persistence race is dismissed for own edits — lastPersistedContent.set() runs synchronously immediately before the UpdateNode RPC, which strictly precedes the echo, so a node's own echo always finds its own baseline. The false positives were purely the unprimed-node case.

    Tests (no __test_ backdoor): load-echo of a hydrated node → no notification; real foreign write after priming → still notified. Full frontend unit suite 3952/3952; quality:fix clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugfoundation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions