Skip to content

fix(ssh): switching back to a quiet remote terminal no longer refetches its snapshot - #29253

Merged
nwparker merged 4 commits into
mainfrom
nwparker/remote-switch-no-snapshot
Oct 16, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/remote-switch-no-snapshot

Conversation

@nwparker

@nwparker nwparker commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you switch away from a remote (SSH) terminal, Orca asks the host to stop sending that terminal's output, which saves bandwidth. When you switched back, Orca always downloaded a fresh copy of the whole screen and its history, even if nothing had happened in that terminal. Over SSH that round trip is slow, so switching felt jittery. Now the host says whether it actually threw anything away while paused, and Orca only downloads the screen when something was really missed.

What Changed

Before (regression from #24863, shipped in 1.4.224): every switch back to a remote pane sent a snapshot request for 5000 rows (up to 2 MiB). It cost one round trip plus host serialization, even for a pane that printed nothing while hidden. Measured on orcad over SSH at 0 ms latency, an idle 20k-line pane cost 1 request and a ~35.6 KB reply (39–57 KB on the wire) per switch, plus a full clear-and-repaint. A live TUI (top) cost 3 requests per switch: the restore, then an untagged "resync" request that cleared and repainted the whole pane 180–420 ms after the switch, then a third restore at ~700–960 ms. 1.4.223 (relay) did zero of this for an idle pane.

After:

  • Switching back to a quiet pane: 0 snapshot requests and no repaint. Live output keeps writing straight to the screen.
  • Switching back to a pane that printed while hidden: 1 snapshot request and no untagged resync.

Measured per switch on the SSH repro rig. Client and orcad were both built from this branch, over Docker SSH, with a 50k-line idle pane and top -d 0.5, 3 rounds × 4 hot switches:

Case main (88bd5db) this branch
Idle pane, 0 ms 1 request, 35.5 KB snapshot, full clear, ~48 KB on the wire 0 requests, 0 snapshot bytes, 0 clears, 2–21 KB on the wire
Idle pane, 150 ms 1 request, 35.6 KB snapshot, ~48 KB on the wire 0 requests, 0 clears, 11–13 KB on the wire
top, 150 ms 3 requests (1 untagged resync), resync clear ~460 ms, third request ~960 ms 1 tagged request, 0 resyncs, snapshot ends at a median of 187 ms
New client + old host, 150 ms n/a Same as main: falls back to today's behaviour

On a real host (openclaw, ~27 ms RTT, client and orcad both built from this branch, compared with main 16eaceb):

  • Idle pane: 1 → 0 snapshot requests and 1 → 0 clears. Wire traffic per switch drops from 37–47 KB to 1.3–8 KB.
  • top: 3 requests (1 untagged) → 1 tagged, 0 untagged, with no late full-screen repaint. Clear writes drop 4 → 1, snapshot bytes 32 KB → 10.7 KB, and the snapshot ends 21–61 ms after the switch.

Out of scope here: a same-worktree tab switch after the pane was parked still pulls one snapshot (24–30 KB). That is the park-reveal path (#29269).

Mechanism:

  • The host already drops output for a paused stream. It now tracks whether a pause actually discarded anything: bytes arriving while paused, output still batched when the pause lands, or ack-queued output cleared by the pause. The first time that happens in a pause, it sends a new empty PausedOutputDropped frame (opcode 19).
  • The renderer no longer marks a restore as needed just because a pane paused, provided the host reports drops. It restores only when that frame arrives. The frame reaches the pane through the same markHiddenOutputRestoreNeeded / hidden-output-restore path as before, so a pane that is visible again when the frame arrives (a fast switch-back) still restores, and output that arrives during the restore still queues.
  • The client multiplexer also stops treating the announced jump in output position after resume as a lost frame. Before, that jump started the untagged resync snapshot and its full-screen clear. The exemption lasts until the next sequenced chunk, so a later real gap still resyncs.

Why

The host is the only side that knows whether bytes were lost, so the cheapest correct answer is for it to say so. Alternatives I considered:

  • Never pause hot remote panes: this brings back the hidden-pane bandwidth and CPU that pausing exists to remove, for every open remote tab.
  • Raise the client's expected position on every requested snapshot: the stall probe resolves through the same request path and compares against that position, so it would hide real stalls.
  • A longer foreground deadline: modern remote hosts are already exempt from the local 750 ms deadline (armHiddenOutputRestoreForegroundDeadline returns early when the transport has serializeBufferOutcome). The extra repaints came from the resync, not from that deadline.

Compatibility (clients and hosts update independently):

  • New client + old host: the client offers outputPauseDropNotice: 1, but the old host ignores the unknown capability and does not echo it. The client keeps today's behaviour: restore on every reveal, with the resync on a gap.
  • Old client + new host: the host sends opcode 19 only to a client that offered the capability, so old clients never see an unknown opcode. A frame from a host that never negotiated the capability is ignored.
  • Mobile clients and local or daemon panes are unaffected: mobile never offers the capability, and local panes do not use this pause path.

Linked: regression origin #24863 (old local prepaint path deleted in #27489).

Visual Proof

N/A. This is a network and repaint-timing change; see the measured table above.

Testing

  • src/renderer/src/components/terminal-pane/pty-connection-remote-pause-drop-notice.spec.ts (run via pty-connection-hidden-replay.test.ts) counts snapshot fetches per switch: 0 across three quiet switches, exactly 1 after a reported drop, and still 1 per reveal with an old host. The first two fail on main.

  • src/renderer/src/runtime/remote-runtime-terminal-paused-output-drop.test.ts: an announced pause gap sends no resync request, a later real gap still resyncs, and an unnegotiated frame is ignored.

  • src/main/runtime/rpc/terminal-multiplex-paused-output-drop.test.ts: the host sends the frame only when a pause really dropped output (including output still batched at pause time), once per pause, and never to a client that didn't negotiate it.

  • pnpm tc, pnpm run check:code-quality:changed, and the main/runtime/rpc, renderer/runtime, terminal-pane and shared suites. remote-snapshot-alt-screen-host-chain.test.ts and remote-runtime-pty-latched-pane-retention.test.ts time out locally on main as well.

  • I manually tested these changes locally (SSH repro rig with orcad over Docker SSH at 0 ms and 150 ms, including the old-host fallback)

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Cross-platform: no platform-specific code. SSH, orcad and Electron serve share this host code. Mobile is unaffected.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…es its snapshot

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The terminal protocol adds a negotiated PausedOutputDropped notice for output discarded during a pause. The renderer treats a reported pause gap as expected and forwards drop events to remote-pane restoration handling. Tests cover host notices, capability negotiation, expected gaps, and pane restoration behavior. The change also expands SSH worktree-listing tests and reformats other code and tests.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 98264

A narrow recovery sequence could miss a later terminal-output gap. Clear the stale expectation before merging, or accept the bounded risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.74% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 40 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly identifies the primary user-facing fix: quiet remote SSH terminals no longer refetch snapshots when revisited.
Description check Passed The description includes all required sections, explains the user impact and mechanism, documents compatibility and testing, and marks visual proof as not applicable. The full lint, typecheck, test, a…
  • Fix all pre-merge checks with AI
✨ 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.

nwparker and others added 3 commits October 15, 2026 16:35
… peers

Co-Authored-By: Claude <noreply@anthropic.com>
…h-no-snapshot

# Conflicts:
#	src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
…h-no-snapshot

# Conflicts:
#	src/renderer/src/runtime/remote-runtime-terminal-binary-controller.ts

@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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 81a14965-74d0-44e6-a483-6173e0618254
📥 Commits

Reviewing files that changed from the base of the PR and between 7d87863 and 98264b5.

📒 Files selected for processing: 14
  • src/main/ipc/worktrees-canonical-ssh-listing.test.ts
  • src/main/worktree-lineage-host-peers.ts
  • src/renderer/src/components/new-workspace/ComposerParentWorktreePicker.tsx
  • src/renderer/src/components/sidebar/DeleteWorktreeDialog.test.tsx
  • src/renderer/src/components/sidebar/agent-send-picker-collapse.test.tsx
  • src/renderer/src/components/sidebar/pinned-section-worktrees.test.ts
  • src/renderer/src/components/sidebar/pinned-section-worktrees.ts
  • src/renderer/src/components/sidebar/worktree-list/grouping/build-rows.ts
  • src/renderer/src/components/sidebar/worktree-list/grouping/cross-project-lineage.test.ts
  • src/renderer/src/components/sidebar/worktree-list/navigation/worktree-reveal-group-keys.ts
  • src/renderer/src/runtime/remote-runtime-terminal-binary-controller.ts
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer-implementation.ts
  • src/shared/project-section-grouping.ts
  • src/shared/resolved-worktree-lineage.test.ts

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

return
}
if (typeof seq === 'number' && !resyncInFlight) {
stream.pausedOutputGapExpected = false

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Trace the flag and recovery lifecycle. Confirm that recovery clears the flag,
# or that a notice cannot arrive while resync is in flight.
rg -n -C 5 '\bpausedOutputGapExpected\b|\bresyncInFlight\b|requestResyncSnapshot|recoverySnapshotSeq' \
  src/renderer/src/runtime \
  src/renderer/src/components/terminal-pane

Repository: stablyai/orca

Length of output: 26662


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- binary controller ---'
nl -ba src/renderer/src/runtime/remote-runtime-terminal-binary-controller.ts | sed -n '40,145p'
printf '%s\n' '--- snapshot application ---'
nl -ba src/renderer/src/runtime/remote-runtime-terminal-binary-snapshots.ts | sed -n '120,195p'
printf '%s\n' '--- resync request lifecycle ---'
nl -ba src/renderer/src/runtime/remote-runtime-terminal-snapshot-controller.ts | sed -n '40,90p'
printf '%s\n' '--- paused-output notice producers ---'
rg -n -C 8 -F -- 'PausedOutputDropped' src/main src/shared src/renderer || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 41826


🏁 Script executed:

set -euo pipefail
nl -ba src/renderer/src/runtime/remote-runtime-terminal-binary-controller.ts | sed -n '45,138p'
nl -ba src/renderer/src/runtime/remote-runtime-terminal-binary-snapshots.ts | sed -n '145,170p'
rg -n -C 10 -F -- 'PausedOutputDropped' src/main src/shared src/renderer || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 41961


Clear pausedOutputGapExpected when recovery sets a new sequence baseline.

A supported drop notice can arrive while resync is in flight. The recovery path clears resyncInFlight but not pausedOutputGapExpected. The next sequenced frame can then skip gap detection and accept a real gap.

Suggested fix
           stream.expectedSeq = typeof info?.seq === 'number' ? info.seq : undefined
+          stream.pausedOutputGapExpected = false
           stream.commandProbeBaselineSeq = undefined

@nwparker
nwparker merged commit 7306273 into main Oct 16, 2026
45 checks passed
nwparker added a commit that referenced this pull request Oct 16, 2026
…host (#29253)

Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>
nwparker added a commit that referenced this pull request Oct 16, 2026
…host (#29253)

Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>
nwparker added a commit that referenced this pull request Oct 16, 2026
…es it (#29342)

* fix(terminal): a reveal after hidden output was dropped always restores it

A restore that failed while its pane was hidden zeroed recovery and wrote
its loss banner where nobody could see it, so the reveal skipped the
restore and the gap stayed silent and permanent. Stay armed instead and
spend one fresh snapshot on reveal. Main's drop latch now retires on the
renderer's paint ack rather than on unhide, so a hidden pane that retires
cannot spend the only marker on a handler that is already gone.

Fixes #15504

Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>

* fix(terminal): dedupe a disclosed hidden-output loss by drop episode

The unhide marker carries main's emit-time output sequence, which visible
output advances without any new drop, so a seq comparison re-bannered the
same gap. Main now tags gate markers with a drop episode, and a drop after
an unhide starts a new episode that the in-flight restore's ack cannot
retire.

Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>

* fix(terminal): a restore ack retires only the drop episode it covered

An older restore still in flight when a newer hide/drop/reveal cycle ran
could ack and erase the newer episode's drop memory. The renderer now
captures the latest reported episode before fetching and names it in the
ack; main retires the latch only on a matching episode.

Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>

* test(terminal): pin hidden-restore recovery against a drop-reporting host (#29253)

Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>

---------

Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>
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