Repository navigation
refactor(terminal): one remote input hold - #27781
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to Remote PTY recovery can send queued keystrokes to a replacement generation, and a recoverable subscribe failure can leave an accepted write pending. Both risks are confined to recovery paths; track incarnation binding and failed-connect settlement before relying on those paths broadly. Pre-merge checks |
|
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:
27996dd3-6e08-4d63-a964-33c6ac6040a4
📒 Files selected for processing (8)
config/scripts/ci-shard-timings.jsonsrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/remote-reattach-input-buffer.test.tssrc/renderer/src/components/terminal-pane/remote-reattach-input-buffer.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport-reattach-type-ahead.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/renderer/src/components/terminal-pane/remote-runtime-recovery-input-hold.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-recovery-input-hold.ts
💤 Files with no reviewable changes (4)
- config/scripts/ci-shard-timings.json
- src/renderer/src/components/terminal-pane/pty-transport-types.ts
- src/renderer/src/components/terminal-pane/remote-reattach-input-buffer.test.ts
- src/renderer/src/components/terminal-pane/remote-reattach-input-buffer.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.
| // Why: typing on a restored screen reaches its original terminal only, never a fresh create. | ||
| async function connectHoldingRestoredInput( | ||
| options: Parameters<PtyTransport['connect']>[0] | ||
| ): Promise<PtyConnectResult | undefined> { | ||
| const expected = recoveryInputHold.expect(restoredInputEndpoint(options.sessionId)) | ||
| try { | ||
| return await connectPane(options) | ||
| } finally { | ||
| recoveryInputHold.settleExpectation(expected, handle !== null && !destroyed) | ||
| if (handle && recoveryInputHold.isHolding()) { | ||
| releaseHeldInput() | ||
| } | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1490,1645p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
sed -n '2640,2685p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
sed -n '2800,2880p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
sed -n '115,155p' src/renderer/src/components/terminal-pane/remote-runtime-recovery-input-hold.tsRepository: stablyai/orca
Length of output: 11264
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- wrapper references and connect entrypoints ---'
rg -n -F --glob '*.ts' -- 'connectHoldingRestoredInput' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
rg -n -F --glob '*.ts' -- 'connectPane(' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
printf '%s\n' '--- wrapper and connect body ---'
sed -n '2628,2690p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
sed -n '2790,2925p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
printf '%s\n' '--- hold implementation ---'
sed -n '1,175p' src/renderer/src/components/terminal-pane/remote-runtime-recovery-input-hold.ts
printf '%s\n' '--- lifecycle cleanup and recovery/retry callers ---'
rg -n -F --glob '*.ts' -e 'recoveryInputHold.discard' -e 'connect(' -e 'retry' -e 'recover' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts | sed -n '1,220p'Repository: stablyai/orca
Length of output: 27985
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- automatic recovery caller ---'
sed -n '950,1008p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
printf '%s\n' '--- lifecycle methods and retry caller ---'
sed -n '2918,3140p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
printf '%s\n' '--- accepted-input public path ---'
sed -n '2960,3035p' src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tsRepository: stablyai/orca
Length of output: 12492
Settle the input hold from the connect result.
connectPane returns undefined when creation fails or its lifecycle epoch becomes stale. The wrapper instead uses the earlier non-null handle as success. This can leave an accepted input promise pending until a later retry or cleanup. A ready but different endpoint causes the hold to discard the input, not send it to another terminal.
Use the current connect result as the bind condition.
Suggested fix
async function connectHoldingRestoredInput(
options: Parameters<PtyTransport['connect']>[0]
): Promise<PtyConnectResult | undefined> {
const expected = recoveryInputHold.expect(restoredInputEndpoint(options.sessionId))
+ let result: PtyConnectResult | undefined
try {
- return await connectPane(options)
+ result = await connectPane(options)
+ return result
} finally {
- recoveryInputHold.settleExpectation(expected, handle !== null && !destroyed)
+ recoveryInputHold.settleExpectation(expected, result !== undefined && !destroyed)
if (handle && recoveryInputHold.isHolding()) {
releaseHeldInput()
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Why: typing on a restored screen reaches its original terminal only, never a fresh create. | |
| async function connectHoldingRestoredInput( | |
| options: Parameters<PtyTransport['connect']>[0] | |
| ): Promise<PtyConnectResult | undefined> { | |
| const expected = recoveryInputHold.expect(restoredInputEndpoint(options.sessionId)) | |
| try { | |
| return await connectPane(options) | |
| } finally { | |
| recoveryInputHold.settleExpectation(expected, handle !== null && !destroyed) | |
| if (handle && recoveryInputHold.isHolding()) { | |
| releaseHeldInput() | |
| } | |
| } | |
| // Why: typing on a restored screen reaches its original terminal only, never a fresh create. | |
| async function connectHoldingRestoredInput( | |
| options: Parameters<PtyTransport['connect']>[0] | |
| ): Promise<PtyConnectResult | undefined> { | |
| const expected = recoveryInputHold.expect(restoredInputEndpoint(options.sessionId)) | |
| let result: PtyConnectResult | undefined | |
| try { | |
| result = await connectPane(options) | |
| return result | |
| } finally { | |
| recoveryInputHold.settleExpectation(expected, result !== undefined && !destroyed) | |
| if (handle && recoveryInputHold.isHolding()) { | |
| releaseHeldInput() | |
| } | |
| } |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Bind restored input to the known PTY incarnation. · remote-runtime-pty-transport.ts:1613-1617
src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts:1613-1617
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winBind restored input to the known PTY incarnation.
During same-handle recovery,
restoredInputEndpointreplaces the existing incarnation withnull. The hold treatsnullas a wildcard, so a provider result with the same handle and a new incarnation can match the held endpoint.releaseHeldInputthen flushes queued input to the replacement PTY generation instead of dropping it.Suggested fix
function restoredInputEndpoint(sessionId: string | undefined): RemoteRuntimeInputEndpoint | null { const restoredHandle = sessionId ? getRemoteRuntimeTerminalHandle(sessionId) : null return restoredHandle && toRemoteRuntimePtyId(restoredHandle, currentRuntimeEnvironmentId) === sessionId - ? { handle: restoredHandle, incarnationId: null } + ? { handle: restoredHandle, incarnationId: authoritativePtyIncarnationId } : null }
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
d4042b80-758f-4e1b-8846-d7f97fe4009c
📒 Files selected for processing (1)
src/renderer/src/components/terminal-pane/remote-runtime-recovery-input-hold.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.
ELI5
When Orca reopens a remote terminal it first paints the old screen, and you can start typing before the terminal is reconnected. Two separate pieces of code used to hold those keystrokes: one for "before the first connect finishes" and one for "while reconnecting". This PR keeps only the second one and teaches it the first one's job. Typing behaves the same; there is one less layer.
What Changed
remote-reattach-input-buffer.tswrapped every remote terminal connection. It buffered typing from the moment the terminal was created, kept it while the first connect ran, and sent it only if that connect came back attached to the same remote terminal id. Inside the transport, a second buffer (the recovery input hold) did the same job during reconnects.remote:<env>@@<handle>id. A fresh create, an id from another server or an old id without an owner drops it, as before. When the connect ends it is either kept for delivery, or dropped if no terminal bound.attach,disconnect,detachanddestroydrop it, as before. Delivery uses the hold's existing endpoint check: typing aimed at one terminal is never sent to a replacement terminal (fix(daemon): respawn on PTY write dropped to a dead daemon socket (STA-2373) #10065).setConnectForRecoveryhook onPtyTransportexisted only so the wrapper could intercept internal recovery connects. It is removed. Recovery connects now call the same holding connect directly.Why
There were two buffers with overlapping jobs and different rules: the wrapper compared terminal ids, while the hold compared endpoints. That meant two places to get the "never type into the wrong shell" rule right. Merging them into the hold, the one that already handles recovery, removes the wrapper and the
setConnectForRecoveryindirection. The reviewed design had a simpler version: seed the hold only at connect time. It was rejected because that drops typing made before connect starts. That is why the hold starts unbound when the transport is created and binds at the first connect.Net lines: production −13 (wrapper −90, transport +16, hold +63, transport types −2), tests +24 (wrapper suite −150, transport suite +158, hold suite +16). The tests grew because they now run against the real transport, and one new case covers typing after the host binds a terminal but before its first snapshot arrives. Production is smaller, which is the condition the design set for keeping this PR. The transport diff looks large because the connect body moved out of the object literal and was re-indented. Use
?w=1to review it.Dead-code proof:
rg "withRemoteReattachInputBuffer|remote-reattach-input-buffer|setConnectForRecovery"oversrc config tests mobile scripts .githubfinds no match. The@ts-nocheckfiles do not reference either symbol.pnpm run build:electron-vitepasses.Linked Issue
Phase 3.99 cleanup (item 2.5). Maintainer PR, no issue.
Visual Proof
N/A. There is no UI change, and the same keystrokes reach the same terminal.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
The wrapper's cases now run against the real transport (
remote-runtime-pty-transport-reattach-type-ahead.test.ts):attach,disconnect,detachanddestroysettle pending acknowledged writes as undelivered.New transport case (from review): typing between the host binding a terminal and that terminal's first snapshot reaches it only if it is the restored one. A replacement terminal never receives it.
New hold unit test: an older connect that was superseded cannot drop the newer connect's held typing.
Mutation check: disabling the unbound start, binding to the wrong endpoint, or skipping the drop each makes these specs fail.
pnpm teston allremote-runtime*,pty-preconnect*andpty-connection*specs: 128 files, 1079 tests pass.Also pass:
pnpm tc:web,oxlint,pnpm run check:code-quality:changed,pnpm lint,pnpm run build:electron-vite.Platforms: renderer-only logic with no platform branches. SSH-managed hosts use this same remote runtime transport, so the reattach behaviour is the same for them.
AI Disclosure
Review
Reviewed for P0/P1 issues by the author and by an independent codex reviewer (GPT-6.1 Sol, high).
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)