Skip to content

Daemon does not suppress same-origin WatchNodes echo — frontend guesses via content-comparison heuristic instead of authoritative client identity #1689

Closed

Description

@malibio

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:

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

  1. Assign each gRPC connection (or each desktop-app/local-agent session) a stable client ID at connection time.
  2. Route writes made through that connection through a NodeService scoped via with_client(that_id).
  3. In watch_nodes (packages/daemon/src/services/node_service.rs), compare each envelope's metadata.source_client_id against the subscribing connection's own client ID; suppress (or explicitly flag as "your own write, already applied optimistically") events that match.
  4. Delete or radically simplify isPlausibleOwnEcho / lastPersistedContent / the skip-while-editing content-comparison guard in shared-node-store.svelte.ts — replacing "guess from content" with "trust the server's identity signal," consistent with C5's original intent.
  5. Multi-client scenarios (cloud sync, future multi-window) still need genuine-foreign-write detection ([bug] A foreign database write to a focused node is silently discarded with no conflict signal #1437's conflictNotifications signal 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_nodes suppresses or clearly flags same-origin events so the frontend no longer needs to content-compare to detect its own echo
  • isPlausibleOwnEcho and lastPersistedContent are 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 database write 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-docs change: 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_id field (~line 756), with_client() (~line 1571 doc reference), emit_event() stamping source_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_nodes handler (~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: isPlausibleOwnEcho region (~line 600-640 area, lastPersistedContent map), the skip-while-editing guard's notifyConflict branch — 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

Activity

  1. added
    bug
    on Jul 18, 2026
  2. malibio commented on Jul 18, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 4104 passed (166 test files)

  3. self-assigned this
    on Jul 18, 2026
  4. added a commit that references this issue on Jul 18, 2026
    6cf2e92
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