Generate descriptive TUI thread titles (#40492)

## What changed

- Give unnamed TUI threads an immediate provisional title from the first user message, then replace it asynchronously with a normalized generated title.
- Preserve manual renames by applying a generated title only while the provisional title is still current, and keep automatic rename notifications out of the transcript.
- Run title generation in a bounded ephemeral structured request that preserves custom permission profiles, otherwise uses read-only access, and disables tools and MCP servers.

## Testing

- Cover prompt and response bounds, Unicode-safe truncation, title normalization, manual-rename races, silent automatic updates, permission preservation, and structured-response failures.

GitOrigin-RevId: 7ed73522f4f6c65a005f65f3a903974d8419e312
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-08-24 23:06:06 +00:00
1 parent c941572917
commit b3c7e1a47f
18 files changed
+1032 -12

No files matched your search

@@ -199,6 +199,7 @@ impl ChatWidget {
pet_image_support_override: None,
thread_id: None,
thread_name: None,
pending_automatic_thread_names: HashSet::new(),
thread_rename_block_message: None,
active_side_conversation: false,
blocks_direct_input: false,
+24 -1
View File
@@ -25,6 +25,7 @@ impl ChatWidget {
self.bottom_pane
.set_queue_submissions(/*queue_submissions*/ false);
if previous_thread_id != self.thread_id {
self.pending_automatic_thread_names.clear();
self.review.recent_auto_review_denials = RecentAutoReviewDenials::default();
self.clear_thread_usage_state();
}
@@ -245,16 +246,38 @@ impl ChatWidget {
)));
}
/// Apply a persisted automatic name immediately and suppress its confirmation.
pub(crate) fn expect_automatic_thread_name(&mut self, name: String) {
self.thread_name = Some(name.clone());
self.pending_automatic_thread_names.insert(name);
}
/// Make a confirmed manual rename visible before its queued server notification arrives.
pub(crate) fn expect_manual_thread_name(&mut self, thread_id: ThreadId, name: String) {
if self.thread_id == Some(thread_id) {
self.thread_name = Some(name);
self.refresh_status_surfaces();
self.request_redraw();
}
}
pub(super) fn on_thread_name_updated(
&mut self,
thread_id: ThreadId,
thread_name: Option<String>,
) {
if self.thread_id == Some(thread_id) {
if let Some(name) = thread_name.as_deref() {
let automatic = thread_name
.as_ref()
.is_some_and(|name| self.pending_automatic_thread_names.remove(name));
if let Some(name) = thread_name.as_deref()
&& !automatic
{
let cell = Self::rename_confirmation_cell(name, self.thread_id);
self.add_boxed_history(Box::new(cell));
}
self.thread_name = thread_name;
self.refresh_status_surfaces();
self.request_redraw();
@@ -1558,6 +1558,69 @@ async fn live_app_server_thread_name_update_shows_resume_hint() {
assert_chatwidget_snapshot!("thread_name_update_resume_hint", rendered);
}
#[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()));
chat.handle_server_notification(
ServerNotification::ThreadNameUpdated(
codex_app_server_protocol::ThreadNameUpdatedNotification {
thread_id: thread_id.to_string(),
thread_name: Some(title.to_string()),
},
),
/*replay_kind*/ None,
);
assert_eq!(chat.thread_name, Some(title.to_string()));
assert!(drain_insert_history(&mut rx).is_empty());
}
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]
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());
assert_eq!(chat.thread_name(), Some("Manual title".to_string()));
assert!(drain_insert_history(&mut rx).is_empty());
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]
async fn live_app_server_thread_closed_requests_immediate_exit() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;