Allow naming sessions with /new and /clear (#34605)

## What changed

- Accept an optional session name after `/new` or `/clear`.
- Set the requested name through the app server when starting the new thread and update the attached session with that name.
- Report naming failures in the chat while still attaching the newly created thread.

## Testing

- Cover named `/new` and `/clear` dispatch, app-server name persistence, and the existing unnamed `/clear` behavior.

GitOrigin-RevId: 570886abb4af522123f0693ce05d2415e1c0d902
This commit is contained in:
Eric Traut authored and copyberry committed 2026-07-21 20:13:08 +00:00
1 parent 2497972808
commit 25d2dfcad0
8 files changed
+149 -21

No files matched your search

@@ -137,6 +137,62 @@ async fn start_recording_app_server(
))
}
#[test]
fn fresh_session_applies_requested_name() -> Result<()> {
const TEST_STACK_SIZE_BYTES: usize = 8 * 1024 * 1024;
std::thread::Builder::new()
.name("tui-named-fresh-session".to_string())
.stack_size(TEST_STACK_SIZE_BYTES)
.spawn(|| {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
runtime.block_on(async {
let mut app = make_test_app().await;
let codex_home = tempdir()?;
app.config.codex_home = codex_home.path().to_path_buf().abs();
app.config.sqlite_home = codex_home.path().to_path_buf();
let (mut app_server, requests, proxy) =
start_recording_app_server(&app.config).await?;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.start_fresh_session_with_summary_hint(
&mut tui,
&mut app_server,
/*session_start_source*/ None,
/*initial_user_message*/ None,
/*new_thread_name*/ Some("Add User".to_string()),
)
.await;
let thread_id = app
.chat_widget
.thread_id()
.expect("fresh session should have a thread id");
assert_eq!(app.chat_widget.thread_name(), Some("Add User".to_string()));
assert!(
requests
.lock()
.expect("request recorder lock")
.iter()
.any(|method| method == "thread/name/set"),
"fresh session should be named through the app server"
);
let thread = app_server
.thread_read(thread_id, /*include_turns*/ false)
.await?;
assert_eq!(thread.name.as_deref(), Some("Add User"));
app_server.shutdown().await?;
proxy.await??;
Ok(())
})
})?
.join()
.expect("named fresh session test thread")
}
#[test]
fn session_lifecycle_avoids_redundant_subagent_metadata_reads() -> Result<()> {
const TEST_STACK_SIZE_BYTES: usize = 8 * 1024 * 1024;
@@ -231,6 +287,7 @@ fn session_lifecycle_avoids_redundant_subagent_metadata_reads() -> Result<()> {
&mut app_server,
/*session_start_source*/ None,
/*initial_user_message*/ None,
/*new_thread_name*/ None,
)
.await;