Return to the agent command center after archiving on shared servers (#44337)

## Why

`/archive` exits the TUI even when connected to a local daemon or remote app server, interrupting access to other tasks.

## What changed

- Keep the TUI running after a successful archive on local daemon and remote connections, and reopen the agent command center.
- Shut down side conversations before archiving, then clear the archived thread's local state, transcript, and unsent draft.
- Preserve exit-on-archive behavior for the embedded app server and remove the exit promise from `/archive` help and confirmation text.

## Testing

Add coverage for local daemon and remote connections, including side-thread cleanup, archive requests, cleared session state, and the resulting command center snapshot. Retain coverage for embedded archive success and failure.

GitOrigin-RevId: 36c61ec76a13a3fc1b5d6725e3b8f42a97fe6793
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-09 23:50:28 +00:00
1 parent 0df6366a87
commit d390f0a09c
8 files changed
+227 -82

No files matched your search

+40 -7
View File
@@ -383,7 +383,7 @@ impl App {
}
}
AppEvent::ArchiveCurrentThread => {
return Ok(self.archive_current_thread(app_server).await);
return self.archive_current_thread(tui, app_server).await;
}
AppEvent::DeleteCurrentThread => {
return Ok(self.delete_current_thread(app_server).await);
@@ -3448,29 +3448,62 @@ impl App {
pub(super) async fn archive_current_thread(
&mut self,
tui: &mut tui::Tui,
app_server: &mut AppServerSession,
) -> AppRunControl {
) -> Result<AppRunControl> {
let Some(thread_id) = self.active_thread_id.or(self.chat_widget.thread_id()) else {
self.chat_widget
.add_error_message("A thread must start before it can be archived.".to_string());
return AppRunControl::Continue;
return Ok(AppRunControl::Continue);
};
if self.side_threads.contains_key(&thread_id) {
self.chat_widget.add_error_message(
"'/archive' is unavailable in side conversations. Press Ctrl+C to return to the main thread first."
.to_string(),
);
return AppRunControl::Continue;
return Ok(AppRunControl::Continue);
}
match app_server.thread_archive(thread_id).await {
Ok(()) => AppRunControl::Exit(ExitReason::Archived(thread_id)),
if !matches!(self.app_server_target, AppServerTarget::Embedded) {
self.shutdown_side_threads(app_server).await;
if !self.side_threads.is_empty() {
return Ok(AppRunControl::Continue);
}
}
Ok(match app_server.thread_archive(thread_id).await {
Ok(()) if matches!(self.app_server_target, AppServerTarget::Embedded) => {
AppRunControl::Exit(ExitReason::Archived(thread_id))
}
Ok(()) => {
self.track_agents_overview_notification(&ServerNotification::ThreadArchived(
codex_app_server_protocol::ThreadArchivedNotification {
thread_id: thread_id.to_string(),
},
));
self.discard_thread_local_state(thread_id).await;
self.agents_overview.input_states.remove(&thread_id);
self.agents_overview.dispatched_requests.remove(&thread_id);
self.reset_for_thread_switch(tui)?;
self.pending_thread_switch_resets += 1;
self.app_event_tx
.send(AppEvent::ResetTranscriptForThreadSwitch);
self.reset_thread_event_state();
let init = self.chatwidget_init_for_forked_or_resumed_thread(
tui,
self.config.clone(),
/*initial_user_message*/ None,
);
self.replace_chat_widget(ChatWidget::new_with_app_event(init));
self.open_agents_overview(app_server);
AppRunControl::Continue
}
Err(err) => {
self.chat_widget
.add_error_message(format!("Failed to archive current thread: {err}"));
AppRunControl::Continue
}
}
})
}
pub(super) async fn delete_current_thread(