Repository navigation
fix(cli): check the runtime source before sending - #27206
Conversation
A terminal Orca launches now carries which Orca launched it (ORCA_RUNTIME_SOURCE_ID = the profile's installation id, ORCA_RUNTIME_SOURCE_INCARNATION = the launching runtime id). Before a request is sent, the CLI compares that with the runtime the profile's runtime record names. Same runtime: sent as before. Different runtime: a read-only status.get asks which profile it serves; the same profile (a restart or update) is accepted, anything else is refused before the request reaches it. The vars cross into WSL through WSLENV. The SSH bridge stamps the bridging runtime itself rather than trusting the remote env. The existing orchestration compatibility stamp is untouched.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to The runtime-source check is client-side and looks sound. One minor hardening point remains in the SSH bridge, where an optional override could skip the check, but no current caller triggers it. This is safe to merge with owner awareness. 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:
4d19d996-a9c5-4067-8764-6fb96d9b24b0
📒 Files selected for processing (18)
src/cli/runtime/client.tssrc/cli/runtime/runtime-source-fence.test.tssrc/cli/runtime/runtime-source-fence.tssrc/main/ipc/pty/ipc/spawn-env-codex.tssrc/main/ipc/pty/provider/local-configure.tssrc/main/ipc/pty/runtime/spawn-preflight.tssrc/main/orcad/orcad-entry.tssrc/main/pty/wsl-orca-env.test.tssrc/main/pty/wsl-orca-env.tssrc/main/runtime/host-descriptor.test.tssrc/main/runtime/host-descriptor.tssrc/main/ssh/ssh-remote-cli-host-passthrough.test.tssrc/main/ssh/ssh-remote-cli-host-passthrough.tssrc/main/ssh/ssh-remote-orca-cli.tssrc/main/startup/configure-process.test.tssrc/main/startup/configure-process.tssrc/shared/runtime-source-env.test.tssrc/shared/runtime-source-env.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| runtimeSource: getRuntimeSourceStamp(runtime), | ||
| ...passthroughOptions |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n 'runRemoteOrcaCli|passthroughOptions|runtimeSource' src/main/ssh/ssh-remote-orca-cli.ts src/main/ssh/ssh-remote-cli-host-passthrough.ts src/main/sshRepository: stablyai/orca
Length of output: 11091
🏁 Script executed:
set -e
printf '%s\n' '--- ssh-remote-orca-cli.ts ---'
nl -ba src/main/ssh/ssh-remote-orca-cli.ts | sed -n '1,125p'
printf '%s\n' '--- ssh-remote-cli-host-passthrough.ts ---'
nl -ba src/main/ssh/ssh-remote-cli-host-passthrough.ts | sed -n '60,250p'
printf '%s\n' '--- direct passthrough option constructions ---'
rg -n -C 8 --glob '*.ts' 'runtimeSource\s*:' src/main/ssh
printf '%s\n' '--- runRemoteOrcaCli call sites with third argument/context ---'
nl -ba src/main/ssh/ssh-remote-orchestration-compatibility.test.ts | sed -n '1,220p'
nl -ba src/main/ssh/ssh-relay-session.ts | sed -n '1580,1635p'
nl -ba src/main/ssh/ssh-remote-orca-cli.test.ts | sed -n '130,235p'
nl -ba src/main/ssh/ssh-remote-cli-dispatch-refusal-passthrough.test.ts | sed -n '1,100p'Repository: stablyai/orca
Length of output: 36598
🏁 Script executed:
set -e
printf '%s\n' '--- all runtimeSource references ---'
rg -n -C 5 --glob '*.ts' --glob '*.tsx' 'runtimeSource|stampRuntimeSourceEnv|getRuntimeSourceStamp|RUNTIME_SOURCE' src
printf '%s\n' '--- host passthrough runtime-source tests ---'
nl -ba src/main/ssh/ssh-remote-cli-host-passthrough.test.ts | sed -n '115,175p'
printf '%s\n' '--- changed diff against merge base ---'
git diff -- src/main/ssh/ssh-remote-orca-cli.ts src/main/ssh/ssh-remote-cli-host-passthrough.ts 0ba67e11819e5a35c2a9569a04c41d09893198c1 3093b1db048075bb089cbb010efb305d77a6405e -- || trueRepository: stablyai/orca
Length of output: 41927
🏁 Script executed:
set -e
rg -n -F --glob '*.ts' 'class RuntimeSourceFence' src
rg -n -C 12 --glob '*.ts' 'RuntimeSourceFence|readRuntimeSourceStamp' src/cli/runtimeRepository: stablyai/orca
Length of output: 6285
Keep the bridge stamp bound to runtime.
If passthroughOptions.runtimeSource is null, the later spread replaces the stamp from getRuntimeSourceStamp(runtime). buildHostCliEnv clears the runtime-source fields, and RuntimeSourceFence.check returns without fencing when no stamp exists. The host CLI can therefore send the request without the runtime-source check. Spread the options first, then set runtimeSource from runtime.
Proposed change
--- "a/src/main/ssh/ssh-remote-orca-cli.ts"
+++ "b/src/main/ssh/ssh-remote-orca-cli.ts"
@@ -86,8 +86,8 @@
let passthroughFailure: HostCliUnavailableError | null = null
try {
return await runHostOrcaCliPassthrough(request, {
- runtimeSource: getRuntimeSourceStamp(runtime),
- ...passthroughOptions
+ ...passthroughOptions,
+ runtimeSource: getRuntimeSourceStamp(runtime)
})
} catch (err) {
if (!(err instanceof HostCliUnavailableError)) {📝 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.
| runtimeSource: getRuntimeSourceStamp(runtime), | |
| ...passthroughOptions | |
| ...passthroughOptions, | |
| runtimeSource: getRuntimeSourceStamp(runtime) |
The stamp also carries the launching runtime's userData path. A CLI that dials a different profile than the one that launched its terminal, and not the platform default an unpinned terminal falls back to, was pointed there on purpose (orca-dev from a packaged Orca's terminal), so the fence does not apply.
ELI5
When you run
orcainside a terminal, it finds "the running Orca" by reading one shared file in the profile folder. If a different Orca has taken over that file (another profile, another instance, a dev build), the command quietly goes to the wrong Orca — and a send, stop or create can take effect there. Now each terminal remembers which Orca opened it, andorcachecks that before it sends anything.What Changed
Before: the CLI read
orca-runtime.json, sent the request, and only afterwards checked that the answer came from the runtime named in that same file. If the file named the wrong live Orca, everything agreed with everything else and the command succeeded against the wrong Orca.After:
ORCA_RUNTIME_SOURCE_ID(the profile's installation id, which survives restarts),ORCA_RUNTIME_SOURCE_INCARNATION(the launching runtime's per-process id) andORCA_RUNTIME_SOURCE_PROFILE_PATH(the launching profile folder).status.getand compares the profile id the runtime reports. The same profile (a restart or auto-update, so panes that outlive the app keep working) is accepted and remembered. Another profile is refused withruntime_source_mismatch. A runtime that does not report a profile is refused withruntime_source_unverifiable. In both cases the real request is never sent.orcacommands on this machine stamps its own runtime as the source. It never takes the value from the remote shell, so remote input cannot choose the runtime.orca-devfrom a packaged Orca's terminal, so the check is skipped.orcad) clears any inherited stamp at startup, so an Orca started from another Orca's terminal (common forpnpm dev) does not tie its own CLI children to the parent.ORCA_ORCHESTRATION_COMPATIBILITY_HOST_*stamp is not touched. It is a WSL-or-SSH value that carries caller attestation and is checked exactly, so it cannot also hold the runtime source.Unchanged: a CLI started outside an Orca terminal (no stamp), and a command aimed at a paired server with
ORCA_ENVIRONMENT/ a pairing code. An explicit target wins over the launch source.Why
status.get), not only mutations. There is no complete list of which methods mutate, and a read answered by the wrong Orca is also wrong. The cost is onestatus.getper CLI process, and only after a restart.runtime-source-fence.v1).Known limits (not regressions; each keeps today's behaviour):
ORCA_USER_DATA_PATHto their own Orca, so a stamp would add nothing until the host-side check.Design adaptation: the design forwarded the stamp through the SSH pass-through allowlist. This PR stamps it from the bridging runtime itself instead, because that runtime is by construction the source, and the remote env is untrusted input.
Linked Issue
Part of #17642 (the host-side half, D4-CL2, closes it).
Visual Proof
N/A — CLI and environment change with no UI.
Testing
src/cli/runtime/runtime-source-fence.test.ts(real socket / named-pipe runtime): another live runtime is refused before the request reaches it (fails onorigin/main: the request was delivered); a restarted runtime of the same profile is accepted and probed once; matching incarnation sends with no probe; a runtime without a profile id is refused; an unstamped CLI is unchanged; an explicit switch to another profile is let through while a fallback to the platform default is still fenced.WSLENV pass-through, SSH bridge stamping (remote and inherited values ignored), startup scrub, stamp helper, and env round-trip tests.
Existing WSL / SSH compatibility-stamp and bridge tests still pass unchanged.
pnpm tc, focusedpnpm test,oxlint,pnpm run check:code-quality:changed.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
Security: the stamp is not a secret (installation id and runtime id are already in
status.get), and the SSH bridge never trusts the remote value. Cross-platform: tests use a named pipe on Windows. SSH: covered as above. Folder workspaces: nothing here depends on Git. Backwards compatibility: old CLI × new host and new CLI × unstamped terminal keep today's behaviour.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)