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
@@ -0,0 +1,37 @@
|
||||
//! Offline editing bypasses command dispatch and popup actions, retaining the draft in place.
|
||||
|
||||
use super::*;
|
||||
|
||||
impl ChatComposer {
|
||||
pub(crate) fn handle_disconnected_key(&mut self, key: KeyEvent) {
|
||||
self.cancel_history_search();
|
||||
self.attachments.clear_remote_image_selection();
|
||||
self.popups.active = ActivePopup::None;
|
||||
self.set_disable_paste_burst(/*disabled*/ true);
|
||||
// Expand in reverse order so remaining ranges stay valid. Textarea replacement
|
||||
// preserves the cursor and other elements, including images and mentions.
|
||||
let pending_pastes = std::mem::take(&mut self.draft.pending_pastes);
|
||||
if !pending_pastes.is_empty() {
|
||||
for element in self.draft.textarea.text_elements().into_iter().rev() {
|
||||
if let Some((_, text)) = pending_pastes.iter().find(|(placeholder, _)| {
|
||||
element.placeholder(self.draft.textarea.text()) == Some(placeholder.as_str())
|
||||
}) {
|
||||
self.draft
|
||||
.textarea
|
||||
.replace_range(element.byte_range.start..element.byte_range.end, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Enter/Tab and configured submit bindings must never consume the draft offline.
|
||||
// The basic editor reconciles attachments without invoking composer-level shortcuts.
|
||||
if !matches!(key.code, KeyCode::Enter | KeyCode::Tab)
|
||||
&& matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat)
|
||||
{
|
||||
self.handle_input_basic(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "reconnect_tests.rs"]
|
||||
mod tests;
|
||||
Reference in new issue
Block a user