tui: one send answered twice — the same user message is persisted bare and again with <turn_meta>, so every save re-branches
Summary
One user send can run two engine turns and produce two different assistant replies. The journal shows why: the same user text is persisted twice, in two different shapes — once as bare text, once with a <turn_meta> tail — as sibling entries under the same parent. Because the save path compares the persisted branch with the live transcript by strict Message equality, a bare copy and a <turn_meta> copy of the same text never match, and each save re-branches the journal instead of appending to it.
This is deterministic. It needs no token threshold, no wall clock and no resume, which is what distinguishes it from the re-root trigger left unestablished in #7142.
Impact
- One send is answered twice. The two replies are not a re-render: their texts differ (measured similarity 0.154; 1103 and 234 characters).
- The persisted active path drops earlier assistant turns. In one session document, 1231 journal entries backed an active path of only 53 entries, and every historical assistant reply was off-path; the only on-path assistant entries were the tool steps of the turn in flight.
- Resuming such a session replays user turns without their answers. The record still contains everything — the leaf simply does not reach it.
Evidence
Sanitized from one session document on Windows 11 with a 0.10.x build. No third-party tooling is involved and no session content is reproduced here.
Timeline for a single send, offsets from the first write of that message:
t0 user bare text of the message
t0+0.06 user (injected server instructions)
t0+0.11 user (injected server configuration)
t0+7.7 assistant reply A, 1103 chars
t0+7.7 user the same message text again, bare, appended after reply A
t0+9.8 user the same message text with a <turn_meta> tail
t0+14.5 assistant reply B, 234 chars, parented to the <turn_meta> copy
Census over the whole document:
- 83 groups of byte-identical entries: 21
user, 62assistant. - 10 pairs of sibling entries whose only difference is the presence of a
<turn_meta>tail — same parent, written 1.2–2.1 s apart. - One message appears 4 times, two of those writes 0.5 µs apart and chained as parent/child, so a single append loop wrote both.
Mechanism
Both sides persist the same user text, but not the same Message:
-
crates/tui/src/tui/ui/dispatch.rs—prepare_user_dispatchpushes the bare text intoapp.api_messagesand immediately saves a checkpoint built from it. -
crates/tui/src/core/engine/turn_loop/preparation.rs— the engine pushesuser_text_message_with_turn_metadata(...), so its copy of the same text carries the<turn_meta>tail. -
crates/tui/src/tui/ui/event_loop.rs—apply_engine_session_projectionmirrors the engine copy back throughapp.set_api_messages(...). -
crates/tui/src/tui/ui/frame.rs—build_session_snapshotre-branches the journal ontoapp.api_messages. -
crates/runtime/src/session_tree.rs—rebranch_active_messages_stampedcomputeslet shared_prefix = active_path .iter() .zip(messages) .take_while(|(entry, message)| entry.kind.projects_to(message)) .count();and for a
Messageentryprojects_tois exact equality:Self::Message { message: own } => own == message,
A bare copy and a <turn_meta> copy of one text are therefore never equal. The shared prefix stops at the first entry whose shape flipped, leaf_id moves back to that entry's parent, and the remainder of the transcript is appended as a sibling branch. The previous copy stays behind as evidence, so the same message is now persisted twice and the leaf sits on the newer one.
The result is visible downstream: set_api_messages already detects this discontinuity with
if unchanged == 0 && !self.api_messages.is_empty() && !messages.is_empty() {
self.window_reroot_cause = Some("engine_projection");
}
but only after the fact. Nothing prevents the second turn, and nothing reconciles the two shapes.
Relationship to existing reports
- #7142 describes the same visible degradation — a live window re-rooted mid-session, earlier turns unreachable, no seam summary, no lifecycle event — and explicitly leaves the trigger unestablished. This report supplies a deterministic trigger plus a second, independent symptom: one send answered twice.
- #6367 (closed) is the same save path discarding branch structure.
- #6842 concerns the same machinery from the memory-growth side, not model visibility.
- #7095 is a different fault: there the last save does not flush, so the record itself is missing.
Suggested fix
Two candidate shapes, in order of preference:
- One shape from the start. Do not let
app.api_messagescarry a user message the engine will rewrite. Either the TUI composes the sameMessagethe engine will store, or the engine stops adding a tail to the copy it persists and instead adds<turn_meta>only at request construction — the copy on disk should not differ from the copy on screen. - Shape-insensitive comparison, narrowly scoped. Keep both writes but make the re-branch comparison treat a message and the same message with its
<turn_meta>tail as one entry. This is the smaller compile surface but leaves two shapes on disk for every later reader to reconcile.
Independently of either: a user send must not start a second turn when the transcript already contains that text at the leaf.
What I have not established
- Whether the double turn bills a provider request twice. The replies differ, so a model call did happen twice; the cost detail is not measured.
- Whether every shape flip re-branches the whole history or only the tail. Entry counts suggest tail-only in most saves and whole-path in some; I have not isolated which condition selects each.
- Whether the flip alone accounts for every observed re-root, or only some of them. It is sufficient to produce one, not proved to be the only cause.
- No fix is claimed or proposed as tested here.
Reproduction and evidence are kept locally. I am happy to provide a sanitised session document or run any probe a maintainer asks for.
署名
🤖 由 SpikeBot 000(CodeWhale-LOCAL) 生成
Thank you @SparkofSpike for the journal census, for tracing this to the strict message comparison in the save path, and for #7180. Commit db2c8d03097 on main compares saved and live messages with the <turn_meta> block stripped, so a bare copy and a stamped copy of the same text no longer split the history into branches. Commit c80c16c14aa (from your #7180) also keeps stamped turns and shared journal ancestors intact. We checked this on macOS: two sends produced two provider requests, and both answers stayed on the active path. We have not reproduced your Windows session. This is on main but not in a published release yet, so the issue stays open until 0.10.3 ships. After that, please tell us whether saves now stay on one path, and especially whether a single send still ever produces two replies.
Written by Claude Opus 5.5 for the Codewhale maintainers.
Thank you @SparkofSpike for the journal census that traced the re-branching to strict message comparison, and for #7180. The fixes shipped in v0.10.3 (db2c8d0309, and c80c16c14a from your PR), so a bare copy and a <turn_meta> copy of the same text no longer split the history. We have not reproduced the Windows session where one send produced two replies, so we are keeping this open for that part. After npm install -g [email protected], could you tell us whether a single send still ever gets two answers?
Fixed after #7180 landed. Closing this.