Preserve voice caption order when replaying TUI history (#44749)

## Why

Retained voice captions were appended after replayed history, placing earlier speech after later typed turns when switching back to a thread.

## What changed

Anchor completed captions to the next live turn and restore them before that turn during replay. Handle buffered item, delta, and completion events even when the turn-start event has been evicted. Restore remaining captions at the end of replay.

## Testing

Extend regression coverage to verify caption order and avoid duplicates across repeated thread switches. Add coverage for inactive-thread captions replayed before a later buffered turn without its start event, with and without a message delta.

GitOrigin-RevId: 6860a649bdcdda4937afb3ab4bbd75cf4ea5b4e6
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-09-11 06:56:37 +00:00
1 parent eab107fed0
commit ab95cd4dd9
9 files changed
+220 -14

No files matched your search

+6 -2
View File
@@ -1545,6 +1545,8 @@ impl App {
let should_buffer_initial_replay = !turns.is_empty();
let replayed_final_items = realtime_delivery::completed_agent_items_from_turns(&turns);
let replayed_voice_texts = realtime_delivery::replayed_voice_texts_from_turns(&turns);
let retained_assistant_captions =
self.prepare_realtime_transcript_replay(replayed_voice_texts);
if should_buffer_initial_replay {
self.app_event_tx
.send(AppEvent::BeginInitialHistoryReplayBuffer);
@@ -1562,7 +1564,7 @@ impl App {
}
self.restore_realtime_replay_state_after_replay(
&replayed_final_items,
replayed_voice_texts,
retained_assistant_captions,
);
if matches!(presentation, ThreadAttachPresentation::PromptEdit) {
self.chat_widget.emit_prompt_edit_thread_event();
@@ -1824,6 +1826,8 @@ impl App {
self.chat_widget.handle_thread_session(session);
}
}
let retained_assistant_captions =
self.prepare_realtime_transcript_replay(replayed_voice_texts);
for turn_id in &snapshot.delegated_turns {
self.chat_widget
.remember_realtime_delegated_reasoning_turn(turn_id);
@@ -1866,7 +1870,7 @@ impl App {
}
self.restore_realtime_replay_state_after_replay(
&replayed_final_items,
replayed_voice_texts,
retained_assistant_captions,
);
self.chat_widget
.set_queue_autosend_suppressed(/*suppressed*/ false);