Repository navigation
Description
Overview
Two related bugs in SharedNodeStore.updateNode()'s persistence path, found and fixed via live interactive testing (both reproduced directly in the running Tauri app and browser dev mode, not just identified by reading code).
Problem Statement
Bug 1: content-only edits forced immediate (non-debounced) persistence
updateNode()'s persist-mode selection computed isNodeTypeChange as 'nodeType' in changes — mere key presence, not a value comparison. reactive-node-service.svelte.ts's updateNodeContent() always bundles the CURRENT (unchanged) nodeType alongside content on every keystroke — a deliberate prior fix so an in-flight slash-command type conversion isn't reverted by a racing content update. That combination meant isNodeTypeChange was true on every single keystroke of every text edit, forcing mode: 'immediate' instead of 'debounce'.
Immediate mode fires an RPC per keystroke instead of coalescing. An early keystroke's broadcast echo could land after later keystrokes moved the local content on, misclassifying it as a foreign write and firing a spurious "Your edit conflicted with a remote change" toast — and, under fast enough typing, visibly corrupted persisted content. Reproduced live: typing "Testing conflict reproduction now" was persisted and read back as "Tng conflict reproduction nowesti" (the debounce race scrambled the sequence of partial-content writes).
Bug 2: property-only updates never synced typed fields back from the backend
In the same updateNode() persistence closure, after backendAdapter.updateNode() returns the backend's authoritative response, only .version was copied back into the local in-memory node. Every other field the backend returned — including type-specific top-level fields the backend's node_to_typed_value flattening promotes (ai-chat's provider/model, task's status/priority, etc.) — was discarded.
The optimistic local write for a properties-only update (e.g. AiChatModelSelector selecting a model) sends the un-flattened { properties: { provider, model } } shape client-side. Since the backend's corrected, flattened response was never applied beyond .version, the local node's top-level provider/model fields stayed undefined forever.
Reproduced live: selecting a model in the AI Chat viewer left the UI stuck on "Choose a model to get started" indefinitely — the message textarea never appeared — even though the daemon had genuinely persisted the selection (confirmed via a direct API read showing properties.ai-chat.model correctly set). A full page reload did not fix it either, which rules out a pure reactivity/timing explanation: the local node object never received the corrected top-level fields through any path, fresh hydration included, until this fix.
Proposed Solution
Both already implemented and manually verified working (bug 2 confirmed live in the Tauri app: textarea now appears after model selection; bug 1 confirmed via a new regression test that fails without the fix and passes with it).
Bug 1 fix: compare changes.nodeType !== existingNode.nodeType instead of mere key presence.
Bug 2 fix: apply the full backendAdapter.updateNode() response over the local node (Object.assign) instead of only .version — but explicitly re-assert .content from the pre-update local node afterward. A user may still be typing when this RPC resolves; the response reflects an earlier send, so blindly applying its .content would lose newer keystrokes. Only .content is protected this way — every other field (including the now-correct typed fields) is taken from the backend's response.
Acceptance Criteria
- Bug 1:
isNodeTypeChangeuses a value comparison, not presence - Bug 1: regression test added to
node-content-persistence-regression.test.ts, verified to fail without the fix and pass with it - Bug 2: full backend response applied to the local node on update, with
.contentprotected against in-flight local edits - Bug 2: live-verified in the Tauri app — AI Chat model selection now shows the message textarea
- No regression to
bun run test:all -
bun run quality:fixclean
Technical Specifications
Reference Files
packages/desktop-app/src/lib/services/shared-node-store.svelte.ts:updateNode()—isNodeTypeChangecomputation (~line 1089), backend-response-sync block (~line 1654).packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts:updateNodeContent()(~line 463) — the nodeType-bundling comment explaining whynodeTypeis always sent alongside content.packages/desktop-app/src/lib/components/viewers/ai-chat-node-viewer.svelte:handleModelSelect(~line 144); theprovider === undefined/isMessageProvider && !modelrender branches (~line 419-438) that stayed stuck without this fix.packages/desktop-app/src/tests/services/node-content-persistence-regression.test.ts: new regression test for bug 1, simulating the exact real-world payload shapeupdateNodeContentsends (content + redundant unchangednodeTypetogether) — the existing tests in this file only ever sent{ content }alone, so they never exercised this path.
No architecture impact
Searched nodespace-docs for relevant ADRs (decisions/, architecture/, components/) — ADR-049 (Canonical Reactivity-Store Pattern, Accepted) covers the SharedNodeStore/SvelteMap reactivity model this bug lives under, but this fix is consistent with it, not a reversal: AiChatNodeViewer's $derived(sharedNodeStore.getNode(nodeId)) direct-read pattern is exactly ADR-049's intended shape, and the bug fixed here is a data-correctness gap underneath that reactivity layer (the backend's authoritative response being discarded), not a reactivity-pattern violation. No companion nodespace-docs change required.
Related Issues
- Daemon does not suppress same-origin WatchNodes echo — frontend guesses via content-comparison heuristic instead of authoritative client identity #1689 (separate: daemon-side same-origin echo suppression — the deeper architectural fix for the conflict-toast class of bug; this issue's bug 1 is a narrower, already-landed mitigation for one specific trigger of that same symptom)
Activity
malibio commentedon Jul 18, 2026
Frontend baseline: 166 test files passed, 4105 tests passed (45.78s) — includes the new regression test already applied in this worktree.
Content-only edits forced immediate (non-debounced) persistence via r…