Skip to content

AI chat nodes can render empty in the UI after a WatchNodes reconnect, despite intact database content #1979

Closed

Description

@malibio

Overview

During manual testing of #1956 (model picker changes), previously-created AI chat conversations rendered as empty (no messages) in the UI after the daemon was restarted several times in one session. The underlying data was never lost — this is a frontend read/cache bug, not a persistence bug.

Problem Statement

The user created 4 AI chat conversations in one session, interacting with Gemma 4 E4B and Gemma 4 26B-A4B. After the daemon was restarted several times (to pick up RUST_LOG/NODESPACE_PROMPT_DUMP env var changes via a launchd plist edit), navigating back to 2 of the 4 previously-created chat nodes showed them as empty in the UI — no messages rendered, despite each having a full multi-turn conversation.

Confirmed NOT a data-loss bug. Querying the database directly (~/.nodespace/database/nodespace.db, node table, properties column) for all 4 chat node IDs shows every one has the full conversation intact:

  • f54df478-e4a7-40b4-9888-e3b873040a0b — 6 messages (one of the two reported empty in the UI)
  • 6418ef13-89e0-47d5-a29b-5f09da2d4fb4 — 6 messages (the other reported empty)
  • 7b2a0f62-7d17-4809-bc5e-646ba135185e — 8 messages
  • 8671f817-096a-4a2b-93fb-642cb510e485 — 6 messages

Daemon logs (~/.nodespace/logs/nodespaced.log) confirm all 4 nodes completed ai-chat turn triggered / ai-chat turn complete cycles successfully with no errors, for every turn in every conversation — including the two now showing empty in the UI.

Likely trigger (unconfirmed, needs investigation). Around the time the daemon was restarted, the log shows a WatchNodes stream failure and reconnect storm:

WatchNodes stream failed: WatchNodes stream returned an error item: status: Unknown, message: "h2 protocol error: error reading a body from connection" ... reconnecting in 1s
WatchNodes stream failed: failed to open WatchNodes stream: status: Unavailable, message: "Connection refused (os error 61)" ... reconnecting in 2s
[repeats with backoff until reconnect succeeds ~7 seconds later]

This suggests the frontend's live node-update subscription (WatchNodes, consumed by sharedNodeStore) entered a degraded state during the daemon restart window, and the client-side cache either held an empty/stale entry for those two specific nodes through the outage, or failed to properly refetch/reconcile after the stream recovered.

packages/desktop-app/src/lib/components/viewers/ai-chat-node-viewer.svelte:78 reads via sharedNodeStore.getNode(nodeId). A fallback fetch exists at ai-chat-node-viewer.svelte:399 (backendAdapter.getNode(nodeId)), so the bug is likely in when/whether that fallback fires, or in whether sharedNodeStore correctly overwrites a stale/empty cached entry once a real fetch returns.

Why this matters: if a WatchNodes reconnect can silently leave the UI showing incorrect (empty) state for existing data, that is a reliability problem independent of restart frequency — any transient connection drop (network blip, a production daemon crash/restart, laptop sleep/wake) could trigger the same symptom for a real user, showing a false "this conversation is gone" state when the underlying data is intact.

ADR-049 (../nodespace-docs/decisions/049-canonical-reactivity-store-pattern.md) already names the general class this belongs to: "a recurring regression class we have paid for repeatedly (stale content after edit, blanked cells after delete, reverted node-type after a slash command)" — caused by the local store copy racing asynchronous domain-event echoes from the daemon. This issue's trigger (a WatchNodes reconnect after daemon restart) is a variant of that same race that ADR-049 does not appear to explicitly cover.

Proposed Solution

  • Reproduce deterministically: open an AI chat node with content, kill/restart the daemon to trigger a WatchNodes reconnect, then navigate away and back to that chat node — confirm whether the empty-render state reproduces on demand.
  • Trace sharedNodeStore's handling of a WatchNodes stream error/reconnect: does it invalidate cached entries on disconnect, or leave them stale? Does a successful reconnect trigger a refetch of currently-relevant/open nodes, or only newly-navigated-to ones?
  • Trace the fallback fetch at ai-chat-node-viewer.svelte:399 — under what conditions does it fire, and does it correctly overwrite a stale/empty cached entry once the fetch returns real data?
  • Determine whether this is specific to ai-chat nodes or a general sharedNodeStore reconnect-handling gap affecting any node type.

