mirror of
https://github.com/openai/codex.git
synced 2026-11-18 23:02:23 +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
@@ -229,6 +229,7 @@ mod platform_actions;
|
||||
mod plugin_mentions;
|
||||
mod rate_limit_refresh;
|
||||
mod recap;
|
||||
mod reconnect;
|
||||
mod replay_filter;
|
||||
mod resize_reflow;
|
||||
mod safety_buffering;
|
||||
@@ -590,6 +591,7 @@ pub(crate) struct App {
|
||||
feedback_audience: FeedbackAudience,
|
||||
environment_manager: Arc<EnvironmentManager>,
|
||||
app_server_target: AppServerTarget,
|
||||
reconnect: reconnect::ReconnectState,
|
||||
/// Set when the user confirms an update; propagated on exit.
|
||||
pub(crate) pending_update_action: Option<UpdateAction>,
|
||||
|
||||
@@ -787,6 +789,18 @@ impl App {
|
||||
app_server: &mut AppServerSession,
|
||||
event: TuiEvent,
|
||||
) -> Result<AppRunControl> {
|
||||
if self.reconnect.offline
|
||||
&& let TuiEvent::Key(key) = &event
|
||||
&& matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat)
|
||||
&& key.modifiers.contains(KeyModifiers::CONTROL)
|
||||
&& let KeyCode::Char(character) = key.code
|
||||
&& (character.eq_ignore_ascii_case(&'c')
|
||||
|| (character.eq_ignore_ascii_case(&'d')
|
||||
&& self.chat_widget.composer_is_empty()
|
||||
&& self.chat_widget.no_modal_or_popup_active()))
|
||||
{
|
||||
return Ok(AppRunControl::Exit(ExitReason::UserRequested));
|
||||
}
|
||||
let screen_size = tui.screen_size_for_event(&event)?;
|
||||
if !matches!(
|
||||
&event,
|
||||
@@ -805,6 +819,17 @@ impl App {
|
||||
event
|
||||
};
|
||||
|
||||
if self.reconnect.offline
|
||||
&& let TuiEvent::Key(key) = &event
|
||||
{
|
||||
if self.reconnect.presentation == reconnect::ReconnectPresentation::Overview {
|
||||
self.chat_widget.handle_disconnected_view_key(*key);
|
||||
} else {
|
||||
self.chat_widget.handle_disconnected_key(*key);
|
||||
}
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
|
||||
match &event {
|
||||
TuiEvent::FocusLost => {
|
||||
let now = Instant::now();
|
||||
@@ -840,6 +865,15 @@ impl App {
|
||||
// [iTerm2]: https://github.com/gnachman/iTerm2/blob/5d0c0d9f68523cbd0494dad5422998964a2ecd8d/sources/iTermPasteHelper.m#L206-L216
|
||||
let pasted = pasted.replace("\r\n", "\n").replace('\r', "\n");
|
||||
self.chat_widget.handle_paste(pasted);
|
||||
if self.reconnect.offline
|
||||
&& self.reconnect.presentation
|
||||
== reconnect::ReconnectPresentation::Conversation
|
||||
{
|
||||
self.chat_widget.handle_disconnected_key(KeyEvent::new(
|
||||
KeyCode::Null,
|
||||
KeyModifiers::NONE,
|
||||
));
|
||||
}
|
||||
}
|
||||
TuiEvent::Draw | TuiEvent::Resume | TuiEvent::Resize(_) | TuiEvent::FocusGained => {
|
||||
if self.backtrack_render_pending {
|
||||
|
||||
Reference in new issue
Block a user