Skip to content

fix(cli): check the runtime source before sending - #27206

Merged
OrcaWin merged 4 commits into
mainfrom
OrcaWin/d4-d4-cl1
Oct 10, 2026
Merged

OrcaWin merged 4 commits into
mainfrom
OrcaWin/d4-d4-cl1

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​291 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​289
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​211 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​209

ELI5

When you run orca inside 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, and orca checks 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:

  • Every terminal Orca spawns (in-process, daemon-backed, and WSL) carries three new variables: ORCA_RUNTIME_SOURCE_ID (the profile's installation id, which survives restarts), ORCA_RUNTIME_SOURCE_INCARNATION (the launching runtime's per-process id) and ORCA_RUNTIME_SOURCE_PROFILE_PATH (the launching profile folder).
  • Before sending, the CLI compares the incarnation with the runtime the record names. If they match, the request is sent exactly as before (no extra round trip).
  • If they differ, the CLI first sends a read-only status.get and 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 with runtime_source_mismatch. A runtime that does not report a profile is refused with runtime_source_unverifiable. In both cases the real request is never sent.
  • WSL: both variables are added to the WSLENV pass-through list.
  • SSH: the bridge that runs remote orca commands 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.
  • Choosing another profile on purpose is not refused. If the CLI dials a profile that is neither the one that launched the terminal nor the platform default (the folder an unpinned terminal falls back to), the user pointed it there, e.g. orca-dev from a packaged Orca's terminal, so the check is skipped.
  • Orca (desktop and orcad) clears any inherited stamp at startup, so an Orca started from another Orca's terminal (common for pnpm dev) does not tie its own CLI children to the parent.
  • The existing 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

  • Check before sending, not after. Checking only the response cannot undo a mutation that already ran.
  • Profile id as the source, runtime id only as a hint. Runtime ids change on every restart, and daemon-backed terminals survive restarts. Binding to the exact runtime id would lock out every surviving terminal after an update. The installation id already exists (the host descriptor) and is stable per profile.
  • Separate variables instead of reusing the compatibility stamp. That stamp holds either WSL or SSH evidence, and SSH terminals need that evidence and the source at the same time.
  • Every method is checked (except 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 one status.get per CLI process, and only after a restart.
  • Client-only. No wire change: an old host never sees the variables, and an old CLI ignores them (today's behaviour). The host-side check that closes the remaining window between the probe and the send is the follow-up (D4-CL2, runtime-source-fence.v1).

Known limits (not regressions; each keeps today's behaviour):

  • A second live runtime on the same profile would pass, because the design accepts a new runtime of the same profile as the restart handoff. The single-instance lock prevents two live runtimes on one profile; an owner-checked adoption record is future work.
  • Structured (non-terminal) agent children are not stamped yet. They already pin ORCA_USER_DATA_PATH to 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 on origin/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, focused pnpm 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

m4air added 2 commits October 10, 2026 02:23
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.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3593cfba-fb2b-4b50-bf2b-a70c53df8637

📥 Commits

Reviewing files that changed from the base of the PR and between 3093b1d and d182de7.


📒 Files selected for processing (14)
  • src/cli/runtime/client.ts
  • src/cli/runtime/runtime-source-fence.test.ts
  • src/cli/runtime/runtime-source-fence.ts
  • src/main/ipc/pty/ipc/spawn-env-codex.ts
  • src/main/ipc/pty/provider/local-configure.ts
  • src/main/ipc/pty/runtime/spawn-preflight.ts
  • src/main/pty/wsl-orca-env.test.ts
  • src/main/pty/wsl-orca-env.ts
  • src/main/runtime/host-descriptor.test.ts
  • src/main/runtime/host-descriptor.ts
  • src/main/ssh/ssh-remote-cli-host-passthrough.test.ts
  • src/main/ssh/ssh-remote-cli-host-passthrough.ts
  • src/shared/runtime-source-env.test.ts
  • src/shared/runtime-source-env.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.



📝 Walkthrough

Walkthrough

The change defines runtime source stamps from an installation ID and runtime incarnation. It propagates these stamps through process environments and clears inherited stamps in specified startup paths. Before sending a local RPC, RuntimeClient checks the runtime source. It probes runtime status when needed and refuses requests when the installation does not match or cannot be verified.


Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to d182d

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 | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 18 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: the CLI checks the runtime source before sending requests.
Description check Passed The description is complete and aligned with the template. It explains the user impact, implementation, rationale, linked issue, testing, security, compatibility, and the lack of UI changes. Some chec…
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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4d19d996-a9c5-4067-8764-6fb96d9b24b0
📥 Commits

Reviewing files that changed from the base of the PR and between 3c71318 and 3093b1d.

📒 Files selected for processing (18)
  • src/cli/runtime/client.ts
  • src/cli/runtime/runtime-source-fence.test.ts
  • src/cli/runtime/runtime-source-fence.ts
  • src/main/ipc/pty/ipc/spawn-env-codex.ts
  • src/main/ipc/pty/provider/local-configure.ts
  • src/main/ipc/pty/runtime/spawn-preflight.ts
  • src/main/orcad/orcad-entry.ts
  • src/main/pty/wsl-orca-env.test.ts
  • src/main/pty/wsl-orca-env.ts
  • src/main/runtime/host-descriptor.test.ts
  • src/main/runtime/host-descriptor.ts
  • src/main/ssh/ssh-remote-cli-host-passthrough.test.ts
  • src/main/ssh/ssh-remote-cli-host-passthrough.ts
  • src/main/ssh/ssh-remote-orca-cli.ts
  • src/main/startup/configure-process.test.ts
  • src/main/startup/configure-process.ts
  • src/shared/runtime-source-env.test.ts
  • src/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.

Comment on lines +89 to +90
runtimeSource: getRuntimeSourceStamp(runtime),
...passthroughOptions

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.

🗄️ 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/ssh

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

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

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

Suggested change
runtimeSource: getRuntimeSourceStamp(runtime),
...passthroughOptions
...passthroughOptions,
runtimeSource: getRuntimeSourceStamp(runtime)

m4air added 2 commits October 10, 2026 02:37
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.
@OrcaWin
OrcaWin merged commit 7aa91f7 into main Oct 10, 2026
133 of 137 checks passed
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