mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Surface session lookup errors in the TUI (#64014)
## Why Looking up a session by ID treated every `thread/read` failure as a missing session, hiding errors such as unreadable session metadata. ## What changed Startup resume and fork report lookup failures after cleaning up the app-server session. In an active TUI, `/resume` displays lookup errors in the current chat or invokes transport recovery when applicable. If a Cloud chat must be opened first, `/resume` directs the user to run the command without an ID and select the chat from the picker. ## Testing Add regression coverage for missing and unreadable sessions, preserving the active session after a failed lookup, and showing picker guidance for an unopened Cloud chat. GitOrigin-RevId: dddac289a2959133809c050b8701975ab474ef13
This commit is contained in:
@@ -761,13 +761,24 @@ impl App {
|
||||
));
|
||||
}
|
||||
Err(err)
|
||||
if err
|
||||
.downcast_ref::<crate::named_session_lookup::AmbiguousSessionName>()
|
||||
.is_some() =>
|
||||
if app_server.thread_params_mode() == crate::ThreadParamsMode::Cloud
|
||||
&& matches!(
|
||||
err.downcast_ref::<TypedRequestError>(),
|
||||
Some(TypedRequestError::Server { method, source })
|
||||
if method == "thread/read"
|
||||
&& source.message == "Open this cloud conversation before reading its transcript."
|
||||
) =>
|
||||
{
|
||||
self.chat_widget.add_error_message(err.to_string());
|
||||
self.chat_widget.add_error_message(
|
||||
"Run /resume without an ID and select the Cloud chat from the picker."
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
if !self.recover_transport_error(&err) {
|
||||
self.chat_widget.add_error_message(err.to_string());
|
||||
}
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
}
|
||||
AppEvent::ResumeBackendSession(_)
|
||||
|
||||
@@ -16,6 +16,84 @@ use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_lookup_distinguishes_missing_and_unreadable_rollouts() -> color_eyre::Result<()> {
|
||||
use crate::resume_picker::SessionPickerAction;
|
||||
|
||||
let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;
|
||||
let config = &app.config;
|
||||
let id = crate::tests::write_session_rollout(
|
||||
config.codex_home.as_path(),
|
||||
"2025-01-02T10-00-00",
|
||||
"2025-01-02T10:00:00Z",
|
||||
"saved session",
|
||||
&config.model_provider_id,
|
||||
config.cwd.as_path(),
|
||||
)?;
|
||||
let mut server = crate::start_embedded_app_server_for_picker(config).await?;
|
||||
let mut lookup = async |action, id: ThreadId| {
|
||||
crate::lookup_session_target_with_app_server(action, &mut server, config, &id.to_string())
|
||||
.await
|
||||
};
|
||||
let missing = lookup(SessionPickerAction::Resume, ThreadId::new()).await?;
|
||||
assert!(missing.is_none());
|
||||
|
||||
let target = lookup(SessionPickerAction::Resume, id)
|
||||
.await?
|
||||
.expect("saved session");
|
||||
let path = target.path.expect("saved session has a rollout");
|
||||
std::fs::write(&path, "")?;
|
||||
let err = lookup(SessionPickerAction::Fork, id)
|
||||
.await
|
||||
.expect_err("unreadable session metadata");
|
||||
let message = err.to_string().replace(path.to_str().unwrap(), "<rollout>");
|
||||
insta::assert_snapshot!(message, @"thread/read failed: failed to read thread: thread-store internal error: failed to read session metadata <rollout>: thread-store internal error: failed to read session metadata <rollout>: rollout at <rollout> is empty (code -32603)");
|
||||
|
||||
let current = ThreadId::new();
|
||||
app.active_thread_id = Some(current);
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let control = app
|
||||
.handle_event(
|
||||
&mut tui,
|
||||
&mut server,
|
||||
AppEvent::ResumeSessionByIdOrName(id.to_string()),
|
||||
)
|
||||
.await?;
|
||||
assert!(matches!(control, AppRunControl::Continue));
|
||||
assert_eq!(app.active_thread_id, Some(current));
|
||||
assert!(next_history_message(&mut events).contains("thread/read failed"));
|
||||
server.shutdown().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn cloud_resume_by_id_points_to_picker_for_unopened_chat() -> Result<()> {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let (client, mut commands, _events) =
|
||||
codex_app_server_client::CloudClient::channel(/*capacity*/ 1);
|
||||
let mut server = AppServerSession::new(
|
||||
crate::backend_id::BackendId::new(),
|
||||
codex_app_server_client::AppServerClient::Cloud(client),
|
||||
crate::ThreadParamsMode::Cloud,
|
||||
);
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let event = AppEvent::ResumeSessionByIdOrName(ThreadId::new().to_string());
|
||||
let (control, ()) = tokio::join!(app.handle_event(&mut tui, &mut server, event), async {
|
||||
let command = commands.recv().await.expect("thread/read");
|
||||
command
|
||||
.response
|
||||
.send(Ok(Err(JSONRPCErrorError {
|
||||
code: -32000,
|
||||
message: "Open this cloud conversation before reading its transcript.".into(),
|
||||
data: None,
|
||||
})))
|
||||
.unwrap();
|
||||
});
|
||||
assert!(matches!(control?, AppRunControl::Continue));
|
||||
insta::assert_snapshot!(next_history_message(&mut events), @"■ Run /resume without an ID and select the Cloud chat from the picker.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn new_and_resumed_sessions_use_quota_for_the_active_provider() -> Result<()> {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
|
||||
+29
-30
@@ -38,6 +38,7 @@ use codex_app_server_client::InProcessClientStartArgs;
|
||||
use codex_app_server_client::RemoteAppServerClient;
|
||||
use codex_app_server_client::RemoteAppServerConnectArgs;
|
||||
pub use codex_app_server_client::RemoteAppServerEndpoint;
|
||||
use codex_app_server_client::TypedRequestError;
|
||||
use codex_app_server_client::cloud_backend;
|
||||
pub use codex_app_server_client::resolve_remote_addr;
|
||||
pub use codex_app_server_client::resolve_remote_endpoint;
|
||||
@@ -100,7 +101,6 @@ use tracing::warn;
|
||||
use tracing_appender::non_blocking;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use tracing_subscriber::prelude::*;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub(crate) use codex_app_server_client::legacy_core;
|
||||
|
||||
@@ -758,35 +758,34 @@ async fn lookup_session_target_with_app_server(
|
||||
config: &Config,
|
||||
id_or_name: &str,
|
||||
) -> color_eyre::Result<Option<resume_picker::SessionTarget>> {
|
||||
if Uuid::parse_str(id_or_name).is_ok() {
|
||||
let thread_id = match ThreadId::from_string(id_or_name) {
|
||||
Ok(thread_id) => thread_id,
|
||||
Err(err) => {
|
||||
warn!(
|
||||
session = id_or_name,
|
||||
%err,
|
||||
"Failed to parse session id during TUI lookup"
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
};
|
||||
return match app_server
|
||||
if let Ok(thread_id) = ThreadId::from_string(id_or_name) {
|
||||
let thread = match app_server
|
||||
.thread_read(thread_id, /*include_turns*/ false)
|
||||
.await
|
||||
{
|
||||
Ok(thread) => Ok(session_target_from_app_server_thread(
|
||||
app_server.backend_id(),
|
||||
thread,
|
||||
)),
|
||||
Ok(thread) => thread,
|
||||
Err(err) => {
|
||||
warn!(
|
||||
session = id_or_name,
|
||||
%err,
|
||||
"thread/read failed during TUI session lookup"
|
||||
);
|
||||
Ok(None)
|
||||
// Startup displays only the outer error. Expose the RPC failure without raw data.
|
||||
let mut err = err.downcast::<TypedRequestError>()?;
|
||||
if let TypedRequestError::Server { source, .. } = &mut err {
|
||||
if source.code == app_server_session::JSONRPC_INVALID_REQUEST
|
||||
&& source.message == format!("thread not loaded: {thread_id}")
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
source.data = None;
|
||||
}
|
||||
return Err(err.into());
|
||||
}
|
||||
};
|
||||
let target = session_target_from_app_server_thread(app_server.backend_id(), thread)
|
||||
.filter(|target| target.thread_id == thread_id)
|
||||
.ok_or_else(|| {
|
||||
color_eyre::eyre::eyre!(
|
||||
"thread/read returned an unexpected session ID for {thread_id}"
|
||||
)
|
||||
})?;
|
||||
return Ok(Some(target));
|
||||
}
|
||||
|
||||
let model_providers = match action {
|
||||
@@ -1615,11 +1614,11 @@ async fn run_ratatui_app(
|
||||
),
|
||||
)
|
||||
.await;
|
||||
let target_session = match lookup {
|
||||
Ok(result) => result?,
|
||||
let target_session = match lookup.map_err(color_eyre::Report::from).flatten() {
|
||||
Ok(result) => result,
|
||||
Err(err) => {
|
||||
shutdown_startup_session(app_server.take(), &mut terminal_restore_guard).await;
|
||||
return Err(err.into());
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
match target_session {
|
||||
@@ -1720,11 +1719,11 @@ async fn run_ratatui_app(
|
||||
),
|
||||
)
|
||||
.await;
|
||||
let target_session = match lookup {
|
||||
Ok(result) => result?,
|
||||
let target_session = match lookup.map_err(color_eyre::Report::from).flatten() {
|
||||
Ok(result) => result,
|
||||
Err(err) => {
|
||||
shutdown_startup_session(app_server.take(), &mut terminal_restore_guard).await;
|
||||
return Err(err.into());
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
match target_session {
|
||||
|
||||
@@ -15,6 +15,7 @@ use codex_app_server_protocol::Turn;
|
||||
use codex_utils_absolute_path::test_support::PathExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tempfile::TempDir;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn tui_startup_future_stays_bounded() {
|
||||
|
||||
Reference in New Issue
Block a user