Repository navigation
fix(ssh): keep keystrokes typed while a restored SSH terminal reattaches - #24166
Conversation
A restored SSH pane that remounts takes keyboard focus as soon as its new xterm mounts, but its transport only binds once the relay answers the reattach. Keys typed in that window were refused by the transport and lost, so the start of a command vanished while the rest ran against the live shell. Buffer input on SSH panes that reattach to an existing PTY and flush it in order once the reattach binds. If the reattach fails or the pane falls back to a fresh shell, drop the buffered keys with a console warning instead of typing them into a replacement shell. Co-Authored-By: Claude <noreply@anthropic.com>
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- SSH reattach type-ahead — a restored SSH pane now sets
bufferInputUntilConnect, so keys typed during the relay round trip are held instead of refused, then flushed in order once the reattach binds. - Reattach-only predicate —
buffersInputOnlyForSshReattachenables this only for SSH panes that already have a PTY identity (restored leaf id, tabptyId, or deferred session id), leaving fresh spawns and split-pane cwd waits on their existing behavior. - Fresh-spawn safeguard — a fallback fresh shell abandons the held keys so they cannot run in the replacement shell, warning once via the new
hasPendingInput/dropPreconnectInputpath. - Tests — a new end-to-end IPC test covers in-order delivery after reattach and the drop-with-warning path; I confirmed both fail when the predicate is forced off.
This is renderer-only and reuses the transport's existing bounded pre-connect buffer, so there is no wire change and remote-runtime/local panes are untouched. The failure path is safe: main's SSH reattach either binds to the same shell or returns sessionExpired without binding, so flushPreconnectInput sees !connected and drops rather than delivering to a replacement shell.
Two non-blocking observations, neither actionable: the new drop warning also fires for the pre-existing local split-pane cwdPromise not-attached case (previously silent), and SSH now uses a different implementation than remote-runtime's withRemoteReattachInputBuffer for the same "buffer typeahead on a restored screen" guarantee.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughRestored SSH panes now buffer input while reattachment is pending. The connection setup identifies sessions that buffer input only for reattachment, and the input buffer reports queued or in-flight input. If reattachment fails and a fresh spawn begins, the code abandons that input. The transport warns and clears pending input on failed attachment or abandonment, and clears it silently when destroyed. Tests check that input is not written before reattachment, that writes retain order after reattachment, and that dropped input produces a warning when the PTY is missing. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue is identified. Restored SSH input is buffered during reattachment and discarded rather than forwarded to a replacement shell; merge after normal checks pass. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Normal reconnection and explicit replacement paths protect buffered keystrokes. However, another recovery path can bind a replacement shell before checking whether the buffered commands belong to it. This creates a potential wrong-shell replay risk, although broader access or privilege escalation has not been demonstrated. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |

ELI5
After Orca restarts, a remote (SSH) terminal reconnects to the shell it already had. For a moment while it reconnects, the terminal already has keyboard focus but isn't wired to the shell yet. Whatever you typed in that moment was thrown away, so the start of your command disappeared and only the rest ran. Now those keys are held and sent, in order, as soon as the terminal is wired up.
What Changed
Before: a restored SSH terminal that gets rebuilt while reconnecting (it is remounted with a fresh terminal view) grabs focus right away, but its connection only becomes usable after the remote relay answers the reattach. Keys typed in that ~tens of milliseconds were refused and silently dropped. With
printf '...' > file; printf MARKERthe shell received'...' > file; printf MARKER— the marker printed, the file was never written (the e2essh-cold-activation-restore.spec.ts:209flake:readRemoteProof(...)→null, losingprintforprin).After: those keys are held and delivered in the order they were typed once the pane reattaches to the same remote shell.
Mechanism: the renderer's IPC terminal transport already has a bounded pre-connect input buffer (
bufferInputUntilConnect, used by split panes waiting on a working directory). It is now also turned on for SSH panes that are going to reattach to an existing PTY (a restored leaf PTY id, the tab's PTY id, or a deferred SSH session id). The buffer is flushed through the normal write queue right after the reattach binds, before any later keystroke, so nothing is reordered. It stays bounded (1024 entries / fixed size); anything past that is refused as before.If the reattach does not bind (the remote shell is gone) or the pane gives up and spawns a fresh shell instead, the held keys are dropped with a
[pty-transport] dropped keys typed while the terminal was connectingwarning rather than being typed into a different shell.Why
I traced the path end to end against the Docker SSH relay: main's
pty:write→ SSH PTY provider → muxpty.data→ relaywriteDataall accept and deliver every byte once the pane is bound. The loss is one layer up: after a remount the new pane's transport rejects input until its reattachconnect()resolves, and nothing buffered it. Forcing a remount right before typing in the e2e reproduces it every time without this change (printf→f ..., 2/2 failed) and passes with it (3/3); the in-renderer trace showed the rejected keys were exactly the ones typed withconnected=false.Fixing it in the transport reuses the existing buffer and flush-order guarantees instead of adding a new queue in main or the relay, and needs no wire change (old relays and hosts see the same writes, just not dropped). Buffering is limited to reattaches: typeahead into a fresh shell could land ahead of a startup/agent command, so fresh spawns keep today's behavior.
Linked Issue
Fixes flaky e2e
tests/e2e/ssh-cold-activation-restore.spec.ts:209(failed on #24133, #24135, #24148).Visual Proof
N/A — no visual change; the fix is that typed characters are no longer lost during an invisible reconnect window. Covered by the unit test and the e2e below.
Testing
New
pty-connection-ssh-reattach-early-input.test.tsdrives a restored SSH pane through the real IPC transport: keys typed while the reattach spawn is in flight arrive in order after it binds (fails without the fix: received"ok"instead of"printf ok"), and a failed reattach drops them with the warning instead of writing them.pnpm test src/renderer/src/components/terminal-pane src/renderer/src/store(8242 passed),pnpm tc,pnpm run check:code-quality:changed,pnpm run audit:anti-slop.Local macOS + Docker SSH relay:
ORCA_E2E_SSH_DOCKER=1 playwright test tests/e2e/ssh-cold-activation-restore.spec.tspasses; with a forced remount just before typing (temporary instrumentation, not committed) it fails 2/2 before and passes 3/3 after.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Written with Claude Code (Claude Opus).
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
Renderer-only; no RPC/stream/wire changes, so mixed client/host versions are unaffected. Applies on all platforms and to folder workspaces (keyed on the SSH connection and PTY identity, not git). Local terminals and fresh SSH spawns are unchanged.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)