Repository navigation
fix(terminal): stop old output bleeding into Claude's screen when revisiting a remote tab - #24926
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughRemote snapshot replay now marks images that carry normal-buffer content. Recovery snapshots no longer clear scrollback, but they still clear the screen and move the cursor home. The replay drain uses a normal-buffer preamble for matching payloads and can preserve scrollback when the pane is on the alternate screen. New tests cover pushed snapshots, requested snapshots, and raw-byte replay. Priority: ➖ Normal Merge Risk: 🔵 Low · up to An undimensioned remote snapshot can leave incompatible terminal history visible. The narrow case is mergeable with owner awareness, though the grid check should be corrected. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is limited to restoring remote terminal displays, with safeguards against applying output to a replaced session. No new privileged operation was identified. A compatibility edge remains: recovery can preserve history without confirming that the snapshot and pane used matching dimensions. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 19 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Alt-screen-safe clear for pushed remote snapshots —
replay-data-drain.ts:135now grounds with the sharedbuildSnapshotReplayPrologue({ targetAlternateScreen: false, paneOnAlternateScreen })when the payload is aserializedImage, instead of clearing the active buffer in place. On a live alt screen this leaves alt, clears the normal buffer + scrollback, and lets the image's own?1049hre-enter a cleared alt. serializedImageprovenance flag — added toPtyReplayDataMeta(pty-transport-types.ts:68),ProcessPtyOutputOptions(pty-output-processor.ts:43), and set only on the remote-runtimeonSnapshotpush (remote-runtime-pty-transport.ts:2023); threaded throughreplayDataCallback(deferred-cold-restore-and-snapshot.ts:163). Renderer-only, no wire change.- Serialized-image fixtures/tests updated — four exact-match expectations now include
{ serializedImage: true }; the fixture callback type narrows toPtyReplayDataMeta. - New regression test —
pty-connection-alt-screen-pushed-snapshot.test.ts; registered in theterminal-output.scrollback-restorereliability gate.
I verified the load-bearing assumptions rather than trusting the description: the host composes pushed snapshots as scrollbackAnsi + rehydrateSequences + snapshotAnsi (so they start on the normal buffer) in serializeBudgetedMobileSnapshot / serializeBudgetedRequestedSnapshot, and headless-emulator.getSnapshot + splitTerminalSnapshotAnsi confirm the normal-history/?1049h/alt-frame shape. I also confirmed ?1049h re-entry clears the alt viewport in the pinned xterm (activateAltBuffer → _alt.fillViewportRows), so no stale alt cells survive. Finally, I reverted only the drain's production change and re-ran the new test: it reproduces the reported garble (SETUP-OUTPUT-5, NoTnoticePtoday) and passes with the fix restored, so the test is genuine coverage, not theatre.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
What changed since the prior pullfrog review (97d943b): the follow-up commits generalise the fix from the pushed-snapshot drain to every path that paints a folded remote image, and hand the clear to the drain.
- Provenance flag renamed and widened —
serializedImageis nowcarriesNormalBufferacrossPtyReplayDataMeta,ProcessPtyOutputOptions,PtyBufferSnapshot, andRemoteRuntimeSnapshotImage. It is now set on the pushedonSnapshotpath, the cancelled-shutdown replay handler, and the requested-snapshot resolution (remote-runtime-terminal-binary-snapshots.ts), so remote images are recognised on every painter. - Shared normal-buffer preamble — new
buildNormalBufferSnapshotPreamble({ paneOnAlternateScreen, keepScrollback? })centralisesABORT + buildSnapshotReplayPrologue({ targetAlternateScreen: false }); the drain andbuildMainModelSnapshotReplayWritesboth use it instead of hand-written clears. - Drain owns the clear, drains before reading the buffer — the drain now waits for queued output to parse before deciding
isPaneOnAlternateScreen(), and keeps the TUI's covered history viakeepScrollback: paneOnAlternateScreen(theESC[3Jdrop). - Hidden-restore/requested path grounded on normal —
buildMainModelSnapshotReplayWritestakes the normal-buffer branch forcarriesNormalBufferimages, not just!alternateScreen. - Recovery snapshot's baked-in clear removed — reduced to the latch release only; the drain's preamble now performs the clear and buffer/history choice.
- Regression test expanded —
remote-snapshot-alt-screen-replay.test.tscovers the pushed drain, the requested hidden-restore builder, and a raw SSH replay that must stay on alt; registered under theterminal-output.scrollback-restoregate.
I verified the delta rather than trusting the description. The pushed-image test is genuine coverage: reverting the drain's buildNormalBufferSnapshotPreamble to the old in-place clear makes it fail with the reported garble (SETUP-OUTPUT-9, Nocnotice today). I traced carriesNormalBuffer into the request path — serializeBufferOutcome returns the resolved image untouched (asserted in remote-runtime-snapshot-outcome.test.ts) and applyMainBufferSnapshot passes it straight to the builder — and confirmed desktop pushes/initial/recovery snapshots serialize at scrollbackRows: 0, which is what makes keepScrollback correct without duplicating history. Nine affected suites (119 tests) pass.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — this looks correct. One bit of stale documentation inline; a PR-description nit below.
Reviewed changes
The delta since the prior pullfrog review (6ed2396) is the recovery snapshot's own clear, split out of the earlier "drain owns the clear" change:
- Recovery prefix restored to clear the screen —
remote-runtime-terminal-binary-snapshots.tsagain emits${RELEASE_SYNCHRONIZED_OUTPUT}\x1b[2J\x1b[H${data}instead of the latch release alone. The\x1b[3Jstays dropped. This matters because consumers that paint a recovery image straight into xterm without a replay drain (subscribeToRuntimeTerminalDatafalls back towatcher(data)when noonSnapshotoption is set) have no drain prologue to clear the stale screen. - Recovery-prefix expectations updated — exact-match assertions in
remote-runtime-terminal-frame-drop-resync.test.ts,remote-runtime-pty-snapshot-source-grid.test.ts, andruntime-terminal-stream.test.tsnow pin\x1b[?2026l\x1b[2J\x1b[H.
I verified the delta rather than the description: the recovery image on the desktop path also reaches the drain's normal-buffer preamble (the onSnapshot handler sets carriesNormalBuffer: true unconditionally at remote-runtime-pty-transport.ts:2025), so the restored \x1b[2J\x1b[H is a redundant second screen clear there — harmless — while being the only clear for the drain-less consumers. All 4 affected suites (29 tests) pass on head.
ℹ️ Nitpicks
- The PR description's "Mechanism" bullet still says the recovery snapshot's prefix is "reduced to the latch release" and "the drain now owns the clear". At head
3e088e9the recovery prefix is${RELEASE}\x1b[2J\x1b[Hand only\x1b[3Jwas removed; the drain-less consumers are why. Worth a one-line update so the description matches the final code.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No new issues from the incremental change — the grid-match fix is sound; one stale comment below.
Reviewed changes
Reviewed the single commit since the prior pullfrog review (3e088e9): keeping the TUI-covered history only when the pane and the host image share a grid.
- Gated kept history on a grid match —
replay-data-drain.tsnow computesatSourceGridfrom the pane's pre-resize geometry and passeskeepScrollback: paneOnAlternateScreen && atSourceGrid, so a pushed screen-only image preserves the history it continues exactly, and otherwise clears it rather than reflowing into duplicated or dropped lines. - Hoisted
sourceGridabove the clear — resolved once beforeclearBeforeReplayso the match decision reads the pane's pre-resize grid while the later resize still owns the repaint geometry. - Rebuilt the alt-screen replay test around real resize events — the drain harness records
terminal.resizecalls and the expected buffers render athostRowsbefore resizing down; a new mismatched-grid case pins exact normal-buffer equality. - Collapsed
abortGapBeforeFirstWriteintobuildNormalBufferSnapshotPreambleand inline call sites interminal-snapshot-replay-paint.ts(behavior-preserving). - Widened
RemoteRuntimeMultiplexedTerminal.serializeBufferto returnRemoteRuntimeSnapshotImage | nullinstead of an inline shape.
Verified rather than trusting the description: reverting only keepScrollback to paneOnAlternateScreen makes the mismatched-grid test fail with duplicated history (SETUP-OUTPUT-0..4), so it is genuine coverage. All 10 affected suites (93 tests) pass at head and pnpm tc:web is clean.
ℹ️ Nitpicks
replay-data-drain.ts:122still says "the clear is grid-independent", but this commit makes the clear'skeepScrollbackdepend onatSourceGrid, so the clear is now grid-dependent. Rewording to say the clear must precede the resize because it reads the pane's pre-resize grid would keep the rationale accurate.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
bc49963a-493a-4b1e-b9ef-d8b119228db2
📒 Files selected for processing (6)
config/reliability-gates.jsoncsrc/renderer/src/components/terminal-pane/pty-connection/replay-data-drain.tssrc/renderer/src/components/terminal-pane/remote-snapshot-alt-screen-replay.test.tssrc/renderer/src/components/terminal-pane/terminal-snapshot-replay-paint.tssrc/renderer/src/runtime/remote-runtime-terminal-binary-snapshots.tssrc/renderer/src/runtime/remote-runtime-terminal-multiplexer-types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/runtime/remote-runtime-terminal-binary-snapshots.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the commit since the prior pullfrog review (4556566): keeping a live TUI's covered history only while the host is still on the alternate screen.
- Gated kept history on the host still running on alt —
replay-data-drain.tsnow requiresalternateScreen === truein addition topaneOnAlternateScreen && paneAtSourceGrid()beforekeepScrollback. Once the host's TUI exits, its shell has written past the pane's frozen history, so the image replaces it rather than leaving a gap above the host's screen. - Generalised the snapshot preamble helper —
buildNormalBufferSnapshotPreamblebecamebuildSnapshotReplayPreamble, taking the fullbuildSnapshotReplayProloguearguments so the normal-buffer and alt-buffer painters share one entry point, and theabortGapBeforeFirstWritewrapper was removed (behavior-preserving). - Added a regression test —
remote-snapshot-alt-screen-replay.test.tsgains "replaces history when the host has left the alt screen", registered under the existingterminal-output.scrollback-restoregate.
I verified the delta rather than the description. The new test is genuine coverage: removing only the alternateScreen === true term makes it fail with the old history retained above the host's screen (SETUP-OUTPUT-0..4), and it passes with the gate restored. The helper rename is behavior-preserving at all call sites, and all 5 tests in the alt-screen suite pass at head with a clean tree.
Not approving because a previously flagged nit remains open inline (runtime-terminal-stream.test.ts:595, stale "clears screen and scrollback" comment), unchanged by this commit.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the commit since the prior pullfrog review (46c4558): gating kept scrollback on the host's proof that the TUI exited, rather than on the alt-screen flag.
- Switched the kept-history gate to the shell-owner proof —
replay-data-drain.tsnow usespaneOnAlternateScreen && terminalOwner !== 'shell' && paneAtSourceGrid()forkeepScrollback, replacingalternateScreen === true. The daemon'sterminalOwneris'shell'only once the host has proven the shell is the foreground process; while a TUI runs it is revoked, so the normal buffer is frozen and the pane's history still continues the host screen on a shared grid. - Fixed a gate that could not fire during a live TUI —
decodeSnapshotInfo(remote-runtime-terminal-snapshot-state.ts:111) only surfacesalternateScreenwhen the host also reportsterminalOwner === 'shell', so the previousalternateScreen === trueterm disabled keep-scrollback in exactly the live-TUI case it was meant to protect. The owner proof has no such coupling. - Renamed and re-centred the regression test — the host-left-alt test became "replaces history once the host proves the TUI exited", passing
terminalOwner: 'shell', and the pushed-image/recovery metas dropped their now-unusedalternateScreen: true.
I verified the delta rather than the description. The new test is genuine coverage: removing only the terminalOwner !== 'shell' term makes it fail with the old history retained above the host's screen (SETUP-OUTPUT-0..4), and it passes with the gate restored. The gate only ever drops preserved scrollback, so it cannot alter the screen outcome. All 5 tests in the alt-screen suite pass at head with a clean tree.
Not approving because a previously flagged nit remains open inline (runtime-terminal-stream.test.ts:595, stale "clears screen and scrollback" comment), unchanged by this commit.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the commit since the prior pullfrog review (c02d142): keeping a live TUI's covered history only when the host image proves it shares the pane's grid.
- Required a proven source grid for kept history —
replay-data-drain.tschangedpaneAtSourceGrid()from!sourceGrid || (exact match)tosourceGrid !== null && exact match, so an image that does not report its capture grid can no longer keep the pane's history.resolvePositiveTerminalDimensionsreturns{ cols, rows } | null, so the!== nullnarrowing is the correct form. - Added a no-grid regression test —
remote-snapshot-alt-screen-replay.test.tsgains "replaces history when the host image has no grid", registered under theterminal-output.scrollback-restoregate. - Fixed the stale recovery-prefix comment —
runtime-terminal-stream.test.tsnow describes the recovery clear as screen-only, resolving the last open review thread. The assertion itself already pinned\x1b[2J\x1b[H.
I verified the delta rather than the description. The new test is genuine coverage: ablating only sourceGrid !== null makes it fail with the old history retained (SETUP-OUTPUT-0..4), and it passes with the gate restored. The 8 affected suites (99 tests) pass at head with a clean tree, and the previously open thread is now resolved. This is a deliberate tightening — an image with no grid has no proof its screen matches the pane, so replacing the history is the safe outcome, including on the shutdownReplayHandler path which threads no grid.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the commit since the prior pullfrog review (a5fa53e): a test-only addition that exercises the fix through the real host chain.
- Added
remote-snapshot-alt-screen-host-chain.test.ts— drives the real host runtime (OrcaRuntimeService), its shell-ownership proof, the ack-recovery publisher, the wire codec, the client multiplexer, and the remote transport; only the transport-to-paneonReplayDatahand-off is wired by the test. It covers a live TUI keeping the covered history on a shared grid, and history being replaced once the host proves the TUI exited. - Registered the suite under the existing
terminal-output.scrollback-restoregate — added to the gate command,testFiles, andassertionRefsinconfig/reliability-gates.jsonc.
I verified the new test can fail rather than trusting the description: setting keepScrollback: false in replay-data-drain.ts:146 makes the "keeps the covered history" case fail with SETUP-OUTPUT-0..4 dropped (expected [ 'SETUP-OUTPUT-5', …(5) ] to deeply equal [ 'SETUP-OUTPUT-0', …(10) ]), so it is genuine coverage, not theatre. Both new tests pass at head, pnpm tc:web and oxlint are clean on the new file, and check-reliability-gates.mjs passes (140 gates). No production code changed by this commit; the previously resolved stale-comment thread remains resolved.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
…apshot A remote terminal running a full-screen agent (Claude Code) could show old output (e.g. a setup script's pnpm log) interleaved with the agent's screen after switching back to the tab. The host's pushed snapshot is a serialized image that starts on the normal buffer and enters the alternate screen itself, but the replay drain cleared with ESC[2J without leaving alt. The image's history painted into the agent's screen, its own ?1049h was a no-op, and the agent's diff paints landed on top of the stale cells. The remote-runtime transport now marks snapshots as serialized images, and the drain grounds them with the shared snapshot prologue (switching to the normal buffer first). Raw byte replays (SSH relay ring buffers) keep the in-place clear.
…verywhere Review follow-ups: - Rename the flag to carriesNormalBuffer: what the painters rely on is that the image starts on the normal buffer and enters alt itself. - Hidden-output restore had the same bug for remote requested snapshots (history folded into data, alternateScreen set): the painter entered alt first and painted the normal buffer into the TUI's screen. Requested remote snapshots now carry the flag and take the normal-buffer start. - Flag pushed snapshots replayed after a cancelled shutdown too. - Pushed snapshots carry only the screen, so over a live TUI the drain keeps the normal-buffer history it covers instead of wiping it. - Read the pane's buffer after queued output parses. - Tests compare whole buffers against a fresh terminal, use production image shapes, and pin the raw-replay path with the same oracle.
The recovery prefix's own \x1b[3J ran after the drain's prologue and wiped the history the drain keeps under a live TUI. Keep only the latch release, which still makes an empty recovery snapshot non-empty so it is applied.
Consumers that write recovery snapshots straight into xterm (no replay drain) rely on the prefix clearing the stale screen. Restore \x1b[2J\x1b[H and drop only \x1b[3J, which wiped history the image does not carry.
The multiplexer prepends its own screen clear; replaying that exact payload pins that the prefix cannot wipe the history a TUI covers.
Second review follow-ups: - A pushed image carries only the host's screen; the pane's frozen history continues it exactly only on the same grid. On another grid keeping it duplicated or dropped lines, so the image replaces it there. - Tests replay the pane's writes and grid changes into a real terminal and compare whole buffers with the host, including a mismatched-grid case. - The split branch shares the normal-buffer preamble; drop the now single-use abort helper. - Type serializeBuffer as RemoteRuntimeSnapshotImage so the flag is carried by type, not by object pass-through. - Register the grid and raw-replay cases in the reliability gate.
…on alt The drain kept the pane's history whenever the pane was on the alt screen. If the host's TUI exited while the tab was hidden, the shell wrote past that history and the kept lines no longer continued the host's screen. Require the host's own alternateScreen too; an absent flag proves nothing, so the image replaces history as on main. Also: one buildSnapshotReplayPreamble for every first replay write, the drain's image and raw clears as separate branches (raw byte-identical to main, comment restored), and a single paneAtSourceGrid check.
The host sends alternateScreen only with terminalOwner 'shell', i.e. once it has proven the TUI exited, so `alternateScreen === true` never held for a live TUI and the drain wiped the history it should keep. Replace the history only once the host proves the TUI exited; tests now use production snapshot shapes. Move the relay-overlap comment into the raw-replay branch it describes.
An image without its grid cannot prove the pane's history continues its screen, so it now replaces history. Also update a stale recovery-prefix test comment.
…e and drain Hand-written replay meta hid a gate that production never satisfies. Drive the host's own emulator, ownership mirror, serializer and recovery publisher through the real wire, client parser, remote transport and pane drain, for a live TUI and after the host proves it exited.
f2e8c06 to
0458230
Compare
…story alone Keeping the pane's history by clearing only the normal screen assumed a pushed image carries no history, which the host does not guarantee: a 0-row push can reuse a concurrent requested capture, and its history then landed twice in scrollback. It also wiped history on a grid mismatch, where main kept it. When pane and image are both on alt, the image's normal part adds nothing (the normal buffers froze together), so paint only its alt payload after an alt-side clear, split at the host's own boundary (splitAtAlternateScreenEntry, now shared with the daemon). Any other image paints from the normal buffer. This drops keepScrollback, the owner and grid gates, and the recovery-prefix change, so history behaves exactly as on main.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the one commit since the last Pullfrog review (f2e8c06): repaint only the alternate-screen frame of a folded remote push over a live TUI, leaving history alone.
- Split the image structurally instead of gating kept history —
replay-data-drain.tsnow callsbuildFoldedImageReplayWrites, which splits a pushed image at its last?1049hand, when the pane is already on alt, writes only the alt payload after an in-place alt clear. The pane's normal buffer and history are left untouched on any grid. - Removed the grid/owner/alt-screen gates — the image containing a fold
?1049his itself the host's proof its TUI is still on alt (buildRehydrateSequencesemits it only whenmodes.alternateScreen), so the priorterminalOwner/alternateScreen/paneAtSourceGridconditions are redundant. This is what removes the mismatched-grid history duplication/drop. - Extracted
splitAtAlternateScreenEntryintosrc/shared— now shared with the daemon'ssplitTerminalSnapshotAnsi(behavior-identical; both usedlastIndexOf('\x1b[?1049h')). - Dropped
keepScrollbackfrombuildSnapshotReplayPrologue— no remaining callers; the clear is again purelytargetAlternateScreen-driven. - Re-added
\x1b[3Jto the recovery push prefix — the drain path drops it (it is part of the discardednormalAnsi) and the non-split preamble already clears scrollback, so it only restores the clear for drain-less consumers. - Reworked the alt-screen tests — the mismatched-grid case now asserts the pane's normal buffer is preserved, plus a history-unduplicated case and a TUI-started-while-hidden case; the host-chain suite drops its reliance on a hand-written meta.
I verified the touched suites pass at head (34 tests across the replay, host-chain, frame-drop-resync, and runtime-terminal-stream suites) and traced the split back to the host composition (scrollbackAnsi + rehydrateSequences + snapshotAnsi, with rehydrateSequences beginning with \x1b[?1049h), so alternateAnsi is self-contained under the grounding prologue. The changed tests compare whole normal buffers and alt viewports against real headless xterm renders, so painting the whole image or never splitting fails them rather than merely shifting output.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
Final-review follow-ups: a drain test where the TUI's ?1049h is still queued when the image arrives, and a transport test replaying a push buffered during a cancelled shutdown; each fails when its guard is removed. The requested-image test now names the exited-TUI case it covers, requestSnapshot shares the snapshot image type, and the clear comment no longer implies every clear drops scrollback.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the single commit since the prior pullfrog review (e79b0ba): regression tests that pin two guarantees the fix relies on, plus a stale-comment fix and a type cleanup.
- Pinned the post-parse buffer read —
remote-snapshot-alt-screen-replay.test.tsgains analternate-queuedharness mode and a test asserting the drain reads the pane's buffer only after a queued?1049hparses. I removed the productionawait waitForTerminalOutputParsed(...)and the test failed with the reported garble (SETUP-OUTPUT-5,NoTnoticePtoday), so it is genuine coverage rather than a tautology. - Pinned the cancelled-shutdown flag —
remote-runtime-pty-transport-snapshot-replay.test.tsasserts that a push buffered during a shutdown replays throughrestorePtyDataHandlersAfterFailedShutdownwithcarriesNormalBuffer: true. - Renamed and re-annotated the requested-image test to describe the exited-TUI
alternateScreen: true+carriesNormalBuffercase. - Behavior-neutral cleanup — reworded the
replay-data-drain.tsclear-rationale comment and collapsedrequestSnapshot's inline return type toRemoteRuntimeSnapshotImage | null.
Both touched test files pass at head (16 tests); the working tree is clean after reverting the mutation probe.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

ELI5
A terminal has two "pages": the normal page (your shell history) and a separate full-screen page that apps like Claude Code switch to. When you come back to a remote terminal tab, Orca redraws it from a snapshot sent by the remote machine. That snapshot says "write the normal page, then switch to the full-screen page and draw it". One redraw path erased the screen but never switched back to the normal page first, so the old shell output (e.g. a setup script's
pnpm installlog) got written onto Claude's page and showed through the gaps in Claude's text.What Changed
Before: in a remote workspace, run
claudein a tab that already has output (the Setup tab is the common case), switch to another workspace for a few minutes, then come back. For about a second, sometimes longer, old setup output is mixed into Claude's screen ("1.titem11.is3fine…"). It clears up only when a later correct redraw happens to arrive.After: coming back shows Claude's screen cleanly from the first frame.
Mechanism: a remote host's snapshot is a serialized terminal image with its normal buffer folded in: the normal screen (plus history, for requested snapshots), then
?1049h, then the full-screen frame. It only reproduces correctly when painted starting from the normal buffer. Two client paths painted it while still on the alternate screen:replay-data-drain.ts), used for snapshots the host pushes when a hidden tab resumes. It cleared withESC[2J ESC[3J ESC[H, which doesn't leave the alternate screen.buildMainModelSnapshotReplayWrites), used for snapshots the client requests. Its alt-screen branch entered alt first, assuming the history arrives separately; remote hosts fold it intodatainstead.In both cases the image's normal screen (old setup output) was painted into Claude's screen. The image's own
?1049hdid nothing because the pane was already on alt, and Claude's frame, which skips cells it believes are blank, was drawn on top.The changes:
carriesNormalBuffer. This is renderer-only metadata; nothing on the wire changes.?1049h, the same boundary the host uses (splitAtAlternateScreenEntry, now insrc/sharedand shared with the daemon).buildSnapshotReplayPrologueand paints the whole image. The pane's buffer is read only after queued output has parsed, so a still-queued?1049hcan't be missed.Why
?1049l. It isn't a no-op when already on the normal buffer: xterm still restores the saved cursor and swaps kitty keyboard flags.Linked Issue
N/A (maintainer).
Visual Proof
The same moment (~0.35 s after switching back to the tab), real Claude Code 2.1.288 in a remote Setup tab after a real
pnpm install:Testing
Real end-to-end repro: an isolated dev Orca host plus a paired dev Orca client (separate profiles and HOME), a repo whose
orca.yamlsetup runspnpm install, realclaudein that Setup tab, 6 minutes in a local workspace on the normal parking timers, then back. A write spy on the client's xterm recorded every write on return.e79b0ba): Claude running at the same and a different window size, 0 of 45 frames over ~4 s showed setup output, and history matched line for line before leaving, after returning, and after another turn. Claude exited while hidden: the pane returned on the normal page matching the host (54/54 lines). Plain shell (colors, wrapping, 237 rows of history) andlessmatched the host exactly. Every unique setup line appeared exactly once. The alternate-screen path was reached by forcing a stream re-subscribe on a mounted pane; a pane rebuilt after being unloaded starts on the normal page and takes the normal path, as on main.Host-to-pane test in
remote-snapshot-alt-screen-host-chain.test.ts: the host's own terminal emulator, ownership tracking, serializer and recovery publisher feed the real wire encoding, client parser, remote transport and pane drain, for a running app and after the app exited. Only the process check, the socket and the transport-to-pane hand-off are stubbed.Tests in
remote-snapshot-alt-screen-replay.test.tspaint onto a real headless xterm that sits on a dirty alternate screen above setup history, and compare whole buffers using production snapshot shapes:Each rule is pinned by a mutation: painting the whole image, never splitting, splitting on a normal-buffer pane, skipping the wait for queued output, or dropping the flag on the cancelled-shutdown replay each fails a test.
Registered under the existing
terminal-output.scrollback-restorereliability gate, whose oracle already names this case.src/renderer/src/components/terminal-paneandsrc/renderer/src/runtime: 6,541 tests pass.pnpm tc:web, oxlint,check:code-quality:changed, and the reliability-gate manifest check are clean.Two Opus reviews. The first found the hidden-restore path, the unflagged shutdown replay, and the history question. The second found that kept history duplicates or drops lines when grids differ. All addressed here.
Platforms: reproduced and verified with a macOS host and client. First reported against a Windows host, but the mechanism is host-independent: the bad clears are in the renderer, and Claude Code enters the alternate screen on Windows too (confirmed on the Windows box). I didn't run the paired repro against a Windows host because its network only allowed the production Orca port.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)