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:
Eric Traut authored and copyberry committed 2026-08-31 21:00:25 +00:00
1 parent b51b07785b
commit a7913390f7
35 files changed
+987 -38

No files matched your search

@@ -0,0 +1,28 @@
---
source: tui/src/app/tests/disconnect_tests.rs
expression: "render_bottom_popup(&app.chat_widget, 100)"
---
Agent command center
Disconnected — agent list is stale
────────────────────────────────────────────────────────────────────────────────────────────────
│
│
│
│
│
│
│
│
│
│
│
│
│
│
│
│
│
│
│
New task › task draft!
ctrl+c quit · actions paused until the list is refreshed
@@ -0,0 +1,14 @@
---
source: tui/src/app/tests/disconnect_tests.rs
expression: "format!(\"{}\\n{}\",\nlines_to_single_string(&app.transcript_cells.last().unwrap().display_lines(80)),\nrender_bottom_popup(&app.chat_widget, 80))"
---
■ Connection lost.
• Connection lost — copy your draft, then relaunch (0s)
• Queued follow-up inputs
↳ queued before disconnect
⌥ + ↑ edit last queued message
› keep this draft!
ctrl+c quit
@@ -0,0 +1,20 @@
---
source: tui/src/app/tests/disconnect_tests.rs
expression: draft
---
queued before disconnectcopied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text copied text copied text
copied text copied text copied text copied text