Show a loading indicator while the resume picker starts (#63102)

## Why

`codex resume` can wait for the app server connection and login status
before the session picker opens, leaving the terminal blank while they wait.

## What changed

Display “Loading sessions…” during startup using the same styling as the
picker. Clear the inline indicator after the login status check or when
startup fails or is canceled.

## Testing

Add a terminal test that holds open a Unix socket to stall the connection,
checks that `codex resume --no-alt-screen` displays the loading indicator,
then closes the socket and verifies that the error replaces the indicator.

GitOrigin-RevId: 04b1a40343be284e2c56fd9519bb57a2b2fa6ecd
This commit is contained in:
Eric Traut
2026-11-22 08:27:26 +00:00
committed by copyberry
parent 1476a08f1b
commit cf3ff1530d
4 changed files with 48 additions and 7 deletions
+15
View File
@@ -1261,6 +1261,17 @@ async fn run_ratatui_app(
)
.await
};
if cli.resume_picker {
tui.draw(/*height*/ 1, |frame| {
frame.render_widget_ref(&resume_picker::loading_sessions_line(), frame.area());
})?;
}
let clear_inline_loading = |tui: &mut Tui| {
if cli.resume_picker && !tui.is_alt_screen_active() {
// Draw so the viewport follows the shell cursor after suspend/resume.
let _ = tui.draw(/*height*/ 0, |_| {});
}
};
let startup_app_server = startup_draft
.run_until(
&mut tui,
@@ -1288,11 +1299,13 @@ async fn run_ratatui_app(
.with_local_codex_home(&initial_config.codex_home)
}
Ok(Err(err)) => {
clear_inline_loading(&mut tui);
terminal_restore_guard.restore_silently();
session_log::log_session_end();
return Err(err);
}
Err(err) => {
clear_inline_loading(&mut tui);
terminal_restore_guard.restore_silently();
session_log::log_session_end();
return Err(err.into());
@@ -1319,6 +1332,7 @@ async fn run_ratatui_app(
);
}
Err(err) => {
clear_inline_loading(&mut tui);
shutdown_startup_session(Some(app_server_session), &mut terminal_restore_guard)
.await;
return Err(err.into());
@@ -1338,6 +1352,7 @@ async fn run_ratatui_app(
let login_status = startup_draft
.run_until(&mut tui, get_login_status(active_app_server))
.await;
clear_inline_loading(&mut tui);
let (login_status, mut startup_account) = match login_status {
Ok(Ok((login_status, account))) => (login_status, Some(account)),
Ok(Err(err)) => {
+9 -6
View File
@@ -4178,6 +4178,14 @@ fn format_timestamp(ts: DateTime<Utc>, clock_format: ClockFormat) -> String {
.to_string()
}
pub(crate) fn loading_sessions_line() -> Line<'static> {
Line::from(
"Loading sessions…"
.set_style(secondary_text_style())
.italic(),
)
}
fn render_empty_state_line(state: &PickerState) -> Line<'static> {
if !state.query.is_empty() {
if state.search_state.is_active()
@@ -4202,12 +4210,7 @@ fn render_empty_state_line(state: &PickerState) -> Line<'static> {
if state.pagination.is_loading() {
if state.all_rows.is_empty() && state.pagination.num_scanned_files == 0 {
return vec![
"Loading sessions…"
.set_style(secondary_text_style())
.italic(),
]
.into();
return loading_sessions_line();
}
return vec![
"Loading older sessions…"
+2 -1
View File
@@ -151,7 +151,8 @@ impl StartupDraftPump {
&& StartupCancelled::matches(&error))
{
if StartupCancelled::matches(&error)
&& let Err(clear_error) = tui.terminal.clear()
&& !tui.terminal.viewport_area.is_empty()
&& let Err(clear_error) = tui.draw(/*height*/ 0, |_| {})
{
tracing::warn!(
error = %clear_error,
+22
View File
@@ -683,6 +683,28 @@ fn no_daemon_skips_startup_and_discovery() -> Result<()> {
Ok(())
}
#[test]
fn resume_shows_loading_until_connection_fails() -> Result<()> {
let workspace = tempfile::tempdir()?;
let home = tempfile::tempdir_in("/tmp")?;
write_test_config(home.path(), workspace.path())?;
let socket = home.path().join("server.sock");
let listener = std::os::unix::net::UnixListener::bind(&socket)?;
let endpoint = format!("unix://{}", socket.display());
let mut terminal = PtyCodex::start_cli(
workspace.path(),
home,
&["resume", "--no-alt-screen", "--remote", &endpoint],
)?;
terminal.wait_for_screen("Loading sessions…")?;
insta::assert_snapshot!(terminal.screen_contents(), @"Loading sessions…");
drop(listener);
ensure!(!terminal.child.wait()?.success());
terminal.wait_for_screen("Error:")?;
ensure!(terminal.screen_contents().starts_with("Error:"));
Ok(())
}
#[test]
fn auto_daemon_start_failure_exits_with_manual_fallback_hint() -> Result<()> {
let workspace = tempfile::tempdir()?;