Repository navigation
fix(remote): overlap a reveal's stream open with its create, and claim the viewport once - #29269
Conversation
|
Warning Review limit reachedYou'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. View limit details
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
…a peer hold re-arms a claim
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:
57ccb67b-01e2-459c-adc2-0c06f24528b0
📒 Files selected for processing: 18
src/main/runtime/rpc/methods/terminal/stream-schemas.tssrc/main/runtime/rpc/methods/terminal/terminal-multiplex-initial-snapshot.tssrc/main/runtime/rpc/methods/terminal/terminal-snapshot-payload.tssrc/main/runtime/rpc/methods/terminal/terminal-stream-types.tssrc/main/runtime/rpc/terminal-multiplex-subscribe-requested-snapshot.test.tssrc/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reveal-round-trips.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-stream-reconnect.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/renderer/src/runtime/remote-runtime-subscribe-snapshot.test.tssrc/renderer/src/runtime/remote-runtime-terminal-binary-controller.tssrc/renderer/src/runtime/remote-runtime-terminal-binary-snapshots.tssrc/renderer/src/runtime/remote-runtime-terminal-multiplexer-base.tssrc/renderer/src/runtime/remote-runtime-terminal-multiplexer-implementation.tssrc/renderer/src/runtime/remote-runtime-terminal-multiplexer-types.tssrc/renderer/src/runtime/remote-runtime-terminal-snapshot-controller.tssrc/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.
| /** 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() | ||
| } | ||
|
|
There was a problem hiding this comment.
🚀 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/srcRepository: 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.
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:
bc9a83bc-f542-41f5-9c70-61f60d9e8522
📒 Files selected for processing: 5
src/main/runtime/rpc/methods/terminal/terminal-multiplex-initial-snapshot.tssrc/main/runtime/rpc/methods/terminal/terminal-multiplex-subscribe-frame.tssrc/main/runtime/rpc/terminal-multiplex-subscribe-requested-snapshot.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reveal-round-trips.test.tssrc/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.
| const requested = await (earlyImage ?? | ||
| serializeBudgetedRequestedSnapshot(runtime, ptyId, requestedScrollbackRows)) |
There was a problem hiding this comment.
🩺 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.
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:
2bc977f7-c8b0-476d-9111-4d5657ba5a95
📒 Files selected for processing: 2
src/main/runtime/rpc/methods/terminal/terminal-multiplex-subscribe-frame.tssrc/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( |
There was a problem hiding this comment.
🎯 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/terminalRepository: 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"
doneRepository: 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.
|
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.
No latency regression on either pane type. |
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:
0425ab75-8073-4ace-a8ea-eae4d873aab0
📒 Files selected for processing: 2
src/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reveal-round-trips.test.tssrc/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() } |
There was a problem hiding this comment.
🎯 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/srcRepository: 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 &&
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:
terminal.create(reattach), orterminal.resolvePane, takes 1 round trip.terminal.multiplex, wait forready), another round trip.After:
desktop-fitanswer counts, whatever grid the host reports. Aremote-desktop-fithold (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()callsensureConnected()and returns a release.connectPanecalls it before its host RPCs and releases it infinally, so a warm-up that nothing subscribed to (for example, after a failed create) closes itself.remote-runtime-pty-transport.tskeepsunconfirmedClaimper stream. Every claim path (sendViewportUpdateand 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:
desktop-fitat 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
SnapshotRequeston 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:terminal.createis pending;desktop-fitor 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 tcandpnpm run check:code-quality:changedpass.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
Notes
SSH, orcad and
orca serveshare this transport. Local panes are unaffected. No platform-specific code.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)