Skip to content

Preserve terminal exit queries across snapshot restore - #34723

Merged
nwparker merged 5 commits into
mainfrom
nwparker/remote-codex-exit
Oct 28, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/remote-codex-exit

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​640 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​635
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​339 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​306

ELI5

Ctrl+C could leave Codex waiting for two seconds and allow a late terminal reply to spill into the shell. A live device-attributes query could disappear when a snapshot replaced queued output. Preserve that query and answer it once, in order.

What Changed

Recover snapshot-covered primary-device queries in the renderer through the existing configured reply handler after the terminal parse barrier. Preserve pending parser tails and suppress duplicate or retired-stream replies.

Keep server-owned stateless query debt when initial or requested multiplex snapshots cover pending output. Replay only owed occurrences, retain existing capability and mobile ownership rules, and settle debt only when output is actually sent. Use existing stream frames and bounded query inventory.

Why

Snapshots contain terminal cells but omit live query commands. A sequence cutoff previously discarded both the covered display bytes and the unanswered query. Replying before earlier terminal reports or injecting queries into an incomplete parser command would also be unsafe; the fix preserves ordering and parser state.

Linked Issue

Supplied remote-terminal report: slow Ctrl+C exit and terminal characters left afterward.

Visual Proof

Before: real paired terminal, Ctrl+C during an in-flight restore, snapshot covers the live query. No reply arrives; the raw fixture times out after 2002 ms.

Before covered exit query

After: identical controlled race receives the configured device-attributes reply in 42 ms total, approximately 23 ms after the test releases the snapshot. Restore generation stays unchanged and shell input still works.

After covered exit query

Real Codex 0.165.0 also exited to a clean shell and accepted a subsequent command. This is behavior evidence, not a measured latency result for the real CLI.

Real Codex clean shell

Testing

  • Independent review: 62 tests across seven focused suites passed, plus three real-xterm parser-state cases.
  • Red/green renderer and server regressions cover FIFO replies, split queries, duplicate ranges, stream retirement, CSI/OSC/DCS tails, configured ConPTY/Sixel replies, output ACK/pause recovery, and bounded replay occurrences.
  • Separate hidden Electron verifier exercised actual paired transport before/after, then clean shell input. Exact production files match the reviewed candidate.
  • Final-head CI: all 55 reported checks settled successfully, including Ubuntu, Debian, and Fedora WSL.
  • Required local ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --maxWorkers=2: 26/27 checks passed. The unit check had 545 passing suites and 7,264 passing tests; three cross-version suites timed out during shared release-source preparation. All three failed suites passed in the isolated retry: 55/55 tests with ORCA_DISABLE_SHARED_RELEASE_CACHE=1 and one worker. The initial failure log is retained.

Review

Work stays proportional to covered output, with the existing buffer caps, 4096-character scanner carry, and 16-entry yielded-query ledger. No new polling, timers, subprocesses, protocol opcodes, or resource owners. Snapshot-covered cursor-position queries remain suppressed. Folder workspaces and mobile reply ownership retain existing behavior.

Agent skill upstream boundary

  • No upstream skill-installer source was copied.

Notes

Runtime proof used macOS paired loopback. Native Windows/WSL/Linux and physical mobile were not exercised locally. Existing pending-output overflow and a snapshot retrieval that itself exceeds the CLI timeout are outside this retained-query fix. Targets main after #34721 was merged. The original parent commit includes that already-merged one-line test-import repair.

Checklist

  • Focused fix with independent review and before/after evidence.
  • Compatibility, ordering, cleanup, and performance reviewed.
  • Required local affected checks, scoped retry, and final-head CI complete.

@nwparker nwparker mentioned this pull request Oct 28, 2026
10 tasks done
@nwparker
nwparker changed the base branch from nwparker/remote-validation-test-import to main October 28, 2026 05:26
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b460451b-6597-49fe-bcd5-094ff410fb46
Commits

Reviewing files that changed from the base of the PR and between 77ab4c0 and b3b6fb8.

Files selected for processing: 1
  • src/renderer/src/components/terminal-pane/remote-snapshot-alt-screen-host-chain.test.ts
Walkthrough

The change adds DA1 query replay for multiplex snapshots and DA1 query handling during hidden-output restoration. Multiplex streams track yielded queries when output is discarded, replay matching queries covered by snapshots, and settle replayed queries after delivery. Hidden-output restoration scans covered output and schedules replies after terminal parsing. Startup and renderer handling use shared DA1 query sequences.

Priority: Normal