Acceptance Criteria

  • Root cause identified and documented: what state sharedNodeStore and/or the ai-chat-node-viewer component are left in after a WatchNodes reconnect that causes existing content to render empty
  • Fix applied so a WatchNodes reconnect (or any daemon-connection interruption) cannot leave a node's UI state showing empty/stale content when the backend has real data
  • Regression test added covering the reconnect-then-navigate-back scenario
  • Confirmed whether the bug is ai-chat-specific or a general sharedNodeStore gap; if general, scope the fix accordingly
  • Tests pass (bun run test:all)
  • Code passes bun run quality:fix

Technical Specifications

Reference Files

  • AI chat viewer: packages/desktop-app/src/lib/components/viewers/ai-chat-node-viewer.svelte — node derivation at line 78 (sharedNodeStore.getNode(nodeId)), fallback fetch at line 399 (backendAdapter.getNode(nodeId))
  • Shared node store: packages/desktop-app/src/lib/services/shared-node-store.svelte.ts — owns the client-side node cache and (per the daemon log evidence) subscribes to the WatchNodes stream
  • Daemon logs: ~/.nodespace/logs/nodespaced.log — search for WatchNodes stream failed to find reconnect events and their timing relative to node reads

Related Architecture

  • ../nodespace-docs/decisions/049-canonical-reactivity-store-pattern.md — names the general "local store races async daemon echo" regression class this issue's trigger is a variant of

Related Issues

Activity

  1. added
    bug
    on Aug 5, 2026
  2. malibio commented on Aug 5, 2026

    @malibio
    CollaboratorAuthor

    Update: found a concrete structural anomaly, not just a timing race

    Checked the actual properties JSON for the specific node reported empty ("Create AI Chat with 26B Gemma", 6418ef13-89e0-47d5-a29b-5f09da2d4fb4) against the three other AI-chat nodes from the same session.

    All 4 nodes have their 6-8 messages fully intact (confirmed again by reading the raw JSON, not just counting). But the top-level properties keys differ:

    node_id properties top-level keys
    8671f817-... ["ai-chat"]
    7b2a0f62-... ["ai-chat"]
    f54df478-... ["ai-chat"]
    6418ef13-... (reported empty) ["ai-chat", "text"]

    6418ef13-... — one of the two nodes reported rendering empty in the UI — is the only one carrying a stray "text": {} key alongside the expected "ai-chat" key. The other reported-empty node (f54df478-...) does not have this extra key, so it isn't a clean 1:1 explanation for both reports, but it's a concrete, reproducible structural difference on at least one of them — not just a timing/cache-staleness guess.

    This points toward a possible node-type/behavior confusion (something writing an empty text-node-shaped properties bucket onto an ai-chat node) rather than purely a WatchNodes reconnect race. Worth checking whether the frontend's node-type dispatch (deciding which viewer/behavior to use, or which properties key to read) gets confused when a node's properties blob carries a key for a type other than its own node_type (ai-chat here) — that could plausibly cause the message list to read from the wrong place and appear empty, independent of any connection/reconnect issue.

    The WatchNodes reconnect-storm timing in the original report may still be a contributing factor (worth checking if this text key appeared as a result of something that ran during that window), but this new finding is a more specific, actionable lead than the original "likely a reconnect race" framing — investigation should start with tracing how/why 6418ef13-... ended up with a text key in its properties at all.

  3. mstomar125 commented on Aug 14, 2026

    @mstomar125
    Contributor

    Root-caused and fixed in #2084.

    Root cause: the desktop app's WatchNodes bridge (`watcher.rs`) reconnects with backoff on any daemon disruption, but opens a fresh live-forward stream with no catch-up replay — updates that happened during the outage are gone, not delayed. `pane-content.svelte`'s hydration logic only checked whether a node was present in `sharedNodeStore`, never whether it might be missing an update from the gap, so a node cached before an outage kept rendering its pre-outage snapshot forever (matching the exact repro: an AI chat conversation with an intact multi-turn history in the DB rendering empty after navigating back post-restart).

    Confirmed general, not ai-chat-specific — the fix lives in `shared-node-store.svelte.ts` (reconnect-generation tracking + `isPossiblyStale`/`ensureNode` re-confirm) and `pane-content.svelte` (hydration gate now checks freshness, not just presence). No changes needed in `ai-chat-node-viewer.svelte` — it already reads the store reactively.

    Regression tests added at both the store level (reconnect-then-navigate-back repro through the real write path) and the component level (real `pane-content.svelte` mount, reconnect-triggered refetch). See PR for full details.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions