Skip to content

Store AI chat messages as ai-chat-message child nodes with real edges #3448

Closed

Description

@malibio

Overview

Store AI-chat messages as ai-chat-message child nodes of ai-chat-native, instead of a nested messages[] property, with real edges for what each message wrote, resolved or proposed to delete (ADR-088 §3).

Problem Statement

  • Rewrites and buffering. Messages live in one growing messages[] property on the chat node (ADR-028). Every append rewrites the whole conversation, so ADR-028 adds write buffering, makes the frontend the source of truth during a chat, and sets a soft cap of 500 messages.
  • Mention edges are never derived. Message text is inside a property, so sync_mentions (packages/core/src/services/node_service/crud.rs) never sees it.
  • The schema describes a design that was never built. The messages[] item declaration describes a shape (tool_call role, args, status, …) that was never built. The real shape (completedWrites, resolvedEntities, pendingDeletions, question/options, outcome) is undeclared and camelCase.

Proposed Solution

  1. A new core type ai-chat-message: text in content, plus role (user | assistant | system), timestamp, reasoning (optional), outcome (acted | clarified | replied, assistant only) and options (a string list; a clarifying question is the message's content).
  2. Structural rules (ADR-089): parent: must_have_parent_of [ai-chat-native, ai-chat-acp], children: none, ordered by has_child order.
  3. Edges declared on the message schema:
    • wrote / written_by, with edge fields tool, summary, canonical_args;
    • resolved / resolved_by, with edge field tool;
    • pending_delete / pending_delete_of, with edge field version. The descendant count is computed when shown; confirming or declining removes the edge.
      "What a chat created" is a query over its messages' wrote edges.
  4. Mentions: a message's content goes through sync_mentions, so a mention is a message → node mentions edge.
  5. Participation: not embedded; excluded from default queries, search, counts and the @ picker; no inbound references.
  6. Frontend:
    • The chat viewer loads its message children.
    • A message is never shown standalone: backlinks, opening a message id, and a chat row in a page outline redirect to the chat, scrolled to the message.
    • Indent, outdent and drag aren't offered inside a chat.
    • Remove ADR-028's buffering, frontend-as-source-of-truth and soft cap.
  7. The agent loop and the cross-turn duplicate guard read and write messages and their edges.
  8. No migration: reset the database.

Architecture Impact

Implements decisions/088-ai-chat-subtypes-and-message-nodes.md §3 (nodespace-docs), which supersedes ADR-028. ADR-085's has_child-ancestry rule already keeps message nodes and their edges unsynced in Pro. Update architecture/ai-chat-node.md and components/typed-relationships.md in the same PR.

Acceptance Criteria

  • ai-chat-message is a core type with the fields above; ai-chat-native has no messages[] (tests)
  • A message can't be created without an ai-chat-native parent, can't be moved out of its chat, and can't have children (tests)
  • wrote, resolved and pending_delete edges replace completedWrites, resolvedEntities and pendingDeletions; the cross-turn duplicate guard reads canonical_args from wrote edges (tests)
  • A nodespace:// link in a message creates a message → node mentions edge (test)
  • Messages are absent from search, default queries, counts and the @ picker (tests)
  • The frontend redirects to the chat for backlinks and message ids; a chat row in an outline never unfolds messages (frontend tests)
  • ADR-028's write buffering, soft cap and frontend-as-truth code are removed
  • Prompt golden regenerated if the model-facing text changes; diff reviewed
  • Follows development/node-type-sequence.md; the node-types.md ai-chat-message and ai-chat-native sheets updated in the same PR
  • bun run test:changed passes; bun run quality:fix clean
  • ai-chat.created_nodes is removed; "what this chat created" is a query over its messages' wrote edges (test)

Technical Specifications

Reference Files

  • packages/core/src/models/core_schemas.rs, packages/nodespace-types/src/ai_chat.rs
  • packages/core/src/services/node_service/crud.rs (sync_mentions)
  • packages/agent/src/local_agent/agent_loop.rs (message persistence, completed writes, the duplicate guard)
  • packages/daemon/src/services/local_agent_service.rs
  • packages/desktop-app/src/lib/components/viewers/ai-chat-node-viewer.svelte, packages/desktop-app/src/lib/stores/ai-chats.svelte.ts, packages/desktop-app/src/lib/services/shared-node-store.svelte.ts

Dependencies

Non-Goals

  • ACP messages
  • Embedding chat summaries

Activity

  1. malibio commented on Oct 2, 2026

    @malibio
    CollaboratorAuthor

    Baseline — Frontend: 303 test files passed, 5559 tests passed

  2. self-assigned this
    on Oct 2, 2026
  3. added 2 commits that reference this issue on Oct 2, 2026
    1d00a7d
    e46433b
  4. added a commit that references this issue on Oct 2, 2026
    4e1e6a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions