mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Preserve TUI drafts after app-server disconnects (#41911)
## Why Losing an external app-server connection can leave a submission's outcome uncertain. The TUI must preserve local work without retrying it or allowing stale server events to trigger more actions. ## What changed - Enter an offline state when an external app-server transport disconnects during startup, event streaming, or submission. - Keep conversation drafts, queued input, expanded pastes, attachments, and agent-overview input editable while blocking submissions, remote actions, and automatic queue replay. - Show a connection-lost notice that directs users to copy their work and relaunch, while retaining `Ctrl-C` and an empty-composer `Ctrl-D` as quit shortcuts. - Cancel pending views and asynchronous work, and ignore stale completions after the disconnect. Embedded app-server behavior is unchanged. ## Testing Added unit, snapshot, and pseudo-terminal coverage for lost startup and mutation replies, offline draft editing, queued-input recovery, stale-event quarantine, agent-overview behavior, and end-to-end preservation without reconnection or resubmission. GitOrigin-RevId: 7219a95fad676dda447d625db9e465345b469d58
This commit is contained in:
1 parent
b51b07785b
commit
a7913390f7
35 files changed
+987
-38
No files matched your search
@@ -37,8 +37,7 @@ fn spawn_startup_thread_start(
|
||||
remote_cwd_override,
|
||||
thread_tool_transport,
|
||||
)
|
||||
.await
|
||||
.map_err(|err| format!("{err:#}"));
|
||||
.await;
|
||||
app_event_tx.send(AppEvent::StartupThreadStarted { result });
|
||||
});
|
||||
}
|
||||
@@ -514,6 +513,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
feedback_audience,
|
||||
environment_manager,
|
||||
app_server_target,
|
||||
reconnect: Default::default(),
|
||||
pending_update_action: None,
|
||||
pending_shutdown_exit_thread_id: None,
|
||||
windows_sandbox: WindowsSandboxState::default(),
|
||||
@@ -717,11 +717,15 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
let initial_session_header_pending = waiting_for_initial_session_header
|
||||
&& app.primary_session_configured.is_some()
|
||||
&& has_pending_app_events;
|
||||
let block_terminal_input_for_pending_startup_events = initial_session_header_pending
|
||||
|| (pending_startup_draft.is_some() || app.startup_protected_input_boundary)
|
||||
&& has_pending_app_events
|
||||
|| (!waiting_for_initial_session_configured
|
||||
&& app.has_queued_startup_protected_request());
|
||||
let block_terminal_input_for_pending_startup_events =
|
||||
(!matches!(app.app_server_target, AppServerTarget::Embedded)
|
||||
&& has_pending_app_events)
|
||||
|| initial_session_header_pending
|
||||
|| (pending_startup_draft.is_some()
|
||||
|| app.startup_protected_input_boundary)
|
||||
&& has_pending_app_events
|
||||
|| (!waiting_for_initial_session_configured
|
||||
&& app.has_queued_startup_protected_request());
|
||||
let control = select! {
|
||||
Some(event) = app_event_rx.recv() => {
|
||||
let is_initial_session_header = matches!(
|
||||
@@ -744,6 +748,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
AppRunControl::Continue
|
||||
}
|
||||
Ok(AppRunControl::Exit(reason)) => AppRunControl::Exit(reason),
|
||||
Err(err) if app.recover_transport_error(&err) => AppRunControl::Continue,
|
||||
Err(err) => break Err(err),
|
||||
}
|
||||
}
|
||||
@@ -756,7 +761,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
}, if App::should_handle_active_thread_events(
|
||||
waiting_for_initial_session_configured,
|
||||
app.active_thread_rx.is_some()
|
||||
) && !has_pending_app_events => {
|
||||
) && !has_pending_app_events && !app.reconnect.offline => {
|
||||
if let Some(event) = active {
|
||||
if let Err(err) = app.handle_active_thread_event(tui, &mut app_server, event).await {
|
||||
break Err(err);
|
||||
@@ -766,13 +771,14 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
}
|
||||
AppRunControl::Continue
|
||||
}
|
||||
event = tui_events.next(), if !block_terminal_input_for_pending_startup_events => {
|
||||
event = tui_events.next(), if app.reconnect.offline || !block_terminal_input_for_pending_startup_events => {
|
||||
if let Some(event) = event {
|
||||
if (matches!(
|
||||
&event,
|
||||
TuiEvent::Key(key)
|
||||
if matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat)
|
||||
) || matches!(&event, TuiEvent::Paste(_)))
|
||||
&& !app.reconnect.offline
|
||||
&& pending_startup_draft.is_none()
|
||||
&& !waiting_for_initial_session_configured
|
||||
&& app_event_rx.is_empty()
|
||||
@@ -789,18 +795,21 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
}
|
||||
match app.handle_tui_event(tui, &mut app_server, event).await {
|
||||
Ok(control) => control,
|
||||
Err(err) => break Err(err),
|
||||
Err(err) if app.recover_transport_error(&err) => AppRunControl::Continue,
|
||||
Err(err) => break Err(err),
|
||||
}
|
||||
} else {
|
||||
tracing::warn!("terminal input stream closed; shutting down active thread");
|
||||
app.handle_exit_mode(&mut app_server, ExitMode::ShutdownFirst).await
|
||||
}
|
||||
}
|
||||
app_server_event = app_server.next_event(), if listen_for_app_server_events => {
|
||||
app_server_event = app_server.next_event(), if listen_for_app_server_events && !app.reconnect.offline
|
||||
&& (matches!(app.app_server_target, AppServerTarget::Embedded) || !has_pending_app_events) => {
|
||||
match app_server_event {
|
||||
Some(event) => app.handle_app_server_event(&app_server, event).await,
|
||||
None => {
|
||||
listen_for_app_server_events = false;
|
||||
app.begin_reconnect();
|
||||
tracing::warn!("app-server event stream closed");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user