Repository navigation
fix(cli): route --host runtime:<id> to that server instead of answering locally - #15364
Conversation
…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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe CLI adds 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 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 |
- 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.
|
thanks for reporting. looking into it |
…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.
…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.
…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.
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 backok: truewith an empty list, and a clone aimed at a remote server landed in the caller's own worktree.What Changed
--hostis now resolved before the runtime client is constructed (src/cli/index.ts), by a newsrc/cli/execution-host-flag.ts:--host runtime:,--host ssh:,--host nonsensefail withinvalid_argumentand 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._meta.runtimeIdis the server's,client.isRemoteis true (remote path validation now applies), and mutations land there. Combining it with--pairing-code, or with an--environmentnaming a different server, is an error.local-stamped rows. A runtime stamps setupslocalwhen they were created on the box andruntime:<id>when a paired client created them; both name the machine we are now connected to. For selection (worktree create/automations createvia--project+--host) an exactruntime:<id>match still wins over alocalrow.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 andagent-contextschema text updated to describe the routing.Why
runtime:<environment-id>ids are minted byaddEnvironmentFromPairingCodeas a client-localrandomUUID(). 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)instore/slices/repos.tspicks the environment target from theruntime: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
After
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/--environmentconflicts, and the local/runtime filter equivalence.New
index-project-setup.test.tscases assert the unknown-id rejection, the malformed-value rejection, and that neither reaches the runtime (callMocknot 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:
--host runtime:with no way to do the thing it looks like it does. The cost is that--hostnow influences which machine a command runs on, not just what it filters.local⇔runtime:<id>equivalence after routing. This mirrorssetupWithFetchedOwner. Without it,--host runtime:Xwould miss setups created on X itself. Exact matches still take precedence in selection so alocalrow 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:ORCA_ENVIRONMENTwas not conflict-checked (Grok, confirmed).ORCA_ENVIRONMENT=staging orca ... --host runtime:<prod-id>silently routed to prod, while the--environment stagingflag 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.--host runtime:gpu(Grok, confirmed).gpuis 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.--jsonerrors weren't machine-recoverable (Grok). The unknown-id error now carrieserror.data.knownEnvironmentsplusnextSteps, matching the existingunknownFlagDataconvention. Kept theinvalid_argumentcode for consistency with how an unknown--environmentalready fails.worktree createandautomations createasserted 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 localfilter-only case anderror.code/error.dataassertions.Fixed in
8879bb0(found while verifying):execution-host-flag.tsis now a sixth module on the--helppath, but theruntime-client-deferralguard 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
zodonto the--helppath. It does not.runtime/typesreachesruntime-rpc-envelopeonly throughimport type/export type(erased),orchestration-compatibility-evidencehas no imports at all, andruntime/typeswas already eager viaargs.ts. Measured the eager graph directly: 54 modules, bare depsnode: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 persistinglocalfor 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 withassertProjectHostSetupRuntimeCapability. That gap already exists on the--environmentpath; it should be closed once for both, not bolted onto the--hostpath.