Skip to content

Store AI chat messages as ai-chat-message child nodes with real edges (closes #3448) - #3491

Merged
malibio merged 2 commits into
mainfrom
issue-3448-ai-chat-message-nodes
Oct 2, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3448-ai-chat-message-nodes

Conversation

@malibio

@malibio malibio commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #3448.

Chat messages are now ai-chat-message child nodes of their ai-chat-native chat, and what a turn wrote, looked up or asked to delete is on edges from its message (ADR-088 §3). The messages[] property, its write buffering, the frontend-as-source-of-truth period and the 500-message soft cap are gone. No migration: reset the database.

The type

ai-chat-message is a concrete, flat core type (node type sequence followed).

Content the message text (a clarifying question is the content)
Fields role (user | assistant | system, default user), timestamp, reasoning, outcome (acted | clarified | replied, assistant only), options (string[])
Relationships wrote / written_by (edge field writes), resolved / resolved_by (tool), pending_delete / pending_delete_of (version); all untyped
Structure children none; parent must_have_parent_of [ai-chat-native]
Participation not embedded, not mentionable, excluded from default queries; no inbound references
Wire AiChatMessageNode, no typed update

ai-chat-native loses messages and becomes flat. The nested wire types AiChatMessage, AiChatCompletedWrite, AiChatResolvedEntity and AiChatPendingDeletion are deleted; AiChatWrite / AiChatWroteEdge / AiChatResolvedEdge / AiChatPendingDeleteEdge are the edge shapes.

Where this departs from the ADRs as they were written

Each of these is now in the docs (nodespace-docs 3b3e77a, 43a1cc9): ADR-088 §3, ADR-070, ai-chat-node.md, node-types.md, typed-relationships.md, participation.md, mentions-and-references.md.

  1. wrote holds a list. The relationship table allows one edge per (source, target, type), and a turn often writes one node twice (creates it, then links it). The edge's writes field holds each call's seq, tool, summary, canonical_args and replaced, instead of three scalar fields.
  2. An untyped relationship may target a schema node (ADR-070). The guard refused any instance edge touching a schema node, which would have left create_schema writes unrecorded. A schema node still can't be an edge's source, which is what every declaration read keys on, and a typed relationship still can't reach one.
  3. A write that leaves no node has no edge: a delete (ADR-088 already accepts this) and a conflict resolution. The reply text is the record.
  4. pending_delete stores descendant_count beside version. The issue has the count computed when shown; storing it keeps the check that a yes deletes only what the user saw.
  5. A held delete's edge is removed on any reply, not only yes/no, so a lapsed delete can't be reached later.
  6. A message's own edges may point at a chat or a message. The no-inbound-reference rule is about other nodes; without this an agent delete of a chat could be asked for and never confirmed.
  7. Mention sync runs when a single node is created with content, for every node type. Before, only a content update created mentions edges.
  8. The parent rule names ai-chat-native only; ai-chat-acp joins when it exists.

Backend

  • Registry, schema, behaviour, wire type, generated TypeScript for the new type; accepts_inbound_references in the registry replaces six is_a(AiChat) checks so the no-reference rule covers messages too.
  • get_child_edges: one read of the edges leaving a node's children. "What did this chat create?" is that read over wrote.
  • Backlinks list a message (as its own container), so a reader can open its chat at that message; a node's relationship view skips inbound groups whose source type is left out of default lists.
  • create_node_with_relationships: a node and the edges from it in one transaction.
  • Daemon (chat_messages.rs): load a conversation in two reads; append a message and its edges in one transaction. A turn is asked for by the chat's processing write, sent after the user's message is stored; a processing chat with no user message to answer is reset to idle.
  • scripts/aichat.ts and the eval snapshot follow the new shape.

Frontend

  • The chat viewer loads the chat's children and derives the conversation from the structure tree; sending creates a user message child, waits for it to be stored, then sets turn_status.
  • A message is never standalone: opening a message id or a backlink to one opens its chat scrolled to it (through a new get_parent lookup when the chat isn't loaded), and a chat row in a page outline never lists its messages.
  • ADR-028's message-count staleness guard, soft cap and buffering comments are removed.
  • The generated registry entry gains excludedFromDefaultQueries; "is this type an outline row" keys on it, not on the parent rule, so a user-defined type with a parent rule stays an ordinary row.

Dev proxy (browser mode)

Found by running the app:

  • It relayed node events but dropped relationship events, so a child created by the daemon (a chat reply) never attached to its parent until a reload. It now relays them, as the desktop listener does.
  • Its backlinks route returned bare ids where the adapter expects references.

Tests

  • Core: ai_chat_message_test.rs (fields, closed bucket, parent/children rules, edges, schema target, mentions, references, participation, cascade delete), registry and schema tests, the narrowed schema-target rule.
  • Daemon: message round trip, write grouping, the duplicate guard reading canonical_args from wrote edges, delete confirmation across turns, the trigger for both write orders.
  • Tauri seam: a real-model turn through the command layer.
  • Frontend: viewer, send path, redirects (loaded and unloaded chat), backlinks, outline, the proxy's event relay.
  • Run in the app (browser mode, isolated database, local model): two-turn chat with live replies, reload, a chat row in a page outline, opening a message id for an unloaded chat, following a message's backlink.

No model-facing text changed; the prompt goldens pass unmodified.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3491

Review Type: Initial Review

The type, schema, behaviour, wire type, generated TypeScript and docs are consistent with each other, the old messages[] shape is gone everywhere I searched, and the core rules are well tested. Each departure from the ADRs is sound and matches the amended docs (nodespace-docs 3b3e77a), with one caveat on the held-delete check (finding 4). The blocker is in the send protocol: one atomic write became two, and the frontend sends them in the opposite order to the one the viewer's comment describes.

What I ran: check-node-type-literals, check-lifecycle-reads, check-pro-boundary, types:check (all clean); core ai_chat_message_test:: and schema_relationship_declarations_test:: (33 passed); daemon chat_messages::, the watcher-order test, the duplicate-guard test and the delete-confirmation tests (12 passed); six frontend test files (41 passed). I did not run the full test:changed or the prompt goldens.

Requirements Check

# Acceptance criterion Note
1 ai-chat-message is a core type with the fields; ai-chat-native has no messages[] (tests) ✅ Registry, closed schema, behaviour, AiChatMessageNode, generated TS. ai-chat-native is now Flat and refuses messages.
2 Can't be created without an ai-chat-native parent, can't be moved out, can't have children (tests) ✅ a_message_must_sit_under_a_native_chat, a_message_cannot_leave_its_chat_or_take_children.
3 wrote / resolved / pending_delete edges replace the nested records; the duplicate guard reads canonical_args from wrote edges (tests) ✅ Tested. The record is dropped without a visible log in the cases in findings 2 and 3.
4 A nodespace:// link in a message creates a message → node mentions edge (test) ✅ a_link_in_a_message_is_a_mention_from_the_message.
5 Messages absent from search, default queries, counts and the @ picker (tests) ✅ a_message_takes_part_in_no_query_count_search_or_picker; not embedded, so absent from semantic search.
6 Frontend redirects to the chat for backlinks and message ids; a chat row in an outline never unfolds messages (frontend tests) ✅ navigation-chat-message, backlinks-panel-chat-message, base-node-viewer-chat-messages.
7 ADR-028 write buffering, soft cap and frontend-as-truth code removed ✅ No remaining reference to the old shape outside absence tests.
8 Prompt golden regenerated if model-facing text changes ✅ No prompt template changed. Not re-run by me. A confirmed delete is no longer rendered as a completed-write fact in later-turn history (the reply text stands in), which the goldens do not exercise.
9 Follows the node type sequence; node-types.md sheets updated ✅ Both sheets updated in the docs commit.
10 bun run test:changed passes; quality:fix clean ✅ Only the checkers and focused tests listed above were run by me.
11 created_nodes removed; "what this chat created" is a query over wrote edges (test) ✅ get_child_edges and its test.

Code Review Findings

🔴 Critical

1. After a cancelled turn, the next send answers the cancelled message and never answers the new one

📁 packages/desktop-app/src/lib/services/ai-chat-messages.ts:22-46, packages/desktop-app/src/lib/components/viewers/ai-chat-native-node-viewer.svelte:266-275, packages/desktop-app/src/lib/services/shared-node-store.svelte.ts:3062, packages/daemon/src/services/local_agent_service.rs:720-752

The viewer creates the message and then sets the status, but the two writes do not reach the daemon in that order:

appendUserMessage(nodeId, trimmed, VIEWER_ID);          // setNode, viewer source, new node
sharedNodeStore.updateNode(nodeId, { properties: { turn_status: 'processing' } }, ...);
// shared-node-store.svelte.ts:3062
mode: source.type === 'viewer' && isNewNode ? 'debounce' : 'immediate',
  • The message create is debounced by 500 ms (DEBOUNCE_MS).
  • The status write is a property change, which updateNode persists immediately.
  • So processing reaches the daemon about 500 ms before the user's message exists, on every send.

The daemon's two-sided trigger covers that when the last stored message is the assistant's. It does not when the last stored message is already the user's:

  • A cancelled turn resets to idle and appends nothing, so the cancelled user message stays last. A failed assistant append leaves the same state.
  • On the next send, maybe_handle_ai_chat_node sees processing and a trailing user message (the old one) and starts the turn.
  • The new message is created mid-turn. Its trigger is dropped because begin_turn returns None.
  • The reply is appended after the new message and the chat goes idle. The new message never gets a turn, and the reply shown under it answers the message the user cancelled.

Stop-then-rephrase is an ordinary flow. Before this PR the message and the status were one update, so this could not happen. The existing test the_watcher_starts_a_turn_whichever_of_the_two_writes_lands_last starts from an empty chat and does not cover it.

Same root cause, second symptom: if the message create fails (the store only raises a write-failure notification), the status write has already gone out. The chat sits in processing with no user message to answer, the composer stays disabled, and only a daemon restart resets it.

Recommendation:

  • Send the status only after the message create is confirmed: persist the create immediately and chain the status write on its promise, and skip the status write when the create fails.
  • Add a daemon test for status-first with a trailing user message already stored, and a frontend test that asserts the order of the backend calls, not the order of the store calls (the current send test mocks setNode and updateNode).
  • Cleaner alternative: node-types.md already calls turn_status daemon-owned. Let the user-message create on an idle native chat be the only trigger and have the daemon set processing itself. That removes the two-write protocol for the viewer and scripts/aichat.ts.

Principle: a request made of two non-atomic writes needs a defined order or an explicit link between them; otherwise the reader acts on a half-made request.

🟡 Important

2. A turn's edges to a chat or a message are refused, so an agent delete of a chat can never be confirmed

📁 packages/daemon/src/services/chat_messages.rs:432-443, 481-500, packages/core/src/services/node_service/relationship.rs:68-83, 834-840

wrote, resolved and pending_delete go through create_relationship, which refuses any non-has_child edge whose target does not accept inbound references. record_edge then drops the failure at debug level:

tracing::debug!(message_id, relationship, target_id, %error,
    "an ai-chat-message edge was not recorded");

Consequences when the target is an ai-chat-* node or a message:

  • Held delete. "Delete the chat called X": delete_node is held and the confirmation is shown, but the pending_delete edge is refused. On "Yes, delete", held_deletion_message finds no held delete, the reply goes to the model as an ordinary turn, the model calls delete_node again, and it is held again. The loop never ends. With pendingDeletions stored as JSON this worked.
  • Write record. A write that lands on a chat (update_node on a chat, create_relationship whose from_id is a chat) leaves no wrote edge, so the cross-turn duplicate guard has no record of it.
  • Lookup record. A looked-up chat leaves no resolved edge. an_edge_that_cannot_be_written_is_skipped asserts this as intended.

I confirmed this by reading the code path and from that existing test; I did not write a failing test for the delete loop.

Recommendation:

  • Decide the rule and state it in ADR-088 §3. Either exempt these three relationships when the source is an ai-chat-message (the edge is private to the chat and unsynced, like the message), or have the agent refuse to hold a delete it cannot record and say so, instead of asking a question whose answer cannot be recognised.
  • Add a test for "agent asked to delete a chat".

Principle: a confirmation that cannot be answered is worse than a refusal; fail at the point the invariant is known.

3. A message and its edges are separate transactions, and a lost wrote edge is logged at debug

📁 packages/daemon/src/services/chat_messages.rs:376-446, 481-500, packages/daemon/src/services/local_agent_service.rs:1358-1392

append_message is one node create, then one create_relationship per written node, per looked-up entity (up to 20) and per held delete, then the idle write. Each is its own transaction.

  • A crash or shutdown between the node create and the edges leaves a reply with no wrote edges. Recovery sees a trailing assistant message, resets to idle, and the duplicate guard has lost that turn. The comment on append_assistant_message calls those edges "the only durable evidence".
  • Any other reason an edge is refused is invisible at the default log level.
  • A read-heavy turn makes about 25 sequential write transactions and relationship events before idle.

Recommendation:

  • Write the message and its edges in one transaction (create_relationship_in_tx exists).
  • Log a refused wrote or pending_delete edge at warn. Keep debug only for the expected case of a target that no longer exists.

Principle: evidence a later step relies on should commit atomically with the thing it describes, and its loss should be visible.

4. The held-delete subtree check no longer checks anything on the chat path, and the comments still say it does

📁 packages/agent/src/local_agent/deletion_confirmation.rs:27-32, 372-405, packages/daemon/src/services/chat_messages.rs:255-270

load_messages rebuilds each PendingDeletion from preview_deletion at the start of the answering turn. execute_confirmed then compares that count with a second preview_deletion taken moments later:

Ok(Some(now)) if now.descendant_count != target.descendant_count => { /* "changed after you were asked" */ }
  • The comparison is between two fresh reads, so it cannot detect a change since the question.
  • The count the user saw is baked into the question text. Nodes added under the target between the question and the yes are deleted unseen.
  • The issue asks for the count to be computed when shown, so the behaviour is as specified. The doc comments on PendingDeletion ("A change to either ... aborts the delete") and on execute_confirmed ("a version or subtree size that differs from what the user was shown") are no longer true for this caller. The gRPC confirmed_delete caller still passes a real expected count.

Recommendation: either store descendant_count as a second declared edge field on pending_delete, which restores the guarantee, or correct the two comments and state the weaker guarantee in ADR-088 §3.

Principle: a destructive action should remove only what the user confirmed; comments must not claim a check the code no longer makes.

🟢 Suggestions

5. isOwnedByParentViewer is keyed on excludedFromDefaultQueries alone

📁 packages/desktop-app/src/lib/types/core-node-types.ts:172-186, packages/desktop-app/src/lib/components/layout/pane-content.svelte:89-106, 140-147

A participation flag ("left out of lists") is used to mean "never a page of its own". A future core type that is excluded from default queries but is a root would never hydrate, and its tab would be closed by retargetTabToParent. Require both the flag and a must_have_parent_of parent rule, or add a dedicated registry flag. Principle: one flag, one meaning.

6. last_message_role loads every child of the chat, with content, to read one role

📁 packages/daemon/src/services/chat_messages.rs:185-208, packages/daemon/src/services/local_agent_service.rs:685-702, 756-764

It runs on every native-chat and message event, three or more times per turn, plus load_messages and the title read. This is no worse than rewriting messages[] was, so it does not block. A store read of the last message child would make the trigger constant-cost.

7. Mention sync on create covers two of the create paths

📁 packages/core/src/services/node_service/crud.rs:437, 454-467, 746

sync_created_mentions runs from create_node and create_node_with_parent. Markdown import (bulk_create_hierarchy) and a Play's create (insert_node_in_tx_no_invariant_dispatch) still create no mentions edges. The PR description and ADR-088 §3 read as if every create syncs. Extend it or narrow the wording.

Nitpicks

  • Nit: components/node-types.md lists a message's content as Markdown, while AiChatMessageNodeBehavior::supports_markdown() returns false.
  • Nit: packages/core/src/db/schema.rs:82-88 still says declarations and instance edges are told apart by "endpoint node_type"; after the ADR-070 amendment it is the source that tells them apart.
  • Nit: the_watcher_starts_a_turn_whichever_of_the_two_writes_lands_last relies on fixed sleeps (100 ms to subscribe, 300 ms for the status-first case) and may be load-sensitive in the merge gate.

Recommendation

REQUEST CHANGES

Finding 1 must be fixed before merge. Findings 2 to 4 are small and same-shaped, so they are worth folding into this PR. The rest is optional.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (30d1952e)

Addressed

  1. 🔴 Send order. The viewer stores the user's message (flushNodeSaves) and only then writes turn_status: processing; if the create fails, no turn is requested and the error is shown. The daemon triggers on the status write alone (the message-create trigger is removed), claims the chat before reading its messages, and puts a processing chat with no user message to answer back to idle. Tests: backend call order and the failed-create case in ai-chat-native-viewer-messages.test.ts; a_send_after_a_cancelled_turn_answers_the_new_message, a_turn_request_with_no_user_message_resets_to_idle, storing_a_user_message_alone_starts_no_turn in the daemon.
  2. 🟡 Edges to a chat or a message. A declared relationship whose source is itself a chat or a message may target one, so an agent delete of a chat is held and confirmed (a_yes_to_deleting_a_chat_deletes_it, a_messages_own_edges_may_point_at_a_chat_or_a_message). A mention still creates no edge. Stated in ADR-088 §3.
  3. 🟡 Atomicity. NodeService::create_node_with_relationships creates the message and its edges in one transaction; an edge to a node that no longer exists is left out. If the transaction fails the message is stored alone and the loss is logged at warn (a_message_is_created_with_its_edges_in_one_write).
  4. 🟡 Held-delete check. Took the first option: pending_delete stores descendant_count beside version, so a yes is checked against what the user was shown and the existing comments are true again (a_yes_does_not_delete_a_node_that_gained_children_since_the_question). This reverses the issue's "count computed when shown"; ADR-088 §3 and the node-type sheet say so.
  5. 🟢 isOwnedByParentViewer requires both the list flag and a must_have_parent_of parent rule.
  6. 🟢 Mention sync on create: the doc comment, ADR-088 and mentions-and-references.md now say single-node creates; a markdown import links in bulk.
  • Nits: node-types.md content wording, the schema.rs table comment, and the sleep-based ordering test is gone with the trigger it tested (the one remaining watcher test asserts that nothing happens, so a slow machine cannot fail it).

Skipped

  1. 🟢 A last-message-only store read. No worse than before this PR, and with the message trigger removed it runs once per status write. Worth doing if chats grow long enough to measure.

Docs: nodespace-docs 43a1cc9. bun run test:changed passes (frontend, scripts, browser, Rust).

@malibio

malibio commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3491 (re-review of 30d1952e)

Review Type: Re-review. Scope is git diff b60632b6..30d1952e and nodespace-docs 43a1cc9.

The blocker is fixed, and the three important findings are fixed in code with tests. I found no new blocker. Three small things the fixes introduced are listed as suggestions.

What I ran on 30d1952e: core ai_chat_message_test:: and ai_chat_subtypes_test:: (33 passed); daemon chat_messages:: and local_agent_service:: (101 passed); frontend ai-chat-native-viewer-messages, core-node-types, navigation-chat-message (35 passed); types:check and check-node-type-literals (clean). I did not run the full test:changed or the prompt goldens.

Previous Review Summary

# Previous finding Status What I verified
1 🔴 Send order: the status write reached the daemon before the message ✅ Addressed The viewer awaits flushNodeSaves([messageId]) before the status write and skips the status write on failure. The daemon triggers on the chat's status write only. a_send_after_a_cancelled_turn_answers_the_new_message and the backend-call-order test cover it.
2 🟡 Edges to a chat or message refused; a chat delete could never be confirmed ✅ Addressed write_relationship_in_tx allows the target when the source is itself a chat or message. a_yes_to_deleting_a_chat_deletes_it, a_held_delete_of_a_chat_is_recorded. Scope note in new finding A.
3 🟡 Message and edges not atomic; lost edge logged at debug ✅ Addressed create_node_with_relationships is one transaction; a missing target is skipped by index; any other failure rolls back. The fallback logs at warn. Note in new finding C.
4 🟡 Held-delete subtree check was vacuous ✅ Addressed descendant_count is a declared, required edge field on pending_delete, on the wire type and in the generated TS; load_messages reads it from the edge. a_yes_does_not_delete_a_node_that_gained_children_since_the_question.
5 🟢 isOwnedByParentViewer keyed on one flag ✅ Addressed Now requires the list flag and !canBeRoot.
6 🟢 last_message_role loads every child ⏭ Skipped, accepted It now runs once per chat status write, not per message event. Fine to leave.
7 🟢 Mention sync wording ✅ Addressed Doc comment and docs now say single-node creates.
Nits sheet wording, schema.rs comment, sleep-based test ✅ Addressed The remaining watcher test asserts that nothing happens, so load cannot fail it.

Requirements Check

Unchanged from the initial review: all eleven acceptance criteria are met. One criterion's wording has moved: the issue says the descendant count is "computed when shown", and it is now stored on the edge. ADR-088 §3 and the ai-chat-message sheet record that, and it is the stronger guarantee.

Checks on the areas you asked about

  • (a) Viewer send. Order is correct and tested against the backend calls. isSending covers the model check and the flush, and disables the composer and the option chips. See finding B for the failed-create path.
  • (b) Daemon claim-then-reset. I found no path where the reset fires wrongly:
    • Running turn: the token is held until after the idle write, so a concurrent event gets None from begin_turn and returns.
    • Between the reply's create and its idle write: same token, same result.
    • Recovery: recover_stuck_turns claims before the watcher subscribes, and applies the same rule.
    • Second window or client: any client that stores its message before the status write is handled the same way; one that writes the status first gets a usable idle chat and a warn, not a stuck one.
    • One theoretical gap: the status is read before the claim, so a stale processing read could claim just after a turn ends. The window is a mutex acquisition wide, and the outcome is a redundant idle write. Re-reading the status after begin_turn would close it.
  • (c) create_node_with_relationships. Atomic through with_transaction; embedding queue and mention sync run after commit, as create_placed_node does. See finding C for the fallback.
  • (d) Reference-rule exemption. The non-transactional builtin path and create_mention still refuse. See finding A for the transactional path.
  • (e) descendant_count. Declared, typed, generated, stored and compared. Correct.

Code Review Findings

No critical or important findings.

🟢 Suggestions

A. The exemption also covers builtin relationships on the transactional path

📁 packages/core/src/services/node_service/relationship.rs:1189-1215

Self::refuse_ai_chat_target(relationship_name, &target, accepts_references || from_inside)?;
  • from_inside is not gated on the relationship being declared, so a mentions or has_role edge from a chat or message to a chat or message passes when it comes through create_relationship_in_tx (a Play's add_relationship action is the caller I can see).
  • The doc comment on refuse_ai_chat_target says "A mentions edge never is".
  • I did not confirm that a Play action can name a builtin, so reachability is unverified.

Recommendation: compute from_inside only when !is_builtin, and add one assertion to a_messages_own_edges_may_point_at_a_chat_or_a_message. Computing it only when the target is unreferenceable also removes a second source read from every declared relationship write. Principle: an exemption should be exactly as wide as its stated rule.

B. A failed send leaves the optimistic message in the conversation

📁 packages/desktop-app/src/lib/components/viewers/ai-chat-native-node-viewer.svelte:285-291

const failed = await sharedNodeStore.flushNodeSaves([messageId]);
if (failed.has(messageId)) {
  sendError = 'The message could not be saved, so it was not sent.';
  return;
}
  • The optimistic node and its structure-tree entry stay. The transcript shows a user message that is not stored, and hasMessages locks the model selector on it. It disappears on reload.
  • flushNodeSaves also reports a 5-second timeout as a failure. In that case the create may still land, so "could not be saved" can be untrue and the chat ends with a stored user message and no turn. The daemon side is safe either way.
  • The test for this path asserts the alert and the absent status write, not what the transcript shows.

Recommendation: on failure remove the optimistic node (or mark it failed) and put the text back in the composer; word the timeout case separately. Principle: optimistic UI should roll back when the write it anticipated fails.

C. The fallback drops every record when one edge is invalid

📁 packages/daemon/src/services/chat_messages.rs:414-441

  • Any edge failure other than a missing target rolls back the transaction, and the message is then stored with no edges at all.
  • That loses the turn's wrote records (the duplicate guard) and its pending_delete edges. A confirmation question stored this way cannot be answered, which is the loop from the earlier finding 2, now logged at warn.
  • I know of no input that triggers it today; it needs a refused edge that is not a missing target.

Recommendation: when the fallback runs for a message that held deletes, replace the question with a notice that the delete could not be held. Optional. Principle: degrade to a state the user can act on.

Recommendation

APPROVE

The suggestions are optional and none needs a further review round.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed

  • A ✅ The inside-a-chat exemption applies to a declared relationship only, never a builtin one, and the source is read only when the target would be refused. a_messages_own_edges_may_point_at_a_chat_or_a_message now asserts a mention is still refused.
  • B ✅ A message that could not be stored is removed from the conversation (discardUnsentMessage); the failed-send test asserts the transcript and the structure tree are empty. The composer text is not restored.
  • C ⏭️ Skipped: replacing a delete question whose edges could not be stored. No known input reaches that fallback, and it is logged at warn.
  • The status re-read after the claim is also left: the outcome of that window is one redundant idle write.

bun run test:changed passes. No re-review needed: both changes are small, covered by tests, and narrow behaviour the review already approved.

@malibio
malibio force-pushed the issue-3448-ai-chat-message-nodes branch from 56e5c54 to cc54fe2 Compare October 2, 2026 12:52
malibio and others added 2 commits October 2, 2026 14:57
…closes #3448)

A chat's messages are ai-chat-message children of its ai-chat-native node,
and what a turn wrote, looked up or asked to delete is on wrote, resolved and
pending_delete edges from its message (ADR-088 §3). The messages[] property,
its write buffering and the soft cap are removed.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-3448-ai-chat-message-nodes branch from cc54fe2 to 15bed7d Compare October 2, 2026 12:57
@malibio
malibio merged commit 4e1e6a4 into main Oct 2, 2026
@malibio
malibio deleted the issue-3448-ai-chat-message-nodes branch October 2, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant