Skip to content

fix(remote): overlap a reveal's stream open with its create, and claim the viewport once - #29269

Merged
nwparker merged 14 commits into
mainfrom
nwparker/ssh-reveal-one-snapshot
Oct 16, 2026
Merged

nwparker merged 14 commits into
mainfrom
nwparker/ssh-reveal-one-snapshot

Conversation

@nwparker

@nwparker nwparker commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​170 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​170
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59

ELI5

When you switch back to a remote (SSH or paired) terminal that Orca had put to sleep, Orca has to reconnect to the remote machine. It was waiting for one step to finish before starting another unrelated one, and it told the remote machine "I'm the one viewing this terminal" several times in a row. Now the two steps overlap, and it says it once.

What Changed

The SSH consolidation (#24863, shipped in 1.4.224) moved SSH panes onto the paired remote-runtime connection. A pane that is parked (hidden more than 30 s, or outside the warm set) has its view and stream torn down, and revealing it rebuilds both.

Before, for a parked reveal:

  1. terminal.create (reattach), or terminal.resolvePane, takes 1 round trip.
  2. Then the shared terminal stream opens (terminal.multiplex, wait for ready), another round trip.
  3. Then the Subscribe goes out.
  4. On a real host the pane also sent 3–5 ClaimViewport + Resize pairs per reveal, all for the same grid.

After:

  1. The stream open runs concurrently with the create/resolve RPC, which saves one serial round trip before Subscribe.
  2. 1 ClaimViewport per reveal. A repeat claim of the same grid is dropped until the host answers. Any desktop-fit answer counts, whatever grid the host reports. A remote-desktop-fit hold (a peer took the pane), a mobile driver, a different grid having been sent, or 1 s passing all allow the next claim.

Mechanism:

  • RemoteRuntimeTerminalMultiplexer.prewarm() calls ensureConnected() and returns a release.
  • connectPane calls it before its host RPCs and releases it in finally, so a warm-up that nothing subscribed to (for example, after a failed create) closes itself.
  • remote-runtime-pty-transport.ts keeps unconfirmedClaim per stream. Every claim path (sendViewportUpdate and the subscribe-install replay) goes through it.

Why

  • Wire-safe: no protocol change. An older host or client sees the same frames, just fewer duplicate claims.

  • The duplicate claims came from three sources:

    • visibility resume plus the layout observer, one frame apart;
    • the subscribe-install replay;
    • xterm's refit after the host answered with desktop-fit at its target grid. The client used to read that grid as "different", re-arm, and claim again about 25 ms later.

    Deduping in the transport catches all three without touching the session callers that other in-flight PRs own.

  • Dropped: folding the reveal's snapshot into the Subscribe frame. It cut the reveal to 1 snapshot and about 30% fewer bytes, but on a real host the pushed image arrived about 50 ms later than main's parallel SnapshotRequest on a 50k-line pane. Parked remote reveal: fold the reveal snapshot into Subscribe without the ~50 ms host penalty #29344 records the data and the next steps.

Linked Issue

Part of the parked-SSH-pane reveal regression from #24863. Follow-up: #29344.

Visual Proof

N/A: this changes timing and wire traffic, not layout. Real-host numbers (openclaw, paired orcad, about 25 ms RTT, parked worktree reveal, client and host both built from this branch, compared with main on the same host) are in a comment below.

Testing

  • remote-runtime-pty-transport-reveal-round-trips.test.ts:

    • the stream open is already on the wire while terminal.create is pending;
    • a warm-up that nothing uses closes;
    • resume plus observer claims of the same grid produce 1 ClaimViewport and 1 Resize;
    • a different grid, a peer hold at the same grid, or a different resize in between all re-allow a claim;
    • a desktop-fit or idle/desktop-driver answer does not.
  • The existing remote transport suites pass, after one adjustment in stream-reconnect: the test now destroys once the pane is waiting on the stream alone.

  • pnpm tc and pnpm run check:code-quality:changed pass.

  • I manually tested these changes locally (Docker SSH and real-host repro harness)

  • 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

SSH, orcad and orca serve share this transport. Local panes are unaffected. No platform-specific code.

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)

@coderabbitai

coderabbitai Bot commented Oct 15, 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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8158262a-27ab-4ab3-9706-9da23465364f
📥 Commits

Reviewing files that changed from the base of the PR and between f8c2057 and 61b54ba.

