Improve automatic thread naming in the TUI (#42749)

## Why

Automatic title generation used a provisional thread name and only applied the
generated result while its thread remained active. Switching threads could
therefore leave the originating thread without its generated name.

## What changed

- Track title-generation requests by thread so results are persisted for the
  originating thread, while preserving any name set before generation finishes.
- Show a `renaming...` spinner instead of a provisional name, including across
  thread switches and failure paths.
- Add `thread-name` items to the status line and terminal title, and include the
  generated thread name in both default layouts.

## Testing

- Cover automatic naming, manual-name precedence, thread switching, failed
  requests, deduplication, and status-surface rendering and animation.

GitOrigin-RevId: a03ae4849bedec9f62f256fadad72c1685ce46e0
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-09-04 12:20:57 +00:00
1 parent 8e85265c39
commit a1294e57f1
32 files changed
+642 -181

No files matched your search

+37 -29
View File
@@ -1735,12 +1735,14 @@ async fn live_app_server_invalid_thread_name_update_is_ignored() {
}
#[tokio::test]
async fn live_app_server_thread_name_update_shows_resume_hint() {
async fn live_app_server_manual_thread_name_updates_status_surfaces() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let thread_id =
ThreadId::from_string("123e4567-e89b-12d3-a456-426614174000").expect("thread id");
chat.thread_id = Some(thread_id);
chat.expect_manual_thread_name(thread_id, "review-fix".to_string());
chat.handle_server_notification(
ServerNotification::ThreadNameUpdated(
codex_app_server_protocol::ThreadNameUpdatedNotification {
@@ -1753,46 +1755,53 @@ async fn live_app_server_thread_name_update_shows_resume_hint() {
assert_eq!(chat.thread_name, Some("review-fix".to_string()));
let cells = drain_insert_history(&mut rx);
assert_eq!(cells.len(), 1);
let rendered = lines_to_single_string(&cells[0]);
assert_chatwidget_snapshot!("thread_name_update_resume_hint", rendered);
let transcript = cells
.iter()
.map(|lines| lines_to_single_string(lines))
.collect::<String>();
let footer = render_bottom_popup(&chat, /*width*/ 80);
let title = chat.last_terminal_title.as_deref().unwrap();
assert_chatwidget_snapshot!(
"manual_thread_name_status_surfaces",
normalize_snapshot_paths(format!(
"transcript:\n{transcript}\nfooter:\n{footer}\ntitle: {title}"
))
);
}
#[tokio::test]
async fn live_app_server_automatic_thread_name_update_is_silent() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let thread_id = ThreadId::new();
chat.thread_id = Some(thread_id);
for title in ["Provisional title", "Generated title"] {
chat.expect_automatic_thread_name(title.to_string());
assert_eq!(chat.thread_name(), Some(title.to_string()));
for replay_kind in [
None,
Some(ReplayKind::ThreadSnapshot),
Some(ReplayKind::ResumeInitialMessages),
] {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let thread_id = ThreadId::new();
let mut session = configured_thread_session(thread_id);
session.thread_name = Some("Generated title".to_string());
chat.handle_thread_session(session);
drain_insert_history(&mut rx);
chat.handle_server_notification(
ServerNotification::ThreadNameUpdated(
codex_app_server_protocol::ThreadNameUpdatedNotification {
thread_id: thread_id.to_string(),
thread_name: Some(title.to_string()),
thread_name: Some("Generated title".to_string()),
},
),
/*replay_kind*/ None,
replay_kind,
);
assert_eq!(chat.thread_name, Some(title.to_string()));
assert!(drain_insert_history(&mut rx).is_empty());
assert_eq!(chat.thread_name(), Some("Generated title".to_string()));
let transcript = drain_insert_history(&mut rx)
.iter()
.map(|lines| lines_to_single_string(lines))
.collect::<String>();
insta::allow_duplicates! {
assert_snapshot!(transcript, @"");
}
}
chat.handle_server_notification(
ServerNotification::ThreadNameUpdated(
codex_app_server_protocol::ThreadNameUpdatedNotification {
thread_id: thread_id.to_string(),
thread_name: Some("Manual title".to_string()),
},
),
/*replay_kind*/ None,
);
assert_eq!(chat.thread_name, Some("Manual title".to_string()));
assert_eq!(drain_insert_history(&mut rx).len(), 1);
}
#[tokio::test]
@@ -1800,7 +1809,6 @@ async fn live_app_server_manual_thread_name_is_visible_before_notification() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let thread_id = ThreadId::new();
chat.thread_id = Some(thread_id);
chat.expect_automatic_thread_name("Provisional title".to_string());
chat.expect_manual_thread_name(thread_id, "Manual title".to_string());
@@ -1818,7 +1826,7 @@ async fn live_app_server_manual_thread_name_is_visible_before_notification() {
);
assert_eq!(chat.thread_name(), Some("Manual title".to_string()));
assert_eq!(drain_insert_history(&mut rx).len(), 1);
assert!(drain_insert_history(&mut rx).is_empty());
}
#[tokio::test]