Skip to content

feat(cli): create workspaces on providers with worktree create --on (draft) - #40250

Draft
nwparker wants to merge 1 commit into
mainfrom
nwparker/cli-workspace-providers
Draft

nwparker wants to merge 1 commit into
mainfrom
nwparker/cli-workspace-providers

Conversation

@nwparker

@nwparker nwparker commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Draft, not for merge yet. CLI flags and JSON shapes are hard to change once scripts depend on them, so this stays open for review of the surface. The earlier --recipe version (#40108) was reverted in #40184 for this reason.

ELI5

orca worktree create --on <target> lets you say where a new workspace runs. The target can be a host you already have (local, an SSH host, a paired Orca server), which works exactly like --host. It can also be a provider that first creates a new host for the workspace: an environment recipe from the repo's orca.yaml (recipe:<id>) or one an approved plugin ships (plugin:<plugin>/<id>). orca provider list shows which providers you can use.

Design

One selector, two kinds of target.

  • A host is where a workspace runs: local, ssh:<id>, runtime:<id>, or a name from orca host list.
  • A provider creates a new host on demand: recipe:<id> or plugin:<pluginKey>/<id>.

The host a provider creates is an ordinary runtime:<id> host, so the existing host and workspace commands work on it. The flag is --on and not --env because --environment already means "send this command to a paired host". Without --on, nothing changes. The default never switches to a provider.

Discover:

  • orca provider list [--repo <selector>] [--json]
  • orca provider show <target>: the target's capabilities, sizes, inputs and availability.
  • orca provider doctor recipe:<id>: the same check as vm recipe doctor, which stays.

JSON output has schemaVersion: 1 and a fixed set of fields per provider:
target, kind, name, description, repo, available, unavailableReason, checkoutMode, capabilities{suspend,resume,destroy}, timeoutSeconds, sizes, inputs.

Create: --on <provider>, plus these flags:

Flag Behaviour
--idempotency-key Sent with every create. A random key is generated and printed if you don't pass one. The key is scoped to the target, so reusing it elsewhere never returns this result.
--progress text|json|none Named steps go to stderr. json writes NDJSON with a started event carrying the key, then phase events, including host-recorded with the new host's runtime id. stdout carries only the result.
--size, --input, --inputs-file Apply only to providers that declare sizes or inputs. Refused with a hint until one does.

The result adds host: {id, origin: {target, runtimeId}, lifecycle: 'per-workspace', state, checkoutMode}, idempotencyKey and schemaVersion.

Failures. A failed create returns host_create_failed with:

  • data.phase: the step that failed.
  • data.providerCode / data.providerParams: the existing recipe failure catalog code and its parameters.
  • data.host.state: destroyed, left-running (the provider has no destroy step), destroy-failed, or unknown (contact was lost after the host was recorded).
Exit code (provider creates and provider commands only) Meaning
0 Done
1 Failed, nothing left running
2 Invalid input
3 Confirmation required (used by the removal follow-up)
4 The workspace exists, but a follow-up such as the agent launch failed. data.result holds the workspace, and nextSteps holds the shell-quoted recovery, or the replay-safe --retry-launch command when the launch reply was lost.
5 Failed, and a host may still be running

Plain worktree create keeps exit 1 for everything, as today.

Where it runs. The Orca desktop app on this computer runs provider creates, because it owns the recipes and VM records. They go through the same main-side provisioning the composer uses: the write-ahead record, per-step timeouts and cancellation. Failure cleanup uses the same shared cleanup. Ctrl+C aborts the request, and a host that finished its create step is destroyed.

Refused for now:

  • Paired devices can't start a provider create.
  • --environment and --pairing-code.
  • --activate, --parent-* and --retry-launch with a provider target.
  • An existing-host --on together with --repo, because the repo already names its host.

Not in this draft:

  • --no-wait / worktree wait.
  • Provider-declared sizes and inputs.
  • host destroy, and removal from the CLI. The phone and other-client removal leak fix is fix(vm-recipes): destroy a recipe VM when a phone deletes its workspace #40205.
  • Durable idempotency. The key rides on the in-memory create dedupe (60 s after a success), and a joined retry shares the first caller's abort.
  • Cross-store lineage for workspaces on a new host.

Explainer: sample sessions

$ orca provider list --repo id:7b2…
orca (/Users/me/src/orca)
  recipe:dev-vm  Dev VM  [orca-worktree; destroys on removal; timeouts create 600s]
  plugin:acme/gpu-box  GPU box  [provisioned-root; destroys on removal]

$ orca worktree create --repo id:7b2… --name fix-login --on recipe:dev-vm
Creating "fix-login" on a new host from recipe:dev-vm (idempotency key 3f6c…). This can take several minutes; Ctrl+C stops it.
- Running the provider's create step...
- Connecting to the new environment...
- Recorded the new environment (vm-01HX…).
- Checking Orca on the environment...
- Registering the project on the environment...
- Creating the workspace...
<worktree summary>
host: runtime:env-9a… (recipe:dev-vm, orca-worktree)
environment: vm-01HX…

$ orca worktree create --repo id:7b2… --name t --on recipe:dev-vm --size large --json; echo "exit $?"
{"ok":false,"error":{"code":"invalid_argument","message":"recipe:dev-vm declares no sizes, so --size doesn't apply. See `orca provider show recipe:dev-vm`.","data":{"field":"size","target":"recipe:dev-vm"}}}
exit 2

$ orca worktree create --repo id:7b2… --name t --on recipe:dev-vm --progress json --json 2>progress.ndjson; echo "exit $?"
{"ok":false,"error":{"code":"host_create_failed","message":"Update Orca on the new environment before creating this workspace. The environment (runtime vm-01HX…) may still be running because destroying it failed: …","data":{"phase":"checking-host","target":"recipe:dev-vm","host":{"runtimeId":"vm-01HX…","state":"destroy-failed"},"idempotencyKey":"…","nextSteps":["…"]}}}
exit 5
$ cat progress.ndjson
{"event":"started","target":"recipe:dev-vm","idempotencyKey":"…","at":…}
{"event":"phase","phase":"running-create","at":…}
{"event":"phase","phase":"host-recorded","runtimeId":"vm-01HX…","at":…}
{"event":"phase","phase":"checking-host","at":…}
{"event":"phase","phase":"destroying-after-failure","at":…}

What Changed

  • Shared contract:
    • workspace-provider-target.ts: the target grammar, the wire schema and the canonical spelling. Recipe ids reuse the orca.yaml id rule, now in a small orca-vm-recipe-id.ts.
    • The provider contract: phases, host_create_failed, the listing types and workspace.providers.v1.
    • worktree.create takes target instead of recipeId.
    • The keepalive progress frame now carries runtimeId.
  • Main:
    • workspace-providers.ts: resolve a target in its own namespace. A plugin recipe whose id matches an orca.yaml recipe is refused, because lifecycle steps resolve by id with orca.yaml first.
    • The provider listing.
    • provider.list RPC.
    • The dedupe key now includes the target.
  • CLI:
    • --on, provider list/show/doctor.
    • NDJSON progress and an early key.
    • Exit codes, applied by tagging provider-create errors only.
    • Shell-quoted recovery commands.
    • provider is treated as a local-only command.
  • The provisioning, cleanup and progress plumbing are carried over from feat(cli): create workspaces on environment recipes #40108.

Based on #39228 by @jutaz, a port of #28439.

Linked Issue

Refs #17292

Visual Proof

N/A: CLI only. Sample sessions are above; they are reconstructed from the CLI tests, not captured from a real VM.

Testing

  • I manually tested these changes locally. Not done: it needs a real recipe VM.
  • Automated tests added/updated

Tests:

  • index-worktree-create-provider.test.ts, 19 tests:
    • typed target and key sent
    • a key is generated when none is given
    • NDJSON progress on stderr
    • exit 2 for invalid input
    • exit 5 for destroy-failed and for lost contact after the host was recorded
    • exit 1 when the failed create destroyed what it started
    • exit 4 with the workspace when the agent launch fails
    • older host refused
    • plain creates keep exit 1
    • provider list and provider show
  • workspace-provider-target.test.ts: the grammar round-trips.
  • workspace-providers.test.ts: namespaces, shadowing, the listing shape.
  • recipe-workspace-create.test.ts, 18 tests: orchestration, failure data, host outcomes.
  • RPC method tests: progress, paired-device refusal, dedupe key.
  • Transport tests on both ends.

Local (macOS):

  • pnpm tc, oxlint and oxfmt, check:code-quality:changed, verify:rpc-params-catalog and verify:bundled-skill-guides all pass.
  • src/cli, src/main/ephemeral-vm, src/main/ipc/ephemeral-vm*, src/main/runtime/rpc and workspaces/creation pass, except one existing timing test (terminal-send-ordered-input) that fails locally under load.

Risk

Draft. If merged as-is: Low for anyone who doesn't pass --on. Medium for the new path, because it starts machines. The desktop recipe flow uses the extracted provisioning and cleanup with their bodies unchanged.

AI Disclosure

Agent skill upstream boundary

  • Not applicable.

Checklist

  • Explained what changed and why
  • Stated the risk

`orca worktree create --on <target>` picks where a workspace runs.
- An existing host (local, ssh:<id>, runtime:<id>, a host name) works
  exactly like --host.
- A provider target creates a new host for the workspace first:
  recipe:<id> (orca.yaml environment recipe) or plugin:<plugin>/<id>
  (approved plugin recipe).
- `orca provider list/show/doctor` shows and checks providers, with
  versioned JSON (schemaVersion 1, allow-listed fields).

Provider creates:
- run through the same main-side provisioning the desktop uses
  (write-ahead record, step timeouts, cancellation) and the shared cleanup
- send an idempotency key, keyed by target, so a retry returns the same
  workspace
- report named steps (and the new host's id as soon as it's recorded) on
  long-poll keepalive frames, printed as text or NDJSON on stderr
- fail with host_create_failed, whose data says the step, the provider's
  failure code and whether the new host was destroyed

Exit codes for provider creates: 2 invalid input, 4 the workspace exists
but a follow-up failed, 5 a host may still be running. Plain creates keep
exit 1.

Based on #39228 by jutaz, a port of #28439.

Co-authored-by: Justas Brazauskas <[email protected]>

This branch has not been deployed

No deployments
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