📒 Files selected for processing: 4
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reveal-round-trips.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-stream-reconnect.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer-base.ts
📝 Walkthrough

The remote terminal transport now prewarms eligible multiplexed connections and releases the prewarm handle when connection setup exits. It also tracks unconfirmed viewport claims by stream and grid, suppresses matching repeats within a 1,000 ms window, and clears pending claims for specified fit and driver changes. New tests cover subscription timing, cleanup, duplicate claims, and claim retries.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to f8c20

An optional snapshot failure can still interrupt a remote terminal subscription, and a failed viewport claim can briefly delay resizing. Resolve these issues before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
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. Analyzed 20 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the two primary changes: overlapping the reveal stream open with creation and suppressing duplicate viewport claims.
Description check Passed The description is complete and aligned with the template. It explains the user impact, changes, rationale, linked issue context, testing, visual-proof exception, and compatibility considerations. The…
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.
✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 57ccb67b-01e2-459c-adc2-0c06f24528b0
📥 Commits

Reviewing files that changed from the base of the PR and between 93095c2 and 9f3faa3.

📒 Files selected for processing: 18
  • src/main/runtime/rpc/methods/terminal/stream-schemas.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-initial-snapshot.ts
  • src/main/runtime/rpc/methods/terminal/terminal-snapshot-payload.ts
  • src/main/runtime/rpc/methods/terminal/terminal-stream-types.ts
  • src/main/runtime/rpc/terminal-multiplex-subscribe-requested-snapshot.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reveal-round-trips.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-stream-reconnect.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
  • src/renderer/src/runtime/remote-runtime-subscribe-snapshot.test.ts
  • src/renderer/src/runtime/remote-runtime-terminal-binary-controller.ts
  • src/renderer/src/runtime/remote-runtime-terminal-binary-snapshots.ts
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer-base.ts
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer-implementation.ts
  • src/renderer/src/runtime/remote-runtime-terminal-multiplexer-types.ts
  • src/renderer/src/runtime/remote-runtime-terminal-snapshot-controller.ts
  • src/renderer/src/runtime/remote-runtime-terminal-snapshot-state.ts

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

Comment on lines +73 to +79
/** Opens the shared stream while the caller's create RPC is in flight, so the two round trips
* overlap. The returned release closes it again if the caller never subscribed. */
prewarm(): () => void {
void this.ensureConnected().catch(() => {})
return () => this.closeIfIdle()
}

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.

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- connectPane prewarm and cleanup ---'
nl -ba src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts | sed -n '2790,2860p;2990,3075p'
printf '%s\n' '--- multiplexer base ---'
nl -ba src/renderer/src/runtime/remote-runtime-terminal-multiplexer-base.ts | sed -n '60,135p;195,225p'
printf '%s\n' '--- subscribeTerminal implementation ---'
nl -ba src/renderer/src/runtime/remote-runtime-terminal-multiplexer-implementation.ts | sed -n '1,55p;125,190p'
printf '%s\n' '--- prewarm and connectPane references ---'
rg -n -F --glob '*.ts' -e '.prewarm(' -e 'connectPane(' src/renderer/src

Repository: stablyai/orca

Length of output: 21082


Keep concurrent prewarm calls alive until all callers release them.

If two connectPane calls prewarm the same environment before either subscribes, the first failed call runs its finally callback while streams.size is still zero. closeIfIdle() then clears the shared connectPromise. The surviving call later creates a replacement subscription, so the prewarm overlap is lost and the shared subscription can be started twice.

Track prewarm ownership separately from subscribed streams, and close the multiplexer only after all prewarm callers release it.

@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: bc9a83bc-f542-41f5-9c70-61f60d9e8522
📥 Commits

Reviewing files that changed from the base of the PR and between 9f3faa3 and 3735b41.

📒 Files selected for processing: 5
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-initial-snapshot.ts
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-subscribe-frame.ts
  • src/main/runtime/rpc/terminal-multiplex-subscribe-requested-snapshot.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reveal-round-trips.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.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.

Comment on lines +68 to +69
const requested = await (earlyImage ??
serializeBudgetedRequestedSnapshot(runtime, ptyId, requestedScrollbackRows))

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Fall back when requested-image serialization rejects.

