Repository navigation
Description
Overview
The recurring "Your edit conflicted with a remote change" false-positive toast (most recently: fired on effectively every keystroke — root-caused and fixed in this session, see below) keeps resurfacing across multiple issues (#1437, #1586, #1684) because the fixes since #1437 have all patched a client-side heuristic that should not exist at all: ADR-026's C5 amendment already decided the daemon is the sole conflict adjudicator and explicitly deleted an earlier version of this exact heuristic for exactly this failure mode.
Problem Statement
packages/core/src/services/node_service/mod.rs has a client_id/source_client_id mechanism built for tagging event origin (NodeService::with_client(), emit_event() stamping source_client_id on every EventEnvelope, subscribe_to_events() returning that metadata) — but it is never wired end-to-end. grep -rn "with_client(" packages/daemon/src returns nothing: the daemon's gRPC layer (packages/daemon/src/services/node_service.rs, watch_nodes handler) has no per-connection client identity, never scopes a write's NodeService via with_client(), and watch_nodes's broadcast stream sends every domain event to every subscriber unconditionally — including the client that made the write.
As a result, a client currently has no server-provided signal to recognize "this broadcast is my own write echoed back" versus "this is a genuine foreign write." The frontend fills that gap with a purely heuristic, content-comparison-based guess (isPlausibleOwnEcho / lastPersistedContent in packages/desktop-app/src/lib/services/shared-node-store.svelte.ts), comparing incoming broadcast content against the last content this client sent, across an async network round-trip. That comparison is inherently racy and has needed repeated tightening:
- [bug] A foreign
databasewrite to a focused node is silently discarded with no conflict signal #1437 (closed, 2026-06-24) — introduced this exact client-side heuristic (a foreign write to a focused node was previously silently discarded with no signal). - Editing a node fires a false 'Your edit conflicted with a remote change' toast on first edit #1586 (closed) — "false conflict toast on first edit": the heuristic returned false unconditionally when no prior
lastPersistedContententry existed. Fixed by priming the baseline on hydration. - [bug] Sync-internal LWW conflicts shown as 'Your edit conflicted' toasts for nodes the user never edited #1684 (open) — background sync-reconcile LWW resolutions on nodes the user never touched still produce a misleading "Your edit conflicted" toast via the same heuristic.
- This session — traced a third variant:
isNodeTypeChangein the persist-mode decision (shared-node-store.svelte.ts) was a presence-check ('nodeType' in changes) rather than a value comparison.updateNodeContent()(reactive-node-service.svelte.ts) always bundles the current, unchangednodeTypealongside every content edit (a deliberate Fix: Node type conversions persist as text nodes with truncated content #424-era fix protecting slash-command conversions from a race). That combination forcedmode: 'immediate'instead of'debounce'on every keystroke, so each keystroke fired its own RPC round-trip; an early keystroke's echo could land after later keystrokes moved local content on, misclassifying it as foreign and firing a conflict toast — and, under fast enough typing, visibly corrupting persisted node content ("Testing conflict reproduction now"was persisted and read back as"Tng conflict reproduction nowesti").
Fixed in this session (frontend-only): the isNodeTypeChange value-comparison bug, with a regression test (node-content-persistence-regression.test.ts) verified to fail without the fix and pass with it. This resolves the "every keystroke" reproduction, but is explicitly a fix to the guessing heuristic's accuracy, not to the underlying architectural gap. A narrower race in the same heuristic is still reproducible even with the debounce fix in place: a single debounced write's confirmation echo can still race against content still landing locally and misclassify as foreign, firing one spurious toast.
Architecture Impact
This reverses (in spirit, via a different mechanism) ADR-026's C5 amendment ("Daemon as OCC Adjudicator", 2026-05-30): C5 states plainly — "The client (Tauri frontend) consumes the verdict; it does not guess or detect conflicts independently" — and explicitly deleted a prior client-side heuristic (a 5-second conflictWindowMs timing window in shared-node-store.svelte.ts) for the documented reason that it "was structurally incapable of detecting cross-client conflicts (it only saw this client's pending writes) and produced false positives."
#1437 (2026-06-24), less than a month after C5 shipped, reintroduced a client-side "is this a foreign write" heuristic — isPlausibleOwnEcho — with different mechanics (content comparison instead of a timing window) but the same fundamental shape C5 rejected: the client guessing at conflict/echo classification instead of the daemon adjudicating it. This was evidently not checked against ADR-026/C5 before implementation. Every fix since (#1586, this session, and #1684's remaining work) has been tightening that reintroduced heuristic rather than removing it.
This issue does not ask to reverse C5's actual OCC-conflict pipeline (version-mismatch detection via VersionConflict → x-version-conflict header → conflictNotifications remains correct and unaffected) — only the separate, additional "is this incoming broadcast my own echo" classification that #1437 layered on top of it. Fixing this requires a companion nodespace-docs change: an amendment to ADR-026 (or a new ADR) documenting that same-origin echo suppression is now handled by the daemon via client_id, and that the frontend's content-comparison heuristic is deleted as a result — mirroring how C5 itself documented the deletion of its predecessor heuristic.
Why This Matters
In normal desktop use, the daemon currently serves a single connected client (no cloud sync, no second window). In that mode, every database-sourced broadcast a client receives is necessarily its own echo — there is no other writer it could be, yet the client still runs a fragile, content-comparison guess to figure that out. The daemon already has the identity information needed to answer this authoritatively and does not use it.
Proposed Solution
- Assign each gRPC connection (or each desktop-app/local-agent session) a stable client ID at connection time.
- Route writes made through that connection through a
NodeServicescoped viawith_client(that_id). - In
watch_nodes(packages/daemon/src/services/node_service.rs), compare each envelope'smetadata.source_client_idagainst the subscribing connection's own client ID; suppress (or explicitly flag as "your own write, already applied optimistically") events that match. - Delete or radically simplify
isPlausibleOwnEcho/lastPersistedContent/ the skip-while-editing content-comparison guard inshared-node-store.svelte.ts— replacing "guess from content" with "trust the server's identity signal," consistent with C5's original intent. - Multi-client scenarios (cloud sync, future multi-window) still need genuine-foreign-write detection ([bug] A foreign
databasewrite to a focused node is silently discarded with no conflict signal #1437'sconflictNotificationssignal for a different client's write) — that part of the design is sound and stays; only the same-origin classification changes from heuristic to authoritative.
Acceptance Criteria
- Daemon assigns a stable identity per client connection and threads it through
NodeService::with_client()for writes made on that connection -
watch_nodessuppresses or clearly flags same-origin events so the frontend no longer needs to content-compare to detect its own echo -
isPlausibleOwnEchoandlastPersistedContentare deleted or reduced to a fallback path, in favor of the authoritative daemon signal - No regression to genuine foreign-write conflict detection (multi-client / future cloud-sync scenarios) — [bug] A foreign
databasewrite to a focused node is silently discarded with no conflict signal #1437's conflict-notification behavior still fires correctly when a different client's write lands on a focused node - The narrow debounced-write echo race identified in this session no longer produces a spurious toast, because the client no longer relies on content comparison at all
- Companion
nodespace-docschange: amend ADR-026 (or file a new superseding ADR) documenting the daemon-side echo-suppression mechanism and the removal of the client-side heuristic - Code passes
bun run quality:fix - Tests pass (
bun run test:all)
Technical Specifications
Reference Files
packages/core/src/services/node_service/mod.rs:client_idfield (~line 756),with_client()(~line 1571 doc reference),emit_event()stampingsource_client_id(~line 1644),subscribe_to_events()(~line 1604) — the existing, unwired infrastructure this issue connects end-to-end.packages/daemon/src/services/node_service.rs:watch_nodeshandler (~line 1392) — needs per-connection client identity and same-origin filtering added to its broadcast loop (~line 1425-1454).packages/desktop-app/src/lib/services/shared-node-store.svelte.ts:isPlausibleOwnEchoregion (~line 600-640 area,lastPersistedContentmap), the skip-while-editing guard'snotifyConflictbranch — target for deletion/simplification once the daemon signal lands.packages/desktop-app/src/lib/services/remote-update-policy.ts:decideRemoteUpdate/isPlausibleOwnEcho— pure-function extraction of the heuristic (Extract an explicit remote-update policy from the skip-while-editing logic #1608), would need reworking to consume an authoritative same-origin flag instead of comparing content.
Related Issues
- [bug] A foreign
databasewrite to a focused node is silently discarded with no conflict signal #1437 (introduced the client-side heuristic this issue proposes to remove) - Editing a node fires a false 'Your edit conflicted with a remote change' toast on first edit #1586 (first "false toast" fix on the same heuristic — hydration priming)
- [bug] Sync-internal LWW conflicts shown as 'Your edit conflicted' toasts for nodes the user never edited #1684 (background sync-reconcile false toasts on the same heuristic, still open)
Activity
malibio commentedon Jul 18, 2026
Frontend: 4104 passed (166 test files)
Daemon does not suppress same-origin WatchNodes echo — frontend guess…