Skip to content

fix(terminal): wait for shell-ready before every SSH startup command - #12963

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/sta-3417-ssh-agent-startup-delivery
Aug 9, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/sta-3417-ssh-agent-startup-delivery

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

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:

const shouldWaitForSshShellReady =
  Boolean(connectionId) &&
  Boolean(pendingStartupCommand) &&
  !shouldDeliverStartupViaTerminalPaste

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 (omitting claude, 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 takes codex-startup-delivery.ts and tui-agent-startup.ts back to their main state.

Net effect: 5 insertions, 10 deletions, one file.

Behaviour notes:

  • Bare Codex now also waits on the SSH path. On a bash/zsh remote the marker arrives promptly, so there is no measurable cost; the deliberate markerless fast path it keeps locally is unaffected.
  • Worst case is bounded by the existing SSH_SHELL_READY_STARTUP_FALLBACK_MS (1.5 s) — strictly safer than today's 50 ms blind send.
  • Fish remotes are unchanged: the relay wraps only bash and zsh, so no marker is armed and delivery falls through the same fallback timer. That gap is tracked separately.

Screenshots

No visual change.

Testing

  • pnpm lint — oxlint + oxfmt clean on the changed file
  • pnpm typecheck — all three projects (node, cli, web) clean against current main
  • pnpm test — pty-connection, codex-session-restart, codex-startup-delivery: 591 passed
  • pnpm build — not run locally; no dependency, bundler, or asset changes
  • Added or updated high-quality tests that would catch regressions

On 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-connection suite 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

  • Cross-platform (macOS/Linux/Windows): the change is a single boolean in renderer transport setup, with no platform branch, no path handling, no shortcut or accelerator changes, and no Electron-surface differences. The gate is already behind Boolean(connectionId), so only SSH-connected panes are affected on any platform.
  • Remote wire compatibility: no wire change. startupCommandDelivery is 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.
  • SSH: the affected path. Behaviour moves from "write after 50 ms" to "write on the marker, or after 1.5 s" — a strict superset of the previous safety, with the fallback already in place and unchanged.
  • Regression risk: the local and daemon paths are untouched (both already call getShellReadyLaunchConfig for every non-Codex command). Codex's markerless local fast path is unchanged. Two imports became unused and were removed; shouldUseShellReadyStartupDelivery itself is retained and still used by the relay, the local provider, and background launches.
  • Folder workspaces / worktrees: unaffected — this is transport-level delivery timing.

Security Audit

  • Command execution: no change to command construction, quoting, or content. This only delays an already-authorized write.
  • Input handling: no new parsing of untrusted data; the marker scanner is reused unchanged.
  • Secrets / auth / IPC / paths: none added or altered. No new dependencies.
  • No follow-up security work needed.

Notes

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PTY connection logic removes agent-specific SSH startup-delivery helpers. SSH startup commands use shell-ready delivery and wait for the orca-shell-ready marker. Fresh SSH startup resets readiness state. Delayed injection verifies that the pending command has not changed. SSH and Codex resume tests cover this behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: SSH startup commands now wait for the shell-ready signal.
Description check ✅ Passed The description covers all required sections and clearly explains behavior, testing, platform review, security review, and follow-up work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

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.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-3417-ssh-agent-startup-delivery branch from 5e9624d to 331d621 Compare August 7, 2026 19:01
@brennanb2025 brennanb2025 changed the title fix(terminal): extend shell-ready startup delivery to omp/pi/opencode fix(terminal): wait for shell-ready before every SSH startup command Aug 7, 2026

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0f46db69-8a37-432e-ba6a-a042aec13120

📥 Commits

Reviewing files that changed from the base of the PR and between 5e9624d and 331d621.

📒 Files selected for processing (1)
  • src/renderer/src/components/terminal-pane/pty-connection.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

SSH validation verdict: land

Target and repo

  • Throwaway Ubuntu 22.04 ARM64 Docker container, reached through a unique host-mapped SSH port with a fresh Ed25519 key; this was not ssh localhost.
  • Login shell was /bin/bash. The live terminal processes were /bin/bash --rcfile /root/.orca-relay/shell-ready/bash/rcfile, proving the Bash shell-ready marker wrapper was armed.
  • The required direct clone of https://github.com/stablyai/demo-project was attempted in the container and GitHub requested credentials. I then used the required fallback: authenticated host clone, git bundle transfer, and remote clone from that bundle. Remote HEAD was 4d6a7ec73eb38d164f2e6dd9f191caef8d4ef084 on main.

PR identity and setup

  • Tested branch brennanb2025/sta-3417-ssh-agent-startup-delivery at 331d621.
  • pnpm build:relay passed before connecting.
  • Launched the PR worktree with unique ORCA_DEV_USER_DATA_PATH, CDP 9333, and an isolated renderer port. window.api.app.getIdentity() reported devBranch=brennanb2025/sta-3417-ssh-agent-startup-delivery and the expected repo root before setup and before every interaction batch.
  • The final target used Node v22.23.2 and a freshly reset linux-arm64 relay with compiled node-pty; Orca reported connected and the required remote repo was visible on SSH QA 12963.

Actions and backing proof

  • Through the real desktop runtime RPC plus renderer-backed PTY surface, created a visible terminal with a plain non-Codex command and deliberately omitted startupCommandDelivery. The startup command contained five newline-separated commands, including a long 198-character payload line, and wrote /work/demo-project/.orca-ssh-startup-12963-1786305411.
  • Independent SSH proof showed the 301-byte file with all five expected records: gate=non-codex-renderer-startup, the complete long line, cwd=/work/demo-project, shell=/bin/bash, and completed=yes. Remote git status showed exactly that untracked sentinel, and the shell-ready wrapped Bash PTY remained live.
  • Created a second visible renderer-backed SSH terminal with no startup command. A later terminal.send RPC was accepted with bytesWritten=101 and wrote /work/demo-project/.orca-ssh-no-startup-12963-1786305411; independent SSH cat returned ordinary-shell-usable=yes. This proves the ordinary no-startup shell opened and remained usable.
  • Visible Electron snapshots showed the SSH host badge, both terminal tabs, one then two terminal sessions, and both remote sentinel files in the remote explorer. The filesystem proof above, not the terminal buffer, is the pass criterion.

Logs

  • Playwright console: 0 errors. Five warnings were non-failing dev UI diagnostics; the two SSH-specific entries reported each tested tab with sshConnected=true.
  • Electron logs showed linux-arm64 detection, /usr/bin/node discovery, native dependency repair, relay launch, and Relay started successfully. Initial target-provisioning attempts correctly failed before Node/build tools were installed; after installing them and resetting the relay, the final connection and both PTYs had no relevant error.
  • Relay/SSH inspection showed ORCA-RELAY READY, successful version handshake, an accepted socket client, two live marker-wrapped Bash PTYs during the test, and no relevant relay failure after the fresh reset.

Cleanup and remaining risk

  • Removed both sentinels; remote git status returned clean, with only the main worktree, no test branches, and no test-prefixed files or folders. Orca stopped exactly two PTYs, terminated the SSH session, and removed the test repo and target from the isolated profile.
  • Closed the CDP session, stopped only the recorded PR dev process tree, removed the Docker container, and removed both unique temp key/profile paths to Trash. CDP 9333 has no listener, no test container remains, and the PR worktree is clean at the tested head with only the intended committed +5/-10 diff.
  • No remaining SSH blocker or unverified merge gate.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron validation at 10bc332c8415673164fccf270b263d89e581b316:

  • CDP identity confirmed brennanb2025/sta-3417-ssh-agent-startup-delivery in /Users/brennanbenson/orca/workspaces/orca/review-12963.
  • The full Orca app shell rendered visibly with 0 console errors; the three warnings were pre-existing dev-only Tooltip/React Grab diagnostics.
  • This PR has no changed visual surface, so the screenshot is launch/context evidence. The functional transport proof remains the live SSH validation with a land verdict.

Electron validation

ghost 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: Pro Plus

Run ID: 5f887898-fa60-449d-8d43-231715cf2bd3

📥 Commits

Reviewing files that changed from the base of the PR and between 331d621 and 10bc332.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts

Comment on lines +4761 to +4779
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
}

ghost Aug 9, 2026

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

🧩 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 -200

Repository: 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

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