# Conversation lifecycle

1. **Connection ready**
2. **Visible transcript** requested first
3. **Bounded execution recovery** live deltas remain authoritative

| Owner | Owns |
| --- | --- |
| Transcript | The rows of each view, written only by the transcript reducer from reads, numbered updates and typed local changes; one read in flight per view; pagination, search targets, scroll anchors |
| Execution | Monotonic cursors and status versions; active task and approval identity. Snapshot recovery does not simulate a new terminal event |
| Composer | Session-owned draft, attachments, queued entries, acknowledgement. Navigation or disconnect never clears unacknowledged input |
| Connection generation | Timers, pending reads, fragment buffers. Obsolete responses cannot change a new connection or the visible session |
| Server | Authorization, execution, cancellation, approvals. No client optimization bypasses them |

Storage failures degrade persistence, not event delivery. No new execution runtime, remote service, account integration or history deletion belongs to this design.

## Transcript reads

| Aspect | Rule |
| --- | --- |
| Ownership | One pending initial or refresh request per session and connection. Navigation reuses it; a mutation invalidates it and keeps one replacement with the latest options |
| Replies | Each echoes its request ID. Expired, replaced and closed-connection replies are ignored |
| Deadline | 15 seconds; session-local loading, disconnected or failed state with a retry button; cached messages stay visible |
| No merge | A read replaces the server rows of the window it covers. While it runs, the server parks that view's updates and text frames and sends them after the reply, so a read never undoes newer progress. Local rows (sends, function placeholders, notices) and overlays survive it, and a local row goes when a read or update names its `clientRequestId`. There is no second transcript store |
| Invalid cursor | One cursor-free read around the reading anchor; failure is visible and retryable, and automatic paging stops |
| Explicit retry | Cursor-free anchor read keeping the branch head; a separate latest-history action when the anchor is gone |
| Safety | Loading transitions do not reset exponential retry delays. Read retries never repeat mutations, submissions, approvals or cancellations |

## Streaming

- Text and thinking frames coalesce into one animation-frame store update and are placed by offset into every view holding their row. A numbered update or a read flushes pending text first.
- Tools, steps, citations, status and terminal rows arrive as numbered `transcript_update` changes, the same rows a read draws.
- A text frame whose offset lies past the text the row holds shows a lost frame, and an update that does not follow the view's revision shows a missed one; either way the view reads once at its anchor.
- Connection close flushes received text before clearing which session each turn belongs to.
- Rendering primitives: bounded history windows, measured row recycling, lazy full tool output, independent follow locks.

## Recovery reads

Recovery reads request snapshot-only mode: the execution record and event cursor come from one SQLite transaction with no event bodies, since persisted streams can exceed 200 MB and the Web replay handler consumes only the snapshot. Explicit event-history clients keep full replay.

**The baseline that drove this**

| Measure | Value |
| --- | --- |
| Native refresh until transcript | 11–14 seconds |
| Direct initial history request | 0.18–0.20 seconds |
| Before the first history request | 16 recoveries processed; five history loads in one refresh |

The reconnect path sent every persisted cursor before the selected conversation, commands run serially per connection, replay snapshots entered the live update path and requested another transcript for terminal executions, and cursor storage synchronously persisted every frame. These are baseline figures, not claims about the optimized App.

## Resources during chat loading

Resource polling shares the worker with transcript hydration.

| Item | Rule |
| --- | --- |
| Reuse | Each resource-list request reuses one conversation graph, one predecessor index and memoized origin and branch-name results across all visible resources; the current-branch query may use one separate snapshot. They live only for that request |
| Authority | Visibility, execution attribution, control reconciliation and stable branch-reference selection stay authoritative |
| Result | Equivalent queries take 124–147 ms instead of 5,741–5,760 ms on the affected conversation (resource query only, not page load) |

## Acceptance

| Scenario | Required outcome | Evidence |
| --- | --- | --- |
| Open or reconnect (`useWS`) | Visible history requested before saved execution recovery. No replay-driven transcript storm. At most one recovery in flight; duplicates coalesce | Controlled transport tests; native cold and warm refresh timing |
| Switch A → B → A | The draft survives and A opens at its latest. Late A responses cannot replace B. Cached content stays during refresh | Rapid switching and delayed responses |
| Long history, paging, jump | Bounded reads and DOM, stable prepend anchor, stale cursor recovery, earliest message reachable, explicit retry | Large transcript, oldest, latest and search targets, interrupted paging |
| Streaming text and tools | Frame-batched; reading history is not interrupted by auto-follow. Expanded output loads on demand; completion flushes final deltas | Burst and delayed deltas, output expansion, long-content render budget |
| Send, queue, steer, stop | Input retained until acknowledgement; no duplicate on reconnect; explicit queued, sending or failed state; cancellation cannot revive the old turn | Disconnect before and after ACK, active queue, retry, cancellation |
| Approvals and questions | Waiting is distinct from generating. Reconnect restores waits. A stale answer cannot resolve a newer generation | Refresh during ask or approval; terminal cleanup |
| Background and nested work | Status recovers without resetting the foreground transcript or merging child history | Two-session and nested execution tests |
| Errors and accessibility | Visible, keyboard-accessible recovery; no false success, infinite spinner or lost draft; reduced motion and narrow layout usable | Transport faults, keyboard checks, native visual inspection |

**References**

| Reference | Behavior | OpenProgram |
| --- | --- | --- |
| [Codex App Server](https://developers.openai.com/codex/app-server/) | Separate stored thread reads, resume, paginated turns and items, notifications | Separate transcript and execution recovery ownership, on OpenProgram's protocol. Experimental pagination is a reference, not a dependency |
| [Claude Code interactive mode](https://code.claude.com/docs/en/interactive-mode) | Queued input, interrupt, editable queue, background tasks, prompt history | Drafts and attachments independent of connection and execution; delivery and approval state explicit |
| [Claude Code checkpointing](https://code.claude.com/docs/en/checkpointing) | Conversation and file restoration | Own branch and rewind semantics; viewing history never executes or rewinds |

Observable behavior and public protocols only, not private implementation or benchmark equivalence.

## Implementation status

| Part | Status |
| --- | --- |
| Implemented | Recovery ordering, snapshot-only reads, correlated history requests, visible retry, session-scoped streaming buffers, the resource projection, failed-reply details, streaming steer interruption, stopped-turn history retention |
| Automated coverage | Bounded large-history rendering, anchor restoration, failed cursor renewal and keyboard retry, peer-session isolation, draft and attachment ownership, queue receipts, stop and steer ordering, question remounts, IME, narrow layout and reduced motion |
| Installed App | Acceptance is a separate release requirement |
