Show recent sessions in the agent command center (#42104)

## Why

The agent command center only listed sessions currently loaded by the app server, so completed or otherwise unloaded tasks could not be revisited from the overview.

## What changed

- Seed the overview with up to 20 recent root sessions in addition to loaded sessions, retain discovered sessions for the lifetime of the TUI, and update rows from thread lifecycle notifications.
- Allow unloaded sessions to be resumed from the overview using the normal working-directory selection and configuration rebuild flow. Explicit runtime permission choices carry across a cold resume, while settings inherited from the previously selected task do not.
- Fall back from `recency_at` to `updated_at` when connected to an older server, and continue showing loaded sessions when recent-history listing is unavailable.

## Testing

Added coverage for recent-session discovery and retention, notification races, legacy and failed listing fallbacks, cold-resume working-directory and permission handling, reconnect behavior, and unloaded-session rendering and selection.

GitOrigin-RevId: 668068b1594eb24b2ea7faccd0327804b8cd22ef
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-01 17:28:35 +00:00
1 parent 9969043b95
commit f40e08478c
21 files changed
+1352 -316

No files matched your search

+4 -83
View File
@@ -13,7 +13,6 @@ use super::app_server_event_targets::server_request_thread_id;
use super::*;
use crate::app_server_session::source_agent_path;
use crate::app_server_session::thread_blocks_direct_input;
use codex_config::types::ResumeCwdMode;
use std::collections::HashSet;
#[derive(Clone, Copy)]
@@ -1087,92 +1086,14 @@ impl App {
return Ok(AppRunControl::Continue);
}
self.refresh_in_memory_config_from_disk_best_effort("resuming a thread")
.await;
let cwd_override = self
.runtime_working_directory_override
.as_deref()
.or(self.harness_overrides.cwd.as_deref())
.or_else(|| app_server.remote_cwd_override());
let resume_cwd_mode = crate::session_resume::effective_resume_cwd_mode(
self.config.tui_resume_cwd,
cwd_override,
);
let remembered_current_cwd = cwd_override.unwrap_or(self.launch_cwd.as_path());
let current_cwd = if matches!(resume_cwd_mode, Some(ResumeCwdMode::Current)) {
remembered_current_cwd.to_path_buf()
} else {
self.config.cwd.to_path_buf()
};
let uses_remote_workspace_or_environment = crate::uses_remote_workspace_or_environment(
&self.app_server_target,
&self.environment_manager,
);
if uses_remote_workspace_or_environment
&& self.harness_overrides.cwd.is_none()
&& app_server.remote_cwd_override().is_none()
&& matches!(resume_cwd_mode, Some(ResumeCwdMode::Current))
{
self.chat_widget.add_error_message(
"`tui.resume_cwd = \"current\"` requires `--cd` when using a remote workspace"
.to_string(),
);
return Ok(AppRunControl::Continue);
}
let resume_cwd = if self.app_server_target.uses_remote_workspace() {
current_cwd.clone()
} else {
let outcome = crate::session_resume::resolve_cwd_for_resume_or_fork(
tui,
&self.config,
self.state_db.as_deref(),
&target_session,
CwdPromptAction::Resume,
crate::session_resume::ResumeCwdContext {
current_cwd: &current_cwd,
remembered_current_cwd,
allow_remember_current: !uses_remote_workspace_or_environment
|| cwd_override.is_some(),
mode: resume_cwd_mode,
},
)
.await;
match outcome {
Err(err) => {
self.chat_widget.add_error_message(format!(
"Failed to determine working directory for resume: {err}"
));
return Ok(AppRunControl::Continue);
}
Ok(crate::session_resume::ResolveCwdOutcome::Continue(Some(cwd)))
| Ok(crate::session_resume::ResolveCwdOutcome::ContinueAfterPrompt(cwd)) => cwd,
Ok(crate::session_resume::ResolveCwdOutcome::Continue(None)) => current_cwd.clone(),
Ok(crate::session_resume::ResolveCwdOutcome::Exit) => {
return Ok(AppRunControl::Exit(ExitReason::UserRequested));
}
}
};
let (config_current_cwd, config_resume_cwd) =
if self.app_server_target.uses_remote_workspace() {
let local_config_cwd = self.config.cwd.to_path_buf();
(local_config_cwd.clone(), local_config_cwd)
} else {
(current_cwd, resume_cwd)
};
let mut resume_config = match self
.rebuild_config_for_resume_or_fallback(&config_current_cwd, config_resume_cwd)
.resume_config_for_target(tui, app_server, &target_session)
.await
{
Ok(cfg) => cfg,
Err(err) => {
self.chat_widget.add_error_message(format!(
"Failed to rebuild configuration for resume: {err}"
));
return Ok(AppRunControl::Continue);
}
Ok(config) => config,
Err(control) => return Ok(control),
};
self.apply_runtime_policy_overrides(&mut resume_config);
self.apply_runtime_policy_overrides(&mut resume_config, RuntimePolicyOverrideScope::All);
let summary = session_summary(
self.chat_widget.token_usage(),