If serializeBudgetedRequestedSnapshot rejects, serializeInitial never reaches serializeBudgetedMobileSnapshot. The subscribe handler then detaches the stream and reports an error. Treat a requested-image failure as an unavailable image so the default snapshot can still serve the subscription.

@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: 2bc977f7-c8b0-476d-9111-4d5657ba5a95
📥 Commits

Reviewing files that changed from the base of the PR and between 3735b41 and 6893d74.

📒 Files selected for processing: 2
  • src/main/runtime/rpc/methods/terminal/terminal-multiplex-subscribe-frame.ts
  • src/main/runtime/rpc/terminal-multiplex-subscribe-requested-snapshot.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.

if (early && earlyRequestedImage) {
// Why: a SnapshotRequest was answered while viewport registration still awaited; the
// served image must not wait on it either, or a long-history reveal pays it serially.
earlyPublication = publishMultiplexInitialSnapshot(

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 | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect whether activation reconciles geometry after viewport registration.
rg -n -C 12 --type ts \
  'activateMultiplexStream|subscribeToTerminalResize|updateViewportForClient|lastResizeCols' \
  src/main/runtime/rpc/methods/terminal

Repository: stablyai/orca

Length of output: 41899


🏁 Script executed:

set -e
for spec in \
  'src/main/runtime/rpc/methods/terminal/terminal-multiplex-subscribe-frame.ts:1,100' \
  'src/main/runtime/rpc/methods/terminal/terminal-multiplex-stream-initialization.ts:1,180' \
  'src/main/runtime/rpc/methods/terminal/terminal-multiplex-live-stream.ts:1,180' \
  'src/main/runtime/rpc/methods/terminal/terminal-multiplex-initial-snapshot.ts:1,240' \
  'src/main/runtime/rpc/methods/terminal/terminal-viewport-update.ts:1,180'; do
  file=${spec%%:*}; range=${spec#*:}
  echo "===== $file:$range ====="
  nl -ba "$file" | sed -n "${range}p"
done

Repository: stablyai/orca

Length of output: 26131


🏁 Script executed:

set -e
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-live-stream.ts | sed -n '1,150p'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-viewport-update.ts | sed -n '1,140p'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-multiplex-initial-snapshot.ts | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 15524


Send a geometry update after the early snapshot.

startRequestedInitialSnapshot starts before initializeMultiplexStream awaits viewport registration. Initialization clears pendingRemoteDesktopViewport and applies it before activation. If that application resizes the PTY after sendSnapshotFrames completes, activation cannot observe the resize. Its parked-viewport block is skipped because the pending viewport is already null, and lastResizeCols still contains the snapshot width. Send a Resized frame for the current geometry after registration.

@nwparker nwparker changed the title fix(ssh): a parked remote pane's reveal needs one snapshot and one fewer round trip fix(remote): overlap a reveal's stream open with its create, and claim the viewport once Oct 16, 2026
@nwparker

Copy link
Copy Markdown
Contributor Author

Real-host measurement (openclaw, paired orcad, about 25 ms RTT, 6 parked worktree reveals, client and host both built from 398a02a, compared with main 16eaceb on the same host and harness). Times are ms from the switch.

main this PR
ClaimViewport per reveal 3–5 1
Seq pane (50k lines): Subscribe → SnapStart → SnapEnd 58–71 → 67–82 → 67–82 61–66 → 68–75 → 68–76
TUI pane: Subscribe → SnapEnd 57–65 → 63–73 48–65 → 60–79
Snapshot groups / SnapshotRequest 2 / 1 2 / 1 (unchanged)
Wire (seq / TUI) 72–83 / 30–34 KB 71–82 / 30 KB

No latency regression on either pane type.

@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: 0425ab75-8073-4ace-a8ea-eae4d873aab0
📥 Commits

Reviewing files that changed from the base of the PR and between 6893d74 and f8c2057.

📒 Files selected for processing: 2
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reveal-round-trips.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.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.

nextStream.claimViewport(desiredViewport.cols, desiredViewport.rows)
if (!isUnconfirmedClaim(nextStream, desiredViewport.cols, desiredViewport.rows)) {
nextStream.claimViewport(desiredViewport.cols, desiredViewport.rows)
unconfirmedClaim = { stream: nextStream, ...desiredViewport, sentAt: Date.now() }

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:

set -eu
printf '%s\n' '--- cited block ---'
nl -ba src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts | sed -n '2560,2665p'
printf '%s\n' '--- claimViewport definitions and references ---'
rg -n -F --glob '*.ts' -e 'claimViewport' -e 'unconfirmedClaim' src/renderer/src/components/terminal-pane src/renderer/src | sed -n '1,220p'
printf '%s\n' '--- implementation context ---'
rg -n -F --glob '*.ts' 'class RemoteRuntimeMultiplexedTerminal' src/renderer/src

Repository: stablyai/orca

Length of output: 25593


🏁 Script executed:

set -eu
printf '%s\n' '--- transport claimViewport implementation ---'
nl -ba src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts | sed -n '1828,1920p'
printf '%s\n' '--- stream claimViewport implementation ---'
nl -ba src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts | sed -n '3140,3215p'
printf '%s\n' '--- multiplexer claimViewport implementation ---'
nl -ba src/renderer/src/runtime/remote-runtime-terminal-multiplexer-implementation.ts | sed -n '70,125p'
printf '%s\n' '--- false-return tests and stream lifecycle context ---'
nl -ba src/renderer/src/runtime/remote-runtime-terminal-stale-stream-frames.test.ts | sed -n '55,95p'
nl -ba src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts | sed -n '2515,2560p'

Repository: stablyai/orca

Length of output: 13270


🏁 Script executed:

set -eu
printf '%s\n' '--- multiplexer sendFrame and stream lifecycle ---'
rg -n -F --glob '*.ts' -e 'sendFrame(' -e 'isRegisteredStream' -e 'closeStream' -e 'subscribe' src/renderer/src/runtime/remote-runtime-terminal-multiplexer-implementation.ts
nl -ba src/renderer/src/runtime/remote-runtime-terminal-multiplexer-implementation.ts | sed -n '1,75p'
nl -ba src/renderer/src/runtime/remote-runtime-terminal-multiplexer-implementation.ts | sed -n '125,245p'

Repository: stablyai/orca

Length of output: 6601


🏁 Script executed:

set -eu
printf '%s\n' '--- binary controller sendFrame ---'
rg -n -F --glob '*.ts' -e 'class RemoteRuntimeTerminalBinaryController' -e 'sendFrame' src/renderer/src/runtime/remote-runtime-terminal-binary-controller.ts
nl -ba src/renderer/src/runtime/remote-runtime-terminal-binary-controller.ts | sed -n '1,240p'

Repository: stablyai/orca

Length of output: 7506


🏁 Script executed:

set -eu
printf '%s\n' '--- sendFrame declaration ---'
rg -n -F --glob '*.ts' -e 'sendFrame' src/renderer/src/runtime | sed -n '1,160p'
printf '%s\n' '--- controller hierarchy ---'
rg -n -F --glob '*.ts' -e 'class RemoteRuntimeTerminalBinarySnapshots' -e 'extends RemoteRuntimeTerminal' -e 'protected send' src/renderer/src/runtime | sed -n '1,200p'

Repository: stablyai/orca

Length of output: 3786


🏁 Script executed:

set -eu
nl -ba src/renderer/src/runtime/remote-runtime-terminal-multiplexer-base.ts | sed -n '1,210p'

Repository: stablyai/orca

Length of output: 9542


Record the claim only when the stream reports success.

nextStream.claimViewport returns false when either frame send fails. This branch still records unconfirmedClaim, so a same-grid retry can be suppressed for up to one second after a failed claim operation.

🐛 Suggested fix
--- "a/src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts"
+++ "b/src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts"
@@ -2618,8 +2618,9 @@
     // Why: a viewport change during the subscribe round-trip hit the no-op one-shot fallback; replay the latest viewport so the PTY isn't stuck at subscribe-time size.
     if (pendingViewportClaim && desiredViewport) {
       if (!isUnconfirmedClaim(nextStream, desiredViewport.cols, desiredViewport.rows)) {
-        nextStream.claimViewport(desiredViewport.cols, desiredViewport.rows)
-        unconfirmedClaim = { stream: nextStream, ...desiredViewport, sentAt: Date.now() }
+        if (nextStream.claimViewport(desiredViewport.cols, desiredViewport.rows)) {
+          unconfirmedClaim = { stream: nextStream, ...desiredViewport, sentAt: Date.now() }
+        }
       }
     } else if (
       desiredViewport &&

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