Merge Risk: Low · previous review 77ab4

Replay tests can pass on output the viewer discards, leaving a regression undetected. Correct the cutoff before relying on those tests.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the required change, rationale, testing, visual proof, compatibility notes, and checklist. However, the Linked Issue section provides only a report description a… Add the actual linked issue reference in the required format, such as Fixes #34722, or provide the applicable pre-existing issue number.
Docstring Coverage Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: preserving terminal exit queries during snapshot restoration.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed and covers the required change, rationale, testing, visual proof, compatibility notes, and checklist. However, the Linked Issue section provides only a report description and does not include an actual issue reference.

Resolution

Add the actual linked issue reference in the required format, such as Fixes #34722, or provide the applicable pre-existing issue number.

Full details: Docstring Coverage

Explanation

Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 16 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f89c676b-7562-41ba-af0a-e580dc2e4cf8
Commits

Reviewing files that changed from the base of the PR and between 66e2d39 and 7b50cc0.

Files selected for processing: 11
  • src/main/claude/claude-rewind-transcript.test.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-frame-delivery.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-initial-snapshot.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-slot-frames.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-yielded-queries.ts
  • src/main/runtime/rpc/terminal-multiplex-snapshot-query-replay.test.ts
  • src/main/runtime/rpc/terminal-output-frame-chunks.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts
  • src/renderer/src/components/terminal-pane/pty-connection/snapshot-covered-terminal-queries.test.ts
  • src/renderer/src/components/terminal-pane/terminal-capability-replies.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comment on lines +101 to +105
