Skip to content

fix(cli): route --host runtime:<id> to that server instead of answering locally - #15364

Merged
nwparker merged 3 commits into
mainfrom
nwparker/cli-host-runtime-routing
Aug 18, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/cli-host-runtime-routing

Conversation

@nwparker

@nwparker nwparker commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​315 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​295
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​212 $\color{#cf222e}{\Huge{\mathbf{−}}}$​31 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​181

ELI5

orca ... --host runtime:<id> looked like "do this on that Orca server". It wasn't — it was a filter applied to whatever runtime the CLI was already talking to, which is normally your own machine. So a real server id and a typo'd one both came back ok: true with an empty list, and a clone aimed at a remote server landed in the caller's own worktree.

What Changed

--host is now resolved before the runtime client is constructed (src/cli/index.ts), by a new src/cli/execution-host-flag.ts:

  • Unparseable host ids are rejected. --host runtime:, --host ssh:, --host nonsense fail with invalid_argument and never reach a runtime.
  • runtime:<environment-id> is resolved against the paired-environment store. An id no paired environment owns is rejected:
    Unknown Orca server in --host runtime:xyz: no paired environment has id xyz. Run 'orca environment list' ...
    Matching is by environment id only — names are not accepted, since runtime:<id> is minted from the id.
  • A known id selects that environment as the connection. The command runs on that server, so _meta.runtimeId is the server's, client.isRemote is true (remote path validation now applies), and mutations land there. Combining it with --pairing-code, or with an --environment naming a different server, is an error.
  • Once routed, a host filter also accepts that runtime's local-stamped rows. A runtime stamps setups local when they were created on the box and runtime:<id> when a paired client created them; both name the machine we are now connected to. For selection (worktree create / automations create via --project + --host) an exact runtime:<id> match still wins over a local row.

Applies to every command that takes --host: project setups, project setup-existing-folder, project setup-clone, project setup-create, worktree create, automations create/edit. Command notes and agent-context schema text updated to describe the routing.

Why

runtime:<environment-id> ids are minted by addEnvironmentFromPairingCode as a client-local randomUUID(). They only name a machine relative to this machine's pairing store, so they are meaningless as a filter over the locally connected runtime's rows — and there is no runtime RPC that can tell the CLI whether such a host exists. That is exactly why an empty result was ambiguous.

The desktop already routes by host id (getProjectSetupRuntimeTarget(args.hostId) in store/slices/repos.ts picks the environment target from the runtime: prefix). This makes the CLI agree with the client that already gets it right, rather than inventing a third interpretation.

Both defects the report asked for are covered by the one rule: unknown runtime ids are rejected instead of returning empty-success, and --host runtime: is routed rather than silently falling back to local.

Linked Issue

N/A — reported directly; happy to file and link a tracking issue if preferred.

Visual Proof

N/A — CLI-only change, no UI surface.

Before

$ orca project setups --host runtime:<real-env-id>
{"ok":true,"result":{"setups":[]},"_meta":{"runtimeId":"<LOCAL runtime>"}}

$ orca project setups --host runtime:<nonexistent-id>
{"ok":true,"result":{"setups":[]},"_meta":{"runtimeId":"<LOCAL runtime>"}}

After

$ orca project setups --host runtime:<real-env-id>
# connects to that server; _meta.runtimeId is the server's

$ orca project setups --host runtime:<nonexistent-id>
invalid_argument: Unknown Orca server in --host runtime:<nonexistent-id>:
no paired environment has id <nonexistent-id>. Run `orca environment list`
to see paired servers, or pass --host local.

$ orca project setups --host runtime:
invalid_argument: Invalid --host value: runtime:. Expected local,
ssh:<target-id>, or runtime:<environment-id>.

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/cli — 86 files / 840 tests pass.

  • pnpm run typecheck, oxlint (base + code-quality native + type-aware), max-lines ratchet — clean.

  • New src/cli/execution-host-flag.test.ts (18 tests) covers parsing, id-not-name resolution, percent-encoded ids, --pairing-code / --environment conflicts, and the local/runtime filter equivalence.

  • New index-project-setup.test.ts cases assert the unknown-id rejection, the malformed-value rejection, and that neither reaches the runtime (callMock not called).

  • The existing "rejects remote project setup relative paths" case no longer needs a hand-fed --pairing-code: routing alone now makes the connection remote, which is the behavior change in miniature.

  • Platform: exercised on macOS. No platform-specific code paths; the resolution reads the same environment store the client already reads on all platforms.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Two judgment calls worth a second opinion:

  1. Routing vs. rejecting. The report offered either. I routed, because the desktop already does and because rejecting would leave --host runtime: with no way to do the thing it looks like it does. The cost is that --host now influences which machine a command runs on, not just what it filters.
  2. The local ⇔ runtime:<id> equivalence after routing. This mirrors setupWithFetchedOwner. Without it, --host runtime:X would miss setups created on X itself. Exact matches still take precedence in selection so a local row cannot shadow the named one.

Agent skill upstream boundary

N/A — no skill content changed.


Review round (Sol + Grok)

Two independent frontier-model reviews. What they found and what I did:

Fixed in 378221b:

  • Ambient ORCA_ENVIRONMENT was not conflict-checked (Grok, confirmed). ORCA_ENVIRONMENT=staging orca ... --host runtime:<prod-id> silently routed to prod, while the --environment staging flag spelling errored. Same intent, different outcome. Now both are checked. An ambient pairing code still loses to the explicit flag, because it can't be resolved to an id to compare — noted in the code.
  • Four documented examples used --host runtime:gpu (Grok, confirmed). gpu is an environment name; matching is id-only, so every one of those documented commands would now be rejected. Replaced with an id and the specs now say outright that names are not accepted.
  • --json errors weren't machine-recoverable (Grok). The unknown-id error now carries error.data.knownEnvironments plus nextSteps, matching the existing unknownFlagData convention. Kept the invalid_argument code for consistency with how an unknown --environment already fails.
  • Missing coverage on the mutating paths (Grok, confirmed). worktree create and automations create asserted RPC args but never that the command actually reached the remote — a regression that stayed local would have passed. Both now assert the routed connection, plus a --environment X --host local filter-only case and error.code/error.data assertions.

Fixed in 8879bb0 (found while verifying): execution-host-flag.ts is now a sixth module on the --help path, but the runtime-client-deferral guard only pinned five. Added it, and verified the assertion actually fails when the import is flipped to the barrel.

Refuted: Sol reported that the new static import drags zod onto the --help path. It does not. runtime/types reaches runtime-rpc-envelope only through import type/export type (erased), orchestration-compatibility-evidence has no imports at all, and runtime/types was already eager via args.ts. Measured the eager graph directly: 54 modules, bare deps node:fs, node:os, node:path, no zod/ws/tweetnacl.

Accepted as a known limitation, follow-up filed as #15366: both reviewers flagged that a runtime:<id> stamp is client-minted, so (a) two clients paired with the same server stamp rows with different ids and don't see each other's, and (b) the CLI running on a paired server rejects an id that appears in its own rows. Both predate this PR — the old behavior was to silently answer for the wrong machine, which is strictly worse. The real fix is to normalize the stamp at the source (the runtime persisting local for its own disk) rather than widen the client-side filter, which would break the nested-pairing case. That's a main-process data-model change and out of scope here — filed as #15366 with the two-client and server-side-lookup cases written up.

Also out of scope: the CLI does not capability-gate projectHostSetup.* the way the renderer does with assertProjectHostSetupRuntimeCapability. That gap already exists on the --environment path; it should be closed once for both, not bolted onto the --host path.

…ng locally

`--host` was only ever a local filter over whatever runtime the CLI happened
to connect to, so `--host runtime:<id>` silently answered for (and mutated)
the local machine. A real environment id and a made-up one were
indistinguishable: both returned ok:true with an empty list and the local
runtimeId in _meta, and `project setup-clone --host runtime:<id>` cloned into
the caller's own machine.

Resolve the flag before the client is built: unparseable host ids and runtime
ids that no paired environment owns are rejected, and a known runtime id
selects that environment as the connection (conflicting with --pairing-code or
a different --environment is an error). Once routed, a host filter also
accepts the runtime's own `local`-stamped rows, since both spellings name the
machine we are now talking to.
@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2d2eaba6-0dfc-4e59-9d12-99768588bac4

📥 Commits

Reviewing files that changed from the base of the PR and between a77a2f9 and 2f3c234.

📒 Files selected for processing (12)
  • src/cli/execution-host-flag.test.ts
  • src/cli/execution-host-flag.ts
  • src/cli/handlers/project.ts
  • src/cli/index-automation-target.test.ts
  • src/cli/index-project-setup.test.ts
  • src/cli/index-test-harness.ts
  • src/cli/index-worktree-create-target.test.ts
  • src/cli/index.ts
  • src/cli/specs/automations.ts
  • src/cli/specs/core.ts
  • src/cli/specs/project.ts
  • src/cli/worktree-project-target.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The CLI adds --host parsing for local, SSH, and paired runtime hosts. It resolves runtime environment IDs and rejects invalid or conflicting routing options. Project setup commands use shared host validation and host matching. Worktree target resolution selects ready setups by normalized host IDs. Tests cover parsing, routing, conflicts, percent encoding, filtering, and paired runtime environments. CLI specifications document runtime host usage.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed and covers the change, rationale, testing, visual proof, review notes, and checklist, but it omits the required linked issue. Add a valid linked issue reference in the Linked Issue section instead of marking it N/A.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes routing --host runtime: commands to the selected server.
✨ Finishing Touches 💡 1
📝 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.

- Conflict-check an ambient ORCA_ENVIRONMENT, not just the --environment flag.
  `ORCA_ENVIRONMENT=staging orca ... --host runtime:<prod-id>` silently routed
  to prod while the flag spelling errored. An ambient pairing code still loses
  to the explicit flag, because it cannot be resolved to an id to compare.
- Attach the known environment ids to the unknown-id error as `error.data`, so
  a --json consumer can retry without parsing prose, and say outright that
  runtime:<id> matches ids only and never environment names.
- Fix four command examples that documented `--host runtime:gpu`. `gpu` is an
  environment name, so every one of them would now be rejected; use an id.
- Cover the routed connection on `worktree create` and `automations create`
  (the mutating paths), the `--environment X --host local` filter-only case,
  and assert error.code/error.data rather than only substrings.
index.ts now loads execution-host-flag.ts on every invocation, making it the
sixth module on the --help path. It imports RuntimeClientError from
./runtime/types today, but nothing enforced that; switching it to the barrel
would silently drag zod/ws/tweetnacl back onto --help, which is exactly what
this guard exists to prevent. Verified the assertion fails when the import is
flipped to the barrel.
@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…ng locally (stablyai#15364)

* fix(cli): route --host runtime:<id> to that server instead of answering locally

`--host` was only ever a local filter over whatever runtime the CLI happened
to connect to, so `--host runtime:<id>` silently answered for (and mutated)
the local machine. A real environment id and a made-up one were
indistinguishable: both returned ok:true with an empty list and the local
runtimeId in _meta, and `project setup-clone --host runtime:<id>` cloned into
the caller's own machine.

Resolve the flag before the client is built: unparseable host ids and runtime
ids that no paired environment owns are rejected, and a known runtime id
selects that environment as the connection (conflicting with --pairing-code or
a different --environment is an error). Once routed, a host filter also
accepts the runtime's own `local`-stamped rows, since both spellings name the
machine we are now talking to.

* fix(cli): close --host routing gaps found in review

- Conflict-check an ambient ORCA_ENVIRONMENT, not just the --environment flag.
  `ORCA_ENVIRONMENT=staging orca ... --host runtime:<prod-id>` silently routed
  to prod while the flag spelling errored. An ambient pairing code still loses
  to the explicit flag, because it cannot be resolved to an id to compare.
- Attach the known environment ids to the unknown-id error as `error.data`, so
  a --json consumer can retry without parsing prose, and say outright that
  runtime:<id> matches ids only and never environment names.
- Fix four command examples that documented `--host runtime:gpu`. `gpu` is an
  environment name, so every one of them would now be rejected; use an id.
- Cover the routed connection on `worktree create` and `automations create`
  (the mutating paths), the `--environment X --host local` filter-only case,
  and assert error.code/error.data rather than only substrings.

* test(cli): pin execution-host-flag to the deferred error-class import

index.ts now loads execution-host-flag.ts on every invocation, making it the
sixth module on the --help path. It imports RuntimeClientError from
./runtime/types today, but nothing enforced that; switching it to the barrel
would silently drag zod/ws/tweetnacl back onto --help, which is exactly what
this guard exists to prevent. Verified the assertion fails when the import is
flipped to the barrel.
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…ng locally (stablyai#15364)

* fix(cli): route --host runtime:<id> to that server instead of answering locally

`--host` was only ever a local filter over whatever runtime the CLI happened
to connect to, so `--host runtime:<id>` silently answered for (and mutated)
the local machine. A real environment id and a made-up one were
indistinguishable: both returned ok:true with an empty list and the local
runtimeId in _meta, and `project setup-clone --host runtime:<id>` cloned into
the caller's own machine.

Resolve the flag before the client is built: unparseable host ids and runtime
ids that no paired environment owns are rejected, and a known runtime id
selects that environment as the connection (conflicting with --pairing-code or
a different --environment is an error). Once routed, a host filter also
accepts the runtime's own `local`-stamped rows, since both spellings name the
machine we are now talking to.

* fix(cli): close --host routing gaps found in review

- Conflict-check an ambient ORCA_ENVIRONMENT, not just the --environment flag.
  `ORCA_ENVIRONMENT=staging orca ... --host runtime:<prod-id>` silently routed
  to prod while the flag spelling errored. An ambient pairing code still loses
  to the explicit flag, because it cannot be resolved to an id to compare.
- Attach the known environment ids to the unknown-id error as `error.data`, so
  a --json consumer can retry without parsing prose, and say outright that
  runtime:<id> matches ids only and never environment names.
- Fix four command examples that documented `--host runtime:gpu`. `gpu` is an
  environment name, so every one of them would now be rejected; use an id.
- Cover the routed connection on `worktree create` and `automations create`
  (the mutating paths), the `--environment X --host local` filter-only case,
  and assert error.code/error.data rather than only substrings.

* test(cli): pin execution-host-flag to the deferred error-class import

index.ts now loads execution-host-flag.ts on every invocation, making it the
sixth module on the --help path. It imports RuntimeClientError from
./runtime/types today, but nothing enforced that; switching it to the barrel
would silently drag zod/ws/tweetnacl back onto --help, which is exactly what
this guard exists to prevent. Verified the assertion fails when the import is
flipped to the barrel.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ng locally (stablyai#15364)

* fix(cli): route --host runtime:<id> to that server instead of answering locally

`--host` was only ever a local filter over whatever runtime the CLI happened
to connect to, so `--host runtime:<id>` silently answered for (and mutated)
the local machine. A real environment id and a made-up one were
indistinguishable: both returned ok:true with an empty list and the local
runtimeId in _meta, and `project setup-clone --host runtime:<id>` cloned into
the caller's own machine.

Resolve the flag before the client is built: unparseable host ids and runtime
ids that no paired environment owns are rejected, and a known runtime id
selects that environment as the connection (conflicting with --pairing-code or
a different --environment is an error). Once routed, a host filter also
accepts the runtime's own `local`-stamped rows, since both spellings name the
machine we are now talking to.

* fix(cli): close --host routing gaps found in review

- Conflict-check an ambient ORCA_ENVIRONMENT, not just the --environment flag.
  `ORCA_ENVIRONMENT=staging orca ... --host runtime:<prod-id>` silently routed
  to prod while the flag spelling errored. An ambient pairing code still loses
  to the explicit flag, because it cannot be resolved to an id to compare.
- Attach the known environment ids to the unknown-id error as `error.data`, so
  a --json consumer can retry without parsing prose, and say outright that
  runtime:<id> matches ids only and never environment names.
- Fix four command examples that documented `--host runtime:gpu`. `gpu` is an
  environment name, so every one of them would now be rejected; use an id.
- Cover the routed connection on `worktree create` and `automations create`
  (the mutating paths), the `--environment X --host local` filter-only case,
  and assert error.code/error.data rather than only substrings.

* test(cli): pin execution-host-flag to the deferred error-class import

index.ts now loads execution-host-flag.ts on every invocation, making it the
sixth module on the --help path. It imports RuntimeClientError from
./runtime/types today, but nothing enforced that; switching it to the barrel
would silently drag zod/ws/tweetnacl back onto --help, which is exactly what
this guard exists to prevent. Verified the assertion fails when the import is
flipped to the barrel.
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.

3 participants