Show streaming reasoning summaries in the TUI status row (#43921)

## What changed

- Update the status heading from the latest usable reasoning line and retain it through tool activity and empty reasoning items. Keep completed reasoning in the expanded transcript only.
- Restore active reasoning after resume, thread switches, and session refreshes, including when earlier events have left the replay buffer.
- Default new embedded TUI threads to `model_reasoning_summary = "detailed"`, honoring explicit summary settings. Keep `concurrent_reasoning_summaries` opt-in and disable it when summaries are `none`.
- Persist the request's captured reasoning summary setting in context updates and local and remote compaction checkpoints.
- Animate status text with a smooth, grapheme-aware shimmer that respects terminal colors and reduced motion.

## Testing

Add regression coverage for reasoning status updates, transcript visibility, resume and buffered replay, outbound summary configuration, and summary settings across all three compaction modes. Add shimmer snapshots and checks for smooth brightness changes and Unicode grapheme preservation.

GitOrigin-RevId: 725c7de20f23166d7a3da6daeca617add5cbc600
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-09-08 21:41:02 +00:00
1 parent 78932f4493
commit 9ec33e1926
45 files changed
+1798 -90

No files matched your search

@@ -69,6 +69,7 @@ async fn switching_from_ultra_thread_restores_configured_plan_effort() {
session: Some(ultra_session),
turns: Vec::new(),
events: Vec::new(),
active_reasoning_item: None,
input_state: None,
},
/*resume_restored_queue*/ false,
@@ -79,6 +80,7 @@ async fn switching_from_ultra_thread_restores_configured_plan_effort() {
session: Some(normal_session),
turns: Vec::new(),
events: Vec::new(),
active_reasoning_item: None,
input_state: None,
},
/*resume_restored_queue*/ false,
@@ -2,7 +2,10 @@
use super::*;
use crate::chatwidget::tests::helpers::normalize_snapshot_paths;
use crate::chatwidget::tests::helpers::render_bottom_popup;
use codex_app_server_protocol::ItemCompletedNotification;
use codex_app_server_protocol::ItemStartedNotification;
use codex_app_server_protocol::ReasoningSummaryTextDeltaNotification;
use pretty_assertions::assert_eq;
fn delta(thread: &str, turn: &str, item: &str) -> ServerNotification {
@@ -30,6 +33,153 @@ fn completed(thread: &str) -> ServerNotification {
})
}
#[tokio::test]
async fn refreshed_active_reasoning_accepts_later_deltas_and_complete_summary() {
for (refresh, refreshed_item_is_partial, capacity, voice_handoff) in [
(true, false, 1, false),
(true, true, 1, false),
(false, false, 8, false),
(false, false, 1, false),
(true, false, 1, true),
] {
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
let thread_id = ThreadId::new();
let session = test_thread_session(thread_id, app.config.cwd.to_path_buf());
let mut turn = test_turn("reasoning-turn", TurnStatus::InProgress, Vec::new());
let channel =
ThreadEventChannel::new_with_session(capacity, session.clone(), vec![turn.clone()]);
{
let mut store = channel.store.lock().await;
store.push_notification(ServerNotification::ItemStarted(ItemStartedNotification {
thread_id: thread_id.to_string(),
turn_id: turn.id.clone(),
item: ThreadItem::Reasoning {
id: "reasoning".into(),
summary: Vec::new(),
content: Vec::new(),
},
started_at_ms: 0,
}));
store.push_notification(ServerNotification::ReasoningSummaryTextDelta(
ReasoningSummaryTextDeltaNotification {
thread_id: thread_id.to_string(),
turn_id: turn.id.clone(),
item_id: "reasoning".into(),
delta: "**First heading**\nOriginal analysis paragraph".into(),
summary_index: 0,
},
));
assert_eq!(store.buffer.len(), capacity.min(/*other*/ 2));
if voice_handoff {
store.push_notification(ServerNotification::ItemStarted(ItemStartedNotification {
thread_id: thread_id.to_string(),
turn_id: turn.id.clone(),
item: ThreadItem::UserMessage {
id: "voice-handoff".into(),
client_id: None,
content: vec![AppServerUserInput::Text {
text: "<realtime_delegation><input>spoken follow-up</input></realtime_delegation>".into(),
text_elements: Vec::new(),
}],
},
started_at_ms: 0,
}));
}
}
let mut snapshot = channel.store.lock().await.snapshot();
app.thread_event_channels.insert(thread_id, channel);
if refreshed_item_is_partial {
turn.items.push(ThreadItem::Reasoning {
id: "reasoning".into(),
summary: vec!["**First heading**\nOriginal analysis paragraph".into()],
content: Vec::new(),
});
}
if refresh {
app.apply_refreshed_snapshot_thread(
thread_id,
AppServerStartedThread {
session,
turns: vec![turn],
blocks_direct_input: false,
task_tools_available: false,
},
&mut snapshot,
)
.await;
assert!(snapshot.events.is_empty());
}
assert!(snapshot.active_reasoning_item.is_some());
app.replay_thread_snapshot(snapshot, /*resume_restored_queue*/ false);
app.chat_widget.handle_server_notification(
ServerNotification::ReasoningSummaryTextDelta(ReasoningSummaryTextDeltaNotification {
thread_id: thread_id.to_string(),
turn_id: "reasoning-turn".into(),
item_id: "reasoning".into(),
delta: "\n**Running checks**\nFinal paragraph".into(),
summary_index: 0,
}),
/*replay_kind*/ None,
);
assert!(render_bottom_popup(&app.chat_widget, /*width*/ 80).contains("Final paragraph"));
let completed = ServerNotification::ItemCompleted(ItemCompletedNotification {
thread_id: thread_id.to_string(),
turn_id: "reasoning-turn".into(),
item: ThreadItem::Reasoning {
id: "reasoning".into(),
summary: vec![
"**First heading**\nOriginal analysis paragraph\n**Running checks**\nFinal paragraph"
.into(),
],
content: Vec::new(),
},
completed_at_ms: 0,
});
let store = &app.thread_event_channels[&thread_id].store;
store.lock().await.push_notification_ref(&completed);
assert!(
store
.lock()
.await
.snapshot()
.active_reasoning_item
.is_none()
);
app.chat_widget
.handle_server_notification(completed, /*replay_kind*/ None);
app.chat_widget.handle_server_notification(
ServerNotification::ReasoningSummaryTextDelta(ReasoningSummaryTextDeltaNotification {
thread_id: thread_id.to_string(),
turn_id: "reasoning-turn".into(),
item_id: "reasoning".into(),
delta: "\n**Stale heading**".into(),
summary_index: 0,
}),
/*replay_kind*/ None,
);
assert!(!render_bottom_popup(&app.chat_widget, /*width*/ 80).contains("Stale heading"));
let transcript = std::iter::from_fn(|| events.try_recv().ok())
.filter_map(|event| match event {
AppEvent::InsertHistoryCell(cell)
if cell
.as_any()
.is::<crate::history_cell::ReasoningSummaryCell>() =>
{
Some(lines_to_single_string(&cell.transcript_lines(/*width*/ 80)))
}
_ => None,
})
.collect::<String>();
insta::allow_duplicates! {
insta::assert_snapshot!(transcript, @"
• Original analysis paragraph
Running checks
Final paragraph
");
}
}
}
#[test]
fn buffered_replay_keeps_unfinished_and_unrelated_deltas_in_order() {
let completion = completed("thread");
@@ -43,6 +43,7 @@ async fn subagent_mcp_startup_settles_while_cached_servers_remain_deferred() {
)),
turns: Vec::new(),
events: Vec::new(),
active_reasoning_item: None,
input_state: None,
},
/*resume_restored_queue*/ false,
@@ -295,6 +295,7 @@ async fn replayed_patch_approval_pager_recovers_stored_turn_changes() {
vec![patch_item()],
)],
events: vec![ThreadBufferedEvent::Request(Box::new(request(thread_id)))],
active_reasoning_item: None,
input_state: None,
},
/*resume_restored_queue*/ false,
@@ -66,6 +66,7 @@ fn empty_thread_snapshot(app: &App, thread_id: ThreadId) -> ThreadEventSnapshot
session: Some(test_thread_session(thread_id, app.config.cwd.to_path_buf())),
turns: Vec::new(),
events: Vec::new(),
active_reasoning_item: None,
input_state: None,
}
}
@@ -558,6 +559,7 @@ async fn replay_reconciles_only_matching_voice_captions_one_for_one() {
session: Some(test_thread_session(source, app.config.cwd.to_path_buf())),
turns: vec![voice, typed],
events: Vec::new(),
active_reasoning_item: None,
input_state: None,
},
/*resume_restored_queue*/ false,
@@ -727,6 +729,7 @@ async fn buffered_voice_items_reconcile_captions_after_thread_switch() {
session: Some(test_thread_session(source, app.config.cwd.to_path_buf())),
turns: Vec::new(),
events: events_to_replay,
active_reasoning_item: None,
input_state: None,
},
/*resume_restored_queue*/ false,
@@ -827,6 +830,7 @@ async fn unrendered_buffered_items_do_not_consume_retained_captions() {
)],
),
],
active_reasoning_item: None,
input_state: None,
},
/*resume_restored_queue*/ false,
@@ -1152,6 +1156,7 @@ async fn switching_threads_retains_undelivered_voice_answer_after_replay_evictio
duration_ms: None,
}],
events: Vec::new(),
active_reasoning_item: None,
input_state: None,
},
/*resume_restored_queue*/ false,
@@ -0,0 +1,180 @@
//! Resume snapshots must accept an unfinished reasoning stream without an earlier item/started.
use super::*;
use crate::chatwidget::tests::helpers::render_bottom_popup;
use codex_app_server_protocol::ItemCompletedNotification;
use codex_app_server_protocol::ReasoningSummaryTextDeltaNotification;
#[tokio::test]
async fn resumed_reasoning_without_start_accepts_deltas_and_completion() {
for initial_replay in [false, true] {
for snapshot_item_id in [None, Some("reasoning"), Some("previous")] {
for with_delta in [false, true] {
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
let thread_id = ThreadId::new();
let session = test_thread_session(thread_id, app.config.cwd.to_path_buf());
let items = snapshot_item_id
.into_iter()
.map(|id| ThreadItem::Reasoning {
id: id.into(),
summary: vec![
if id == "previous" {
"**Earlier work**\nEarlier paragraph."
} else {
"**Inspecting**\nSnapshot paragraph."
}
.into(),
],
content: Vec::new(),
})
.collect();
let turns = vec![test_turn("turn", TurnStatus::InProgress, items)];
if initial_replay {
app.chat_widget.handle_thread_session(session);
app.chat_widget
.replay_thread_turns(turns, ReplayKind::ResumeInitialMessages);
} else {
// Reconnect constructs a fresh store; no start notification was retained.
let store =
ThreadEventStore::new_with_session(/*capacity*/ 1, session, turns);
assert!(store.active_reasoning_item.is_none());
app.replay_thread_snapshot(
store.snapshot(),
/*resume_restored_queue*/ false,
);
}
let delta = |turn_id: &str, text: &str| {
ServerNotification::ReasoningSummaryTextDelta(
ReasoningSummaryTextDeltaNotification {
thread_id: thread_id.to_string(),
turn_id: turn_id.into(),
item_id: "reasoning".into(),
delta: text.into(),
summary_index: 0,
},
)
};
app.chat_widget.handle_server_notification(
delta("old-turn", "Wrong turn"),
/*replay_kind*/ None,
);
assert!(
!render_bottom_popup(&app.chat_widget, /*width*/ 80).contains("Wrong turn")
);
if with_delta {
app.chat_widget.handle_server_notification(
delta("turn", "\n**Running checks**"),
/*replay_kind*/ None,
);
assert!(
render_bottom_popup(&app.chat_widget, /*width*/ 80)
.contains("Running checks")
);
}
app.chat_widget.handle_server_notification(
ServerNotification::ItemCompleted(ItemCompletedNotification {
thread_id: thread_id.to_string(),
turn_id: "turn".into(),
completed_at_ms: 0,
item: ThreadItem::Reasoning {
id: "reasoning".into(),
summary: vec![
"**Inspecting**\nSnapshot paragraph.\nCompleted paragraph.".into(),
],
content: Vec::new(),
},
}),
/*replay_kind*/ None,
);
app.chat_widget.handle_server_notification(
delta("turn", "Stale update"),
/*replay_kind*/ None,
);
assert!(
!render_bottom_popup(&app.chat_widget, /*width*/ 80).contains("Stale update")
);
let transcript = reasoning_transcript(&mut events);
insta::allow_duplicates! {
if snapshot_item_id == Some("previous") {
insta::assert_snapshot!(transcript, @"
• Earlier paragraph.
• Snapshot paragraph.
Completed paragraph.
");
} else {
insta::assert_snapshot!(transcript, @"
• Snapshot paragraph.
Completed paragraph.
");
}
}
}
}
}
}
#[tokio::test]
async fn resumed_trailing_reasoning_is_kept_when_no_more_reasoning_arrives() {
for next_item in [false, true] {
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
let thread_id = ThreadId::new();
let session = test_thread_session(thread_id, app.config.cwd.to_path_buf());
let store = ThreadEventStore::new_with_session(
/*capacity*/ 1,
session,
vec![test_turn(
"turn",
TurnStatus::InProgress,
vec![ThreadItem::Reasoning {
id: "finished".into(),
summary: vec!["**Inspecting**\nSaved paragraph.".into()],
content: Vec::new(),
}],
)],
);
app.replay_thread_snapshot(store.snapshot(), /*resume_restored_queue*/ false);
if next_item {
app.chat_widget.handle_server_notification(
ServerNotification::ItemStarted(
codex_app_server_protocol::ItemStartedNotification {
thread_id: thread_id.to_string(),
turn_id: "turn".into(),
started_at_ms: 0,
item: ThreadItem::Reasoning {
id: "next".into(),
summary: Vec::new(),
content: Vec::new(),
},
},
),
/*replay_kind*/ None,
);
}
app.chat_widget.handle_server_notification(
turn_completed_notification(thread_id, "turn", TurnStatus::Completed),
/*replay_kind*/ None,
);
insta::allow_duplicates! {
insta::assert_snapshot!(reasoning_transcript(&mut events), @"
• Saved paragraph.
");
}
}
}
fn reasoning_transcript(events: &mut tokio::sync::mpsc::UnboundedReceiver<AppEvent>) -> String {
std::iter::from_fn(|| events.try_recv().ok())
.filter_map(|event| match event {
AppEvent::InsertHistoryCell(cell)
if cell
.as_any()
.is::<crate::history_cell::ReasoningSummaryCell>() =>
{
Some(lines_to_single_string(&cell.transcript_lines(/*width*/ 80)))
}
_ => None,
})
.collect::<Vec<_>>()
.join("\n\n")
}
+1
View File
@@ -1520,6 +1520,7 @@ async fn ignore_same_thread_resume_allows_retrying_read_only_view() -> Result<()
session: Some(session),
turns: vec![test_turn("running", TurnStatus::InProgress, Vec::new())],
events: Vec::new(),
active_reasoning_item: None,
input_state: None,
},
/*resume_restored_queue*/ false,