mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
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:
1 parent
eab107fed0
commit
ab95cd4dd9
9 files changed
+220
-14
No files matched your search
@@ -588,6 +588,7 @@ async fn replay_reconciles_only_matching_voice_captions_one_for_one() {
|
||||
role: role.to_string(),
|
||||
text: text.to_string(),
|
||||
complete: true,
|
||||
before_turn_id: None,
|
||||
})
|
||||
.collect();
|
||||
app.pending_realtime_transcript_replay
|
||||
@@ -660,6 +661,7 @@ async fn retained_caption_consumes_only_one_matching_answer_fallback_on_reattach
|
||||
role: "assistant".into(),
|
||||
text: "Same answer".into(),
|
||||
complete: true,
|
||||
before_turn_id: None,
|
||||
}]
|
||||
.into(),
|
||||
);
|
||||
@@ -755,6 +757,7 @@ async fn buffered_voice_items_reconcile_captions_after_thread_switch() {
|
||||
role: role.to_string(),
|
||||
text: text.to_string(),
|
||||
complete: true,
|
||||
before_turn_id: None,
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
@@ -834,6 +837,7 @@ async fn unrendered_buffered_items_do_not_consume_retained_captions() {
|
||||
role: role.to_string(),
|
||||
text: text.to_string(),
|
||||
complete: true,
|
||||
before_turn_id: None,
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
@@ -948,6 +952,16 @@ async fn completed_voice_caption_survives_repeated_thread_replacement() {
|
||||
.collect::<String>();
|
||||
assert_eq!(initial.matches("spoken complete").count(), 1);
|
||||
|
||||
let typed = test_turn(
|
||||
"later-typed-turn",
|
||||
TurnStatus::Completed,
|
||||
vec![test_user_message("later-user", "Later typed question")],
|
||||
);
|
||||
app.chat_widget.handle_server_notification(
|
||||
turn_started_notification(source, &typed.id),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
|
||||
for cycle in 0..2 {
|
||||
let side = ThreadId::new();
|
||||
let (side_widget, _, mut side_events, _) = make_chatwidget_manual_with_sender().await;
|
||||
@@ -969,10 +983,14 @@ async fn completed_voice_caption_survives_repeated_thread_replacement() {
|
||||
let (source_widget, _, mut source_events, _) = make_chatwidget_manual_with_sender().await;
|
||||
app.active_thread_id = Some(source);
|
||||
app.replace_chat_widget(source_widget);
|
||||
app.replay_thread_snapshot(
|
||||
empty_thread_snapshot(&app, source),
|
||||
/*resume_restored_queue*/ false,
|
||||
);
|
||||
let mut snapshot = empty_thread_snapshot(&app, source);
|
||||
snapshot.turns.push(Turn {
|
||||
id: "earlier-typed-turn".into(),
|
||||
items: vec![test_agent_message("earlier-answer", "Earlier answer")],
|
||||
..typed.clone()
|
||||
});
|
||||
snapshot.turns.push(typed.clone());
|
||||
app.replay_thread_snapshot(snapshot, /*resume_restored_queue*/ false);
|
||||
assert!(!app.pending_realtime_transcript_replay.contains_key(&source));
|
||||
let rendered = std::iter::from_fn(|| source_events.try_recv().ok())
|
||||
.filter_map(|event| match event {
|
||||
@@ -988,6 +1006,13 @@ async fn completed_voice_caption_survives_repeated_thread_replacement() {
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
assert_eq!(rendered.matches("spoken complete").count(), 1);
|
||||
assert!(
|
||||
rendered.find("Earlier answer").unwrap() < rendered.find("spoken complete").unwrap()
|
||||
);
|
||||
assert!(
|
||||
rendered.find("spoken complete").unwrap()
|
||||
< rendered.find("Later typed question").unwrap()
|
||||
);
|
||||
if cycle == 0 {
|
||||
insta::assert_snapshot!(
|
||||
"voice_completed_after_thread_switch",
|
||||
@@ -997,6 +1022,78 @@ async fn completed_voice_caption_survives_repeated_thread_replacement() {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn inactive_caption_precedes_later_buffered_turn_without_start_event() {
|
||||
for include_delta in [false, true] {
|
||||
let (mut app, _initial_events, _ops) = make_test_app_with_channels().await;
|
||||
let source = ThreadId::new();
|
||||
app.retain_inactive_realtime_transcript(
|
||||
source,
|
||||
&ServerNotification::ThreadRealtimeTranscriptDone(
|
||||
codex_app_server_protocol::ThreadRealtimeTranscriptDoneNotification {
|
||||
thread_id: source.to_string(),
|
||||
role: "assistant".into(),
|
||||
text: "Earlier spoken answer".into(),
|
||||
},
|
||||
),
|
||||
);
|
||||
app.retain_inactive_realtime_transcript(
|
||||
source,
|
||||
&turn_started_notification(source, "later-turn"),
|
||||
);
|
||||
let (widget, _, mut events, _) = make_chatwidget_manual_with_sender().await;
|
||||
app.active_thread_id = Some(source);
|
||||
app.replace_chat_widget(widget);
|
||||
let mut snapshot = empty_thread_snapshot(&app, source);
|
||||
if include_delta {
|
||||
snapshot
|
||||
.events
|
||||
.push(ThreadBufferedEvent::Notification(Box::new(
|
||||
ServerNotification::AgentMessageDelta(
|
||||
codex_app_server_protocol::AgentMessageDeltaNotification {
|
||||
thread_id: source.to_string(),
|
||||
turn_id: "later-turn".into(),
|
||||
item_id: "later-answer".into(),
|
||||
delta: "Later typed question".into(),
|
||||
},
|
||||
),
|
||||
)));
|
||||
}
|
||||
// The bounded replay buffer may have evicted both the start and item notifications.
|
||||
snapshot
|
||||
.events
|
||||
.push(ThreadBufferedEvent::Notification(Box::new(
|
||||
ServerNotification::TurnCompleted(TurnCompletedNotification {
|
||||
thread_id: source.to_string(),
|
||||
turn: test_turn(
|
||||
"later-turn",
|
||||
TurnStatus::Completed,
|
||||
vec![test_agent_message("later-answer", "Later typed question")],
|
||||
),
|
||||
}),
|
||||
)));
|
||||
app.replay_thread_snapshot(snapshot, /*resume_restored_queue*/ false);
|
||||
let rendered = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.filter_map(|event| match event {
|
||||
AppEvent::InsertHistoryCell(cell) => Some(
|
||||
cell.transcript_lines(/*width*/ 80)
|
||||
.into_iter()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
assert_eq!(rendered.matches("Earlier spoken answer").count(), 1);
|
||||
assert!(
|
||||
rendered.find("Earlier spoken answer").unwrap()
|
||||
< rendered.find("Later typed question").unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn rejected_realtime_speech_restores_the_delegated_final_answer() -> Result<()> {
|
||||
let (mut app, mut events, mut ops) = make_test_app_with_channels().await;
|
||||
|
||||
Reference in new issue
Block a user