// Seq-less output survives the viewer's snapshot cutoff; retain host-only settlement until actually sent.
connection.queueOrSendOutput(stream, {
bytes: encodeTerminalStreamText(data),
displayLength: data.length,
replayedQuery: { seq: querySeq, data: query.data }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

set -eu
printf '%s\n' '--- yielded-query replay module ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-yielded-queries.ts | sed -n '1,180p'
printf '%s\n' '--- replay and snapshot helpers/callers ---'
rg -n -F --glob '*.ts' -e 'replaySnapshotCoveredStatelessQueries' -e 'getOutputAfterSnapshotSeq' -e 'serializeBudgetedRequestedSnapshot' -e 'sendAckRecoverySnapshot' -e 'ackPendingOutputOverflowed' -e 'queueOrSendOutput' -- src/main/runtime/rpc/methods/terminal src/main/runtime/rpc | head -200
printf '%s\n' '--- snapshot/replay caller definitions ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-stream-replay.ts | sed -n '1,180p'
printf '%s\n' '--- flow control ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-flow-control.ts | sed -n '1,180p'
printf '%s\n' '--- frame delivery ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-frame-delivery.ts | sed -n '1,180p'
printf '%s\n' '--- pause and cleanup ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-slot-frames.ts | sed -n '60,125p'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-cleanup.ts | sed -n '1,55p'

Repository: stablyai/orca

Length of output: 44318


Script executed:

set -eu
printf '%s\n' '--- slot-frame snapshot branch ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-slot-frames.ts | sed -n '145,275p'
printf '%s\n' '--- initial snapshot branch ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-initial-snapshot.ts | sed -n '90,155p'
printf '%s\n' '--- yielded-query registration callers ---'
rg -n -F --glob '*.ts' -e 'recordYieldedTerminalQueries' -e 'yieldedQueryScan' -e 'outputBatcher' -- src/main/runtime/rpc/methods/terminal | head -160
printf '%s\n' '--- stream initialization and output ingestion ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-stream-initialization.ts | sed -n '1,120p'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-output.ts 2>/dev/null | sed -n '1,220p' || true

Repository: stablyai/orca

Length of output: 19765


Preserve covered query debt across ACK recovery.

sendRequestedSnapshot replays covered queries before it queues the remaining live output. Under ACK backpressure, the replay chunk can enter ackPendingOutput first and then be removed by byte-budget trimming. Recovery sends the snapshot but does not replay or answer the query.

A retained numeric live chunk can then call settleDeliveredYieldedQueries(stream, chunk.seq). That removes the covered query because its sequence is below the live chunk, although the renderer never received the replay and main never called runtime.answerYieldedTerminalQueries. Track the recovery snapshot boundary and preserve covered query debt until the matching replay is sent or the debt is handed to answerUndeliveredYieldedQueries.


Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

set -u
printf '%s\n' '--- relevant tests and symbols ---'
rg -n -F --glob '*.{ts,tsx}' \
  -e 'replaySnapshotCoveredStatelessQueries' \
  -e 'answerSnapshotCoveredPrimaryDeviceAttributes' \
  -e 'replayDataCallback' \
  -e 'isReplaying()' \
  -e 'queueOrSendOutput' \
  -e 'replayedQuery' \
  -e 'primary device attributes' \
  src/main/runtime/rpc/methods/terminal src/renderer/src/components/terminal-pane 2>/dev/null || test "$?" -eq 1
printf '%s\n' '--- producer block ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-yielded-queries.ts | sed -n '70,125p'
printf '%s\n' '--- output routing declarations ---'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-frame-delivery.ts | sed -n '1,90p'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/transport-output-callbacks.ts | sed -n '70,110p'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/live-data-callback.ts | sed -n '135,190p'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-drain.ts | sed -n '30,65p'
nl -ba src/renderer/src/components/terminal-pane/pty-connection/write-pty-output-to-xterm.ts | sed -n '1,35p;95,140p'
nl -ba src/renderer/src/components/terminal-pane/replay-guard.ts | sed -n '95,120p;165,225p'
nl -ba src/renderer/src/components/terminal-pane/terminal-capability-replies.ts | sed -n '145,172p'

Repository: stablyai/orca

Length of output: 26427


Route replayed query output through the replay-guarded path.

When a covered DA1 matches the sole owner’s yielded query, replaySnapshotCoveredStatelessQueries queues it as ordinary Output. The renderer then parses it through writePtyOutputToXterm, so isReplaying() is false. The covered numeric chunk separately schedules answerSnapshotCoveredPrimaryDeviceAttributes() after its parse barrier. Both paths can send a reply for the same query.

Route only the synthetic replay frame through the existing replay-specific path, such as replayDataCallback/replayIntoTerminal. Preserve the covered-source reply.

…ed replays

- Mark yielded queries discarded when ACK overflow trimming, the recovery
  cutoff, or snapshot-buffer overflow drops their output unsent, and replay
  them after the covering snapshot (including the ACK recovery snapshot).
- Purge snapshot query replays and escape-tail frames still queued behind the
  ACK window when a newer snapshot is published, and put new replays at the
  head of the ACK queue so they follow their snapshot.
- Share isPrimaryDeviceAttributesQuerySequence across DA1 call sites.
- Move replayed-query settlement into settleReplayedYieldedQuery.
@nwparker
nwparker force-pushed the nwparker/remote-codex-exit branch from 7b50cc0 to a269ea4 Compare October 28, 2026 07:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a76db0e0-ba91-4192-9a0b-cde9c1ef928c
Commits

Reviewing files that changed from the base of the PR and between 7b50cc0 and a269ea4.

Files selected for processing: 13
  • src/main/daemon/startup-device-attributes-responder.ts
  • src/main/runtime/rpc/methods/terminal-stream-extraction-characterization.test.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-flow-control.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-frame-delivery.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-initial-snapshot.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-slot-frames.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-yielded-queries.ts
  • src/main/runtime/rpc/methods/terminal/terminal-stream-replay.ts
  • src/main/runtime/rpc/terminal-multiplex-snapshot-query-replay.test.ts
  • src/main/runtime/rpc/terminal-output-frame-chunks.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-output-restore-chunk.ts
  • src/renderer/src/components/terminal-pane/pty-connection/hidden-startup-renderer-query-write.ts
  • src/shared/terminal-reply-query-extraction.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 39fdf22c-5923-4816-995f-be8588e14e35
Commits

Reviewing files that changed from the base of the PR and between a269ea4 and 77ab4c0.

Files selected for processing: 3
  • src/main/runtime/rpc/methods/terminal-stream-extraction-characterization.test.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-flow-control.ts
  • src/main/runtime/rpc/terminal-multiplex-snapshot-query-replay.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

return frames
.slice(snapshotEnd + 1)
.filter((frame) => frame?.opcode === TerminalStreamOpcode.Output)
.filter((frame) => !frame?.seq || frame.seq > viewerCutoffSeq)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Use the latest snapshot sequence as the default cutoff.

Several replay tests call outputAfterLastSnapshot() without an argument. With a cutoff of zero, the helper counts a sequence-tagged DA1 query even when the latest snapshot covers it and the viewer drops it. Those tests can pass without a usable replay. Read the latest SnapshotStart payload’s seq by default; keep the explicit cutoff for the batched-query test. (raw.githubusercontent.com)

@nwparker
nwparker merged commit 8377149 into main Oct 28, 2026
117 of 120 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant