mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Reconnect TUI app-server sessions automatically (#41916)
## What changed - Reconnect out-of-process TUI sessions after the app-server transport drops, bootstrap a fresh client, and resume the active thread. - Preserve cached transcripts, drafts, runtime settings, task-tool capabilities, and live notification routing across the new connection. - Keep recovered or possibly submitted input paused for manual review instead of resending it, and leave conversations that cannot be resumed available as read-only cached views. - Show reconnect progress and actionable failure states while still allowing drafts to be edited or copied. ## Testing - Add app-level coverage for successful recovery, failed and unavailable resumes, input quarantine, and preserved session state. - Extend the terminal integration test to verify that a draft survives reconnection, the thread is resumed without starting a turn, and notifications arrive through the replacement connection. GitOrigin-RevId: 5dcb867c89e226a0c545d6313a77424c233cd47a
This commit is contained in:
1 parent
9a4b78579a
commit
907c34e867
20 files changed
+1082
-46
No files matched your search
@@ -683,6 +683,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
}
|
||||
|
||||
let mut listen_for_app_server_events = true;
|
||||
let mut reconnect = None;
|
||||
let mut waiting_for_initial_session_configured = wait_for_initial_session_configured;
|
||||
let mut waiting_for_initial_session_header = true;
|
||||
|
||||
@@ -711,6 +712,20 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
Ok(exit_reason)
|
||||
} else {
|
||||
loop {
|
||||
if app.reconnect.offline
|
||||
&& !app.reconnect.failed
|
||||
&& reconnect.is_none()
|
||||
&& app.reconnect.presentation == reconnect::ReconnectPresentation::Conversation
|
||||
{
|
||||
reconnect = Some(Box::pin(reconnect::reconnect(
|
||||
app.app_server_target.clone(),
|
||||
app.config.clone(),
|
||||
app.current_displayed_thread_id(),
|
||||
app_server.remote_cwd_override().map(Path::to_path_buf),
|
||||
app_server.thread_tool_transport(),
|
||||
app.reconnect.presentation,
|
||||
)));
|
||||
}
|
||||
// Replay queues history and operations. A buffered closure must not switch
|
||||
// widgets before those app events have been applied.
|
||||
let has_pending_app_events = !app_event_rx.is_empty();
|
||||
@@ -815,6 +830,25 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
}
|
||||
AppRunControl::Continue
|
||||
}
|
||||
result = async { match reconnect.as_mut() { Some(future) => future.await, None => std::future::pending().await } }, if reconnect.is_some() && !has_pending_app_events => {
|
||||
reconnect = None;
|
||||
match result {
|
||||
Ok(connected) => {
|
||||
app.finish_reconnect(tui, &mut app_server, &mut app_event_rx, connected).await?;
|
||||
listen_for_app_server_events = true;
|
||||
waiting_for_initial_session_configured = false;
|
||||
}
|
||||
Err(error) => {
|
||||
app.reconnect.failed = true;
|
||||
app.chat_widget.reconnect_failed();
|
||||
app.chat_widget.add_error_message(error.to_string());
|
||||
if let Ok(mut state) = app.agents_overview.view_state.lock() {
|
||||
state.connection_notice = Some("Reconnect failed — agent list is stale; relaunch to retry");
|
||||
}
|
||||
}
|
||||
}
|
||||
AppRunControl::Continue
|
||||
}
|
||||
() = async {
|
||||
match app.chat_widget.terminal_title_next_refresh {
|
||||
Some(deadline) => {
|
||||
|
||||
Reference in new issue
Block a user