mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:22:05 +00:00
Return to the command center after session cancellation or deletion (#44711)
## Why Deleting a session, canceling an archived session resume or fork, and pressing `Esc` in a conversation open in another app previously exited the TUI. Local daemon and remote connections can instead return to the command center to select another conversation. ## What changed - Return to the command center after successful deletion on local daemon and remote connections. Shut down side conversations before deletion and clear the deleted thread's local state. - Return to the command center when an unarchive prompt is canceled, discarding startup input intended for the canceled resume or fork. Keep explicit quit actions and embedded server exit behavior. - Make `Esc` open the command center from a conversation open in another app. Reselecting that conversation preserves its read-only snapshot and draft; `R` explicitly retries attachment. - Update deletion confirmation text and keyboard hints to reflect these destinations. ## Testing Add lifecycle tests for deletion success and failure, side conversation cleanup, unarchive cancellation and quitting, and read-only snapshot preservation. Add snapshots for command center navigation hints and deletion confirmation. GitOrigin-RevId: 55a96358edb7af73949877a515614943bdc73643
This commit is contained in:
1 parent
fc948f8c47
commit
08e49689b8
18 files changed
+500
-142
No files matched your search
@@ -617,58 +617,130 @@ async fn make_history_test_app() -> Result<(App, tempfile::TempDir)> {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn deleting_remote_thread_omits_disconnect_guidance() -> Result<()> {
|
||||
let (mut app, codex_home) = make_history_test_app().await?;
|
||||
let thread_id = ThreadId::from_string(
|
||||
&create_fake_rollout(
|
||||
codex_home.path(),
|
||||
"2026-01-01T00-00-00",
|
||||
"2026-01-01T00:00:00Z",
|
||||
"Saved user message",
|
||||
Some(app.config.model_provider_id.as_str()),
|
||||
/*git_info*/ None,
|
||||
)
|
||||
.expect("create rollout"),
|
||||
)?;
|
||||
let (mut server, _, proxy) = start_recording_app_server(
|
||||
&app.config,
|
||||
/*blocked_thread_list*/ None,
|
||||
/*failed_thread_name*/ None,
|
||||
)
|
||||
.await?;
|
||||
let resumed = server
|
||||
.resume_thread(
|
||||
&app.local_settings,
|
||||
app.config.clone(),
|
||||
thread_id,
|
||||
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
|
||||
async fn delete_current_thread_navigates_only_after_success() -> Result<()> {
|
||||
let endpoint = crate::resolve_remote_addr("ws://127.0.0.1:4500")?;
|
||||
for target in [
|
||||
AppServerTarget::Embedded,
|
||||
AppServerTarget::LocalDaemon {
|
||||
endpoint: endpoint.clone(),
|
||||
},
|
||||
AppServerTarget::Remote { endpoint },
|
||||
] {
|
||||
let (mut app, _codex_home) = make_history_test_app().await?;
|
||||
let thread_id =
|
||||
create_history_rollout(&app.config, ThreadHistoryMode::Legacy, "delete me")?;
|
||||
let (mut server, requests, proxy) = start_recording_app_server(
|
||||
&app.config,
|
||||
/*blocked_thread_list*/ None,
|
||||
/*failed_thread_name*/ None,
|
||||
)
|
||||
.await?;
|
||||
app.app_server_target = AppServerTarget::Remote {
|
||||
endpoint: crate::resolve_remote_addr("ws://127.0.0.1:4500")?,
|
||||
};
|
||||
app.active_thread_id = Some(thread_id);
|
||||
app.chat_widget.handle_thread_session(resumed.session);
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
// Keep the large dispatcher future off the Windows test thread's stack.
|
||||
let AppRunControl::Exit(reason) =
|
||||
Box::pin(app.handle_event(&mut tui, &mut server, AppEvent::DeleteCurrentThread)).await?
|
||||
else {
|
||||
panic!("removing the current thread must exit");
|
||||
};
|
||||
assert_matches!(reason, ExitReason::ThreadRemoved);
|
||||
let mut exit_info = app.exit_info(reason);
|
||||
exit_info.token_usage = TokenUsage {
|
||||
output_tokens: 2,
|
||||
total_tokens: 2,
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
exit_info.format_exit_messages(/*color_enabled*/ false),
|
||||
vec!["Token usage: total=2 input=0 output=2".to_string()]
|
||||
);
|
||||
server.shutdown().await?;
|
||||
proxy.await??;
|
||||
app.app_server_target = target;
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let missing_id = ThreadId::new();
|
||||
app.active_thread_id = Some(missing_id);
|
||||
app.chat_widget.insert_str("Retained on failure");
|
||||
assert_matches!(
|
||||
app.delete_current_thread(&mut tui, &mut server).await?,
|
||||
AppRunControl::Continue
|
||||
);
|
||||
assert_eq!(app.active_thread_id, Some(missing_id));
|
||||
assert_eq!(
|
||||
app.chat_widget.composer_text_with_pending(),
|
||||
"Retained on failure"
|
||||
);
|
||||
assert!(!app.chat_widget.has_active_view());
|
||||
|
||||
let resumed = server
|
||||
.resume_thread(
|
||||
&app.local_settings,
|
||||
app.config.clone(),
|
||||
thread_id,
|
||||
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
|
||||
)
|
||||
.await?;
|
||||
app.active_thread_id = Some(thread_id);
|
||||
app.enqueue_primary_thread_session(resumed.session.clone(), resumed.turns)
|
||||
.await?;
|
||||
app.chat_widget.handle_thread_session(resumed.session);
|
||||
let mut side_config = app.config.clone();
|
||||
side_config.ephemeral = true;
|
||||
let side = server
|
||||
.fork_side_thread(&app.local_settings, side_config.clone(), thread_id)
|
||||
.await?;
|
||||
let side_id = side.session.thread_id;
|
||||
app.side_threads
|
||||
.insert(side_id, SideThreadState::new(thread_id));
|
||||
if !matches!(app.app_server_target, AppServerTarget::Embedded) {
|
||||
// The recording proxy rejects the next unsubscribe after a failed fork.
|
||||
side_config.cwd = side_config.cwd.join("failure");
|
||||
assert!(
|
||||
server
|
||||
.fork_side_thread(&app.local_settings, side_config, thread_id)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
assert_matches!(
|
||||
app.delete_current_thread(&mut tui, &mut server).await?,
|
||||
AppRunControl::Continue
|
||||
);
|
||||
assert_eq!(app.active_thread_id, Some(thread_id));
|
||||
assert!(app.side_threads.contains_key(&side_id));
|
||||
assert!(!app.chat_widget.has_active_view());
|
||||
assert_eq!(recorded_params(&requests, "thread/delete").len(), 1);
|
||||
}
|
||||
let (tx, mut events) = tokio::sync::mpsc::unbounded_channel();
|
||||
app.app_event_tx = AppEventSender::new(tx);
|
||||
let control =
|
||||
Box::pin(app.handle_event(&mut tui, &mut server, AppEvent::DeleteCurrentThread))
|
||||
.await?;
|
||||
assert!(
|
||||
server
|
||||
.thread_read(thread_id, /*include_turns*/ false)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
if matches!(app.app_server_target, AppServerTarget::Embedded) {
|
||||
assert_matches!(control, AppRunControl::Exit(ExitReason::ThreadRemoved));
|
||||
assert!(recorded_params(&requests, "thread/unsubscribe").is_empty());
|
||||
} else {
|
||||
assert_matches!(control, AppRunControl::Continue);
|
||||
assert!(app.side_threads.is_empty());
|
||||
assert_eq!(
|
||||
recorded_params(&requests, "thread/unsubscribe"),
|
||||
vec![serde_json::json!({"threadId": side_id.to_string()}); 2]
|
||||
);
|
||||
loop {
|
||||
let event = tokio::time::timeout(Duration::from_secs(/*secs*/ 5), events.recv())
|
||||
.await?
|
||||
.expect("command center refresh");
|
||||
let refreshed = matches!(&event, AppEvent::AgentsOverviewThreadsLoaded { .. });
|
||||
Box::pin(app.handle_event(&mut tui, &mut server, event)).await?;
|
||||
if refreshed {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
(
|
||||
app.active_thread_id,
|
||||
app.primary_thread_id,
|
||||
app.chat_widget.thread_id()
|
||||
),
|
||||
(None, None, None)
|
||||
);
|
||||
assert!(app.chat_widget.composer_is_empty());
|
||||
assert!(app.chat_widget.has_active_view());
|
||||
}
|
||||
assert_eq!(
|
||||
recorded_params(&requests, "thread/delete"),
|
||||
vec![
|
||||
serde_json::json!({"threadId": missing_id.to_string()}),
|
||||
serde_json::json!({"threadId": thread_id.to_string()}),
|
||||
]
|
||||
);
|
||||
server.shutdown().await?;
|
||||
proxy.await??;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4294,3 +4366,85 @@ fn session_lifecycle_avoids_redundant_subagent_metadata_reads() -> Result<()> {
|
||||
mod new_session_tests;
|
||||
#[path = "startup_defaults_tests.rs"]
|
||||
mod startup_defaults_tests;
|
||||
|
||||
#[tokio::test]
|
||||
async fn external_writer_escape_preserves_snapshot_and_explicit_quits() -> Result<()> {
|
||||
let endpoint = crate::resolve_remote_addr("ws://127.0.0.1:4500")?;
|
||||
for target in [
|
||||
AppServerTarget::LocalDaemon {
|
||||
endpoint: endpoint.clone(),
|
||||
},
|
||||
AppServerTarget::Remote { endpoint },
|
||||
] {
|
||||
let (mut app, _codex_home) = make_history_test_app().await?;
|
||||
let thread_id =
|
||||
create_history_rollout(&app.config, ThreadHistoryMode::Legacy, "owned elsewhere")?;
|
||||
let (mut server, requests, proxy) = start_recording_app_server(
|
||||
&app.config,
|
||||
/*blocked_thread_list*/ None,
|
||||
/*failed_thread_name*/ None,
|
||||
)
|
||||
.await?;
|
||||
app.app_server_target = target;
|
||||
app.active_thread_id = Some(thread_id);
|
||||
app.primary_thread_id = Some(thread_id);
|
||||
app.ensure_thread_channel(thread_id).mark_external_writer();
|
||||
app.chat_widget.show_external_writer_thread();
|
||||
app.chat_widget.insert_str("Retained draft");
|
||||
let (tx, mut events) = tokio::sync::mpsc::unbounded_channel();
|
||||
app.app_event_tx = AppEventSender::new(tx);
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
for key in [
|
||||
KeyEvent::new(KeyCode::Char('q'), KeyModifiers::NONE),
|
||||
KeyEvent::new(KeyCode::Char('Q'), KeyModifiers::SHIFT),
|
||||
KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL),
|
||||
] {
|
||||
app.handle_key_event(&mut tui, &mut server, key).await;
|
||||
assert_matches!(events.try_recv(), Ok(AppEvent::Exit(ExitMode::Immediate)));
|
||||
}
|
||||
app.handle_key_event(
|
||||
&mut tui,
|
||||
&mut server,
|
||||
KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE),
|
||||
)
|
||||
.await;
|
||||
assert!(app.chat_widget.has_active_view());
|
||||
loop {
|
||||
let event = tokio::time::timeout(Duration::from_secs(/*secs*/ 5), events.recv())
|
||||
.await?
|
||||
.expect("command center refresh");
|
||||
let refreshed = matches!(&event, AppEvent::AgentsOverviewThreadsLoaded { .. });
|
||||
Box::pin(app.handle_event(&mut tui, &mut server, event)).await?;
|
||||
if refreshed {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert_matches!(
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut server,
|
||||
AppEvent::SelectAgentsOverviewThread { thread_id },
|
||||
))
|
||||
.await?,
|
||||
AppRunControl::Continue
|
||||
);
|
||||
assert!(!app.chat_widget.has_active_view());
|
||||
assert_eq!(app.active_thread_id, Some(thread_id));
|
||||
assert!(app.chat_widget.is_external_writer_view());
|
||||
assert_eq!(
|
||||
app.chat_widget.composer_text_with_pending(),
|
||||
"Retained draft"
|
||||
);
|
||||
assert_eq!(
|
||||
app.thread_event_channels[&thread_id].attachment(),
|
||||
ThreadEventAttachment::ExternalWriter
|
||||
);
|
||||
assert!(requests.lock().unwrap().iter().all(|request| matches!(
|
||||
request.method.as_str(),
|
||||
"thread/read" | "thread/list" | "thread/loaded/list" | "thread/turns/list"
|
||||
)));
|
||||
server.shutdown().await?;
|
||||
proxy.await??;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user