Prompt to unarchive sessions before resuming or forking (#39640)

## Why

Starting an archived session with `codex resume` or `codex fork` stopped with
guidance to run a separate `codex unarchive` command first.

## What changed

- Detect archived-session startup failures and offer to unarchive and retry the
  requested operation.
- Allow the user to cancel without modifying the archived session.
- Render the confirmation in the alternate screen when available and preserve
  inline terminal context when `--no-alt-screen` is set.
- Preserve `--no-alt-screen` whether it appears before or after the `resume` or
  `fork` subcommand.

## Testing

- Cover confirmation, cancellation, retry behavior, and unrelated startup
  failures for both resume and fork.
- Add prompt interaction and terminal rendering coverage, including narrow and
  inline viewports.

GitOrigin-RevId: 382cdbd15b5d12c091e554d6d3a2f9b3589654f4
This commit is contained in:
Jeremy Rose authored and copyberry committed 2026-08-20 07:25:40 +00:00
1 parent fdc23b93b8
commit d944ce83a2
11 files changed
+736 -57

No files matched your search

+38 -5
View File
@@ -4,6 +4,10 @@
//! remains isolated from protected interactive requests until the initialized composer owns it.
use super::*;
use crate::session_start::SessionStartAction;
use crate::session_start::cancel_session_start;
use crate::session_start::complete_session_start;
use crate::unarchive_prompt::run_unarchive_prompt;
async fn resolve_runtime_model_provider_base_url(provider: &ModelProviderInfo) -> Option<String> {
let provider = create_model_provider(provider.clone(), /*auth_manager*/ None);
@@ -304,10 +308,25 @@ impl App {
)
.await
{
Ok(resumed) => resumed
.map_err(|err| session_start_error("resume", &target_session, err))?,
Ok(resumed) => resumed,
Err(err) => return shutdown_on_startup_error(app_server, err).await,
};
let action = SessionStartAction::Resume(model_settings);
let Some(resumed) = complete_session_start(
&mut app_server,
&config,
&target_session,
action,
resumed,
async || {
startup_draft.flush_pending_events(tui).await?;
run_unarchive_prompt(tui, target_session.thread_id, action).await
},
)
.await?
else {
return Ok(cancel_session_start(app_server).await);
};
let init = crate::chatwidget::ChatWidgetInit {
config: config.clone(),
frame_requester: tui.frame_requester(),
@@ -350,11 +369,25 @@ impl App {
)
.await
{
Ok(forked) => {
forked.map_err(|err| session_start_error("fork", &target_session, err))?
}
Ok(forked) => forked,
Err(err) => return shutdown_on_startup_error(app_server, err).await,
};
let action = SessionStartAction::Fork;
let Some(forked) = complete_session_start(
&mut app_server,
&config,
&target_session,
action,
forked,
async || {
startup_draft.flush_pending_events(tui).await?;
run_unarchive_prompt(tui, target_session.thread_id, action).await
},
)
.await?
else {
return Ok(cancel_session_start(app_server).await);
};
let init = crate::chatwidget::ChatWidgetInit {
config: config.clone(),
frame_requester: tui.frame_requester(),
-27
View File
@@ -6272,33 +6272,6 @@ fn active_turn_not_steerable_turn_error_extracts_structured_server_error() {
);
}
#[test]
fn session_start_error_surfaces_archived_guidance_without_rollout_path() {
let thread_id =
ThreadId::from_string("019e72f4-e09a-70f2-b2c2-a153a57b8cc0").expect("thread id");
let target_session = SessionTarget {
path: Some(std::path::PathBuf::from(
"/Users/me/.codex/archived_sessions/rollout.jsonl",
)),
thread_id,
history_mode: None,
};
let expected = format!(
"session {thread_id} is archived. Run `codex unarchive {thread_id}` to unarchive it first."
);
for action in ["resume", "fork"] {
let err = color_eyre::eyre::eyre!(
"thread/{action} failed during TUI bootstrap: thread/{action} failed: {expected} (code -32600)"
);
assert_eq!(
session_start_error(action, &target_session, err).to_string(),
expected
);
}
}
#[test]
fn active_turn_steer_race_detects_missing_active_turn() {
let error = TypedRequestError::Server {