Repository navigation
fix(terminal): wait for shell-ready before every SSH startup command - #12963
Conversation
📝 WalkthroughWalkthroughThe PTY connection logic removes agent-specific SSH startup-delivery helpers. SSH startup commands use shell-ready delivery and wait for the 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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 |
Renderer-delivered SSH launches wrote the startup command after a flat 50ms, so a remote shell still reaching its prompt could drop it. Only Codex plans opted into waiting. Gate on whether a startup command exists rather than on which agent it names: an unready shell drops whatever is written to it regardless. The relay already gates its own delivery on the marker it armed; this mirrors that for the renderer path, bounded by the existing 1.5s fallback.
5e9624d to
331d621
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0f46db69-8a37-432e-ba6a-a042aec13120
📒 Files selected for processing (1)
src/renderer/src/components/terminal-pane/pty-connection.ts
|
SSH validation verdict: land Target and repo
PR identity and setup
Actions and backing proof
Logs
Cleanup and remaining risk
|
|
Electron validation at
|
left a comment
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5f887898-fa60-449d-8d43-231715cf2bd3
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.ts
| let sshShellReadyMarkerScan = shouldWaitForSshShellReady | ||
| ? createShellReadyMarkerScanState() | ||
| : null | ||
| let sshStartupShellReady = !shouldWaitForSshShellReady | ||
| const armSshStartupShellReady = (): void => { | ||
| if (!connectionId || !pendingStartupCommand || shouldDeliverStartupViaTerminalPaste) { | ||
| return | ||
| } | ||
| if (startupInjectTimer !== null) { | ||
| clearTimeout(startupInjectTimer) | ||
| startupInjectTimer = null | ||
| } | ||
| if (sshShellReadyFallbackTimer !== null) { | ||
| clearTimeout(sshShellReadyFallbackTimer) | ||
| sshShellReadyFallbackTimer = null | ||
| } | ||
| sshShellReadyMarkerScan = createShellReadyMarkerScanState() | ||
| sshStartupShellReady = false | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="src/renderer/src/components/terminal-pane/pty-connection.ts"
printf 'File exists: '
test -f "$file" && echo yes || echo no
printf 'Lines around scanner definition/usages/markSshStartupShellReady/output scan:\n'
rg -n "createShellReadyMarkerScanState|sshShellReadyMarkerScan|sshStartupShellReady|markSshStartupShellReady|pendingStartupCommand|shouldDeliverStartupViaTerminalPaste|shellReadyMarkerScan|scan" "$file" | head -200
printf '\nRelevant line counts:\n'
wc -l "$file"
printf '\nContext definitions/calls:\n'
sed -n '4730,4805p' "$file"
printf '\nmarkSshStartupShellReady context:\n'
rg -n -C 12 "const markSshStartupShellReady|function markSshStartupShellReady|markSshStartupShellReady" "$file"
printf '\nOutput scan context around 7730:\n'
sed -n '7680,7760p' "$file"Repository: stablyai/orca
Length of output: 15847
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="src/renderer/src/components/terminal-pane/shell-ready-marker-scan.ts"
printf 'File exists: '
test -f "$file" && echo yes || echo no
printf '\n scanner implementation:\n'
cat -n "$file"
printf '\n Search for shell-ready-marker-scan usage/tests:\n'
rg -n "shell-ready-marker-scan|createShellReadyMarkerScanState|scanForShellReadyMarker|ShellReadyMarker|shell-ready-marker|shell ready marker|sshStartupShellReady|mar" src/renderer/src/components/terminal-pane src/renderer/src --glob '*.{ts,tsx}' | head -200Repository: stablyai/orca
Length of output: 29906
Clear the shell-ready scanner after readiness.
scanForShellReadyMarker() continues scanning after a match and returns matched: true while keeping prior output in output. When markSshStartupShellReady() sets sshStartupShellReady, leave the scanner active, so later chunks are still transformed by the scanner. Clear it after readiness, or skip scanning once ready.
Proposed fix
const markSshStartupShellReady = (): void => {
if (sshStartupShellReady) {
return
}
sshStartupShellReady = true
+ sshShellReadyMarkerScan = null
Summary
Split out of #12840 (STA-3417). This change does not fix STA-3417 and #12840 does not depend on it — the two are scoped differently and their file sets are disjoint, so either can merge first.
Renderer-delivered SSH launches wrote the startup command after a flat 50 ms, so a remote shell that had not yet reached its prompt could drop it. Only Codex plans opted into waiting for the remote shell-ready marker.
The gate now keys on whether a startup command exists at all, rather than on which agent the command happens to name:
An unready shell drops whatever is written to it regardless of which binary the command invokes, so agent identity was the wrong axis. The relay already gates its own delivery on the marker it armed (
pty-handler.ts—waitForShellReady: shellLaunch.env.ORCA_SHELL_READY_MARKER === '1'); this mirrors that decision for the renderer-delivered path instead of duplicating it with a hand-maintained list.An earlier revision of this PR added a
startupCommandDelivery: 'shell-ready'allowlist of four agents. That has been removed — it covered 4 of ~30 agents (omittingclaude, which carries both an argv prompt and--prefill), had to be extended by hand for every new agent with no type or test to catch an omission, and did nothing on the local or daemon paths, which already wrap every non-Codex command unconditionally. Deleting it takescodex-startup-delivery.tsandtui-agent-startup.tsback to theirmainstate.Net effect: 5 insertions, 10 deletions, one file.
Behaviour notes:
SSH_SHELL_READY_STARTUP_FALLBACK_MS(1.5 s) — strictly safer than today's 50 ms blind send.Screenshots
No visual change.
Testing
pnpm lint— oxlint + oxfmt clean on the changed filepnpm typecheck— all three projects (node, cli, web) clean against currentmainpnpm test—pty-connection,codex-session-restart,codex-startup-delivery: 591 passedpnpm build— not run locally; no dependency, bundler, or asset changesOn that last box, in the interest of being straight about it: this revision removes tests rather than adding them, because it removes the machinery they covered. The behaviour it changes is a timing decision on the SSH transport, which the existing
pty-connectionsuite exercises but does not assert an SSH-specific wait for.Not covered: no QA against a live SSH remote. That is the only transport this change affects, so a bash/zsh remote launch should be exercised before merge.
AI Review Report
Boolean(connectionId), so only SSH-connected panes are affected on any platform.startupCommandDeliveryis a pre-existing optional field that remains in the schema and is still honoured by the relay and by the local/daemon Codex fast paths; this PR simply stops consulting it for the renderer's SSH wait. Old and new relays are unaffected because nothing new is sent.getShellReadyLaunchConfigfor every non-Codex command). Codex's markerless local fast path is unchanged. Two imports became unused and were removed;shouldUseShellReadyStartupDeliveryitself is retained and still used by the relay, the local provider, and background launches.Security Audit
Notes