Skip to content

feat(cli): create workspaces on environment recipes - #28439

Closed
nwparker wants to merge 3 commits into
mainfrom
nwparker/cli-worktree-environment-recipe
Closed

nwparker wants to merge 3 commits into
mainfrom
nwparker/cli-worktree-environment-recipe

Conversation

@nwparker

@nwparker nwparker commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​394 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​394
Prod 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​731 $\color{#cf222e}{\Huge{\mathbf{−}}}$​199 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​532

ELI5

An agent can create its own VM or sandbox workspace with orca worktree create --recipe <id>, then start work there without opening the desktop composer.

What Changed

The CLI verifies recipe support, then asks the provisioning host to run the selected environmentRecipes entry. The host reuses desktop provisioning, connects to the managed Orca server, registers the checkout, and adopts its primary root at the pinned source commit and requested branch. The result includes recipeEnvironmentId for follow-up commands. With --agent, the CLI launches on that server using the existing agent launch flow, including model, effort, prompt delivery, and safe replay.

Why

Recipe provisioning was available only from the desktop composer. Sharing provisioning and checked-root adoption keeps the CLI and desktop behavior aligned instead of introducing a separate VM implementation. Capability checks prevent older hosts from silently ignoring the recipe and creating a local checkout. Agent recovery commands address the existing remote workspace, avoiding a second provisioning attempt.

Linked Issue

Refs #17292 and #17026. Implements the creation half of #17026 using the current managed-server architecture. Environment teardown is handled separately in #28435; both PRs target main independently.

Visual Proof

N/A — CLI/RPC change; no renderer components or layouts change.

Testing

124 tests passed across recipe orchestration, CLI recipe selection/agent launch, existing CLI create/parent/host flows, IPC provisioning/cancellation, pinned-ref selection, root verification/adoption, RPC dispatch, and long-poll transport. Full pnpm tc, changed-code quality, RPC parameter catalog, bundled skill guide, and skill manifest checks passed on macOS. Real cloud infrastructure and Windows/Linux execution were not exercised.

  • I manually tested these changes locally
  • Automated tests added/updated

Review

Provisioning stays on the host that owns the recipe; checkout adoption and agents run on the serving host. Failed setup/adoption triggers destroy and retains any failed-cleanup record. Provider references, CLI provenance, comments and parent lineage are preserved. recipeId and adoption provenance are optional wire fields. Only provisioned-root SSH recipes are supported, matching the reference PR; sparse checkout and forced repo setup are refused before provisioning. The recipe create script owns setup.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer code or assets copied.

Notes

CLI recipe creation must run against the provisioning host, without an environment/pairing selector. Direct agent.launch requests embedding a recipe are refused; the CLI performs creation followed by launch on the existing remote workspace. CI covers the full build and broader checks.

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
  • Full lint, typecheck, test, and build suite pass (CI will cover)

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The change adds worktree create --recipe support. The CLI checks runtime capability, requests recipe-based workspace creation, and can launch an agent on the created environment. The runtime provisions the recipe environment, sets up and adopts its checkout as a managed worktree, and records lineage and CLI provenance. Provisioning and adoption failures trigger cleanup paths. The CLI guide documents supported options and recovery after a failed agent launch.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to dde4d

If a recipe workspace creation times out or is interrupted, the cloud machine keeps running without being reported to the user. Retrying the command can then create a second billed machine. Wire cancellation or retry deduplication before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description covers the user-facing change, implementation, rationale, testing, limitations, and review considerations. The Linked Issue section uses issue references but does not provide the requi… Update the Linked Issue section with an actual issue relationship, such as Fixes #17026 or another appropriate linked issue. Keep the existing references as supplemental context if needed.
Docstring Coverage Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 21 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: CLI creation of workspaces from environment recipes.
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.
Full details: Description check

Explanation

The description covers the user-facing change, implementation, rationale, testing, limitations, and review considerations. The Linked Issue section uses issue references but does not provide the required actual issue link or Fixes relationship.

Full details: Docstring Coverage

Explanation

Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 21 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • 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: cc4b1ab0-14cf-46f7-a6b8-303016a4ab4b
📥 Commits

Reviewing files that changed from the base of the PR and between 26a265d and dde4d64.

📒 Files selected for processing: 23
  • skill-guides/orca-cli.md
  • src/cli/bundled-skill-guides.ts
  • src/cli/handlers/worktree-create-recipe.ts
  • src/cli/handlers/worktree.ts
  • src/cli/index-worktree-create-recipe.test.ts
  • src/cli/specs/core.ts
  • src/main/ephemeral-vm-cli-workspace-create.ts
  • src/main/ephemeral-vm-environment-provision.ts
  • src/main/ephemeral-vm-recipe-workspace-create.test.ts
  • src/main/ephemeral-vm-recipe-workspace-create.ts
  • src/main/ipc/ephemeral-vm.ts
  • src/main/provisioned-root-checkout.ts
  • src/main/runtime/orca-runtime-get-status.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/agent-launch-target-authorization.ts
  • src/main/runtime/rpc/methods/worktree-provisioned-root-method.ts
  • src/main/runtime/rpc/methods/worktree-recipe-create-method.test.ts
  • src/main/runtime/rpc/methods/worktree.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-long-poll.ts
  • src/main/startup/main-process-runtime-service.ts
  • src/shared/rpc-contract/worktree-create-params.ts
  • src/shared/rpc-contract/worktree-provisioned-root-params.ts
  • src/shared/worktree-recipe-create-capability.ts

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

Comment on lines +57 to +70
provision: () =>
provisionRecipeEnvironment(
store,
userDataPath,
{
repoId: repo.id,
recipeId: recipe.id,
workspaceName: params.name,
projectId,
branch: branchName,
ref: params.baseBranch
},
pluginRecipes
),

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.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Pass a cancellation signal into recipe provisioning.

provisionRecipeEnvironment accepts options.signal, but this call passes no options. The recipe flow has three phases: VM provisioning, the remote projectHostSetup.setupExistingFolder call, and worktree.adoptProvisionedRoot. Each remote call has its own 600 s budget. The CLI waits a total of 600 s (timeoutMs: 600_000 in src/cli/handlers/worktree-create-recipe.ts).

If the CLI times out or the user interrupts it, the host continues. It creates the VM and the remote workspace, but the caller never receives recipeEnvironmentId. The CLI does not send a clientMutationId, so a retry is not deduplicated and provisions a second machine. The first VM stays running and incurs cost, and the user does not know about it.

Wire the RPC abort signal from the long-poll context through createManagedRecipeWorkspace into createCliRecipeWorkspace. Pass it to provisionRecipeEnvironment. The existing catch in createProvisionedRecipeWorkspace then destroys the VM on abort. If the long-poll path does not supply context.signal for worktree.create, add that wiring. Alternatively, have the CLI send a clientMutationId so a retry joins the in-flight create.

🔧 Sketch
--- "a/src/main/ephemeral-vm-cli-workspace-create.ts"
+++ "b/src/main/ephemeral-vm-cli-workspace-create.ts"
@@ -54,20 +54,21 @@
   return createProvisionedRecipeWorkspace(
     { params, branchName, projectId },
     {
       provision: () =>
         provisionRecipeEnvironment(
           store,
           userDataPath,
           {
             repoId: repo.id,
             recipeId: recipe.id,
             workspaceName: params.name,
             projectId,
             branch: branchName,
             ref: params.baseBranch
           },
-          pluginRecipes
+          pluginRecipes,
+          args.signal ? { signal: args.signal } : {}
         ),
       call: (environmentId, method, payload) =>
         callRuntimeEnvironment(userDataPath, `id:${environmentId}`, method, payload, 600_000),
       attach: (runtimeId, workspaceId) => {

Also add signal?: AbortSignal to the createCliRecipeWorkspace args. Thread context.signal from the worktree.create handler through createManagedRecipeWorkspace and the registered creator.

@ArturMakowski

Copy link
Copy Markdown

Strong +1. This is the missing piece for my setup, and I'd use it the day it lands.

Use case: I run an orchestrator agent, a skill driving orca orchestration task-create / worker-start, that fans tickets out to 10–15 worker agents. Running all of them on one laptop melts it: the harness, Docker, test suites and frontend builds compete for the same CPUs. Paired servers (worker-start --on ) already move workers onto a fixed box. What I can't do from the CLI is give each worker its own throwaway VM, which is exactly what environmentRecipes do from the desktop dialog.

What I'd need from the CLI path:

  1. --recipe on orchestration worker-start too, not only worktree create, so the orchestrator can route per task: local, --on or --recipe fly.
  2. Reliable destroy on worktree rm, worker-abandon and task completion (see [Bug]: Recipe destroy never runs and the VM leaks when a runtime's repo id no longer resolves #17293 / fix(workspace): destroy recipe environments on CLI and mobile removal #28435). With per-second billing, a leaked VM is the main risk of handing creation to an agent.
  3. In the JSON result: recipeEnvironmentId (already there 👍) plus some cost or lifetime hint, ideally a TTL/idle-timeout option on the recipe, so an orchestrator can enforce a budget.
  4. Setup hooks running on the recipe host, so per-worktree secrets like .env get copied in the same way as for local worktrees.

Happy to test against Fly or Vercel Sandbox once it's in a build.

@tatwizard

tatwizard commented Oct 20, 2026 •

Copy link
Copy Markdown

+1, really looking forward to seeing this merged. Thank you so much!

@steinafortuin

Copy link
Copy Markdown

+1

@jutaz

jutaz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

@nwparker I need this and #28435 for a controller setup (#30422): a headless orca serve that provisions a VM per workspace when a paired client creates one. Both PRs now conflict with #31771, which moved the ephemeral-vm-* modules into src/main/ephemeral-vm/.

Are you planning to rebase them? If not, I can port both onto current main as follow-up PRs that keep your commits and authorship and link back here, and close mine if you update yours. On top of them I'd add a recipe-listing RPC and composer support for a paired server's recipes.

@jutaz

jutaz commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

@nwparker thanks for landing #36838. One more question about this PR and #28435. Host-side recipe create and host-side destroy are the two things a headless controller still lacks: a phone or laptop can't create a VM workspace through it, and removing one leaves the VM running. Both PRs now conflict with main (#31771 moved the modules).

Would you rather finish them yourself, or should I port both onto current main with your authorship kept, like you did with mine? Either works for me. #36924 lists the whole use case and #36923 the resume gap that goes with them.

@tatwizard

Copy link
Copy Markdown

Thanks @nwparker for all the work here, and @jutaz for offering to port it. Whichever path is easier for you works for me. I'm not trying to rush anything, just adding a data point.

My use case is similar to @ArturMakowski 's above. I use boat.dev, and with this PR an orchestrator skill could create each worktree independently on its own boat.dev sandbox, all running in parallel. That would let Orca drive hundreds of worktrees at once. On a local machine I hit resource limits long before that, and creating recipe workspaces by hand from the desktop composer doesn't scale. With worktree create --recipe (and ideally --recipe on orchestration worker-start too), the orchestrator can do it.

This PR (create) and #28435 (destroy) are exactly the two pieces needed for that loop. Once a rebased build is available, I'm happy to test it end to end against a boat.dev recipe and report back.

@jutaz

jutaz commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@nwparker I've ported this onto current main as #39228 and #28435 as #39235, since both had drifted far behind (#31771 moved the modules, and #38842/#39038 added the sleep coordinator). Your commits are cherry-picked with your authorship. My commits on top are kept separate and listed in each PR body, so you can see exactly what you didn't write.

The two stay independently mergeable, as you split them, and they merge cleanly in either order. Both have open questions for you in their Review sections, notably the created lifecycle event and whether phones may start a recipe create. If you'd rather land your own versions, close mine.

nwparker added a commit that referenced this pull request Nov 9, 2026
`orca worktree create --recipe <id>` creates the workspace on a new
environment from one of the repo's environment recipes, and
`orca vm recipe list` shows which recipes it accepts.

The desktop app on the provisioning computer runs the same main-side
provisioning the composer uses (write-ahead record, per-step timeouts,
cancellation), registers the project on the environment's Orca server,
then creates (orca-worktree) or adopts (provisioned-root) the
workspace there. Named progress steps ride on long-poll keepalive
frames, so the CLI prints them to stderr; older CLIs ignore them. A
failure after the VM exists destroys it through the shared cleanup and
returns recipe_workspace_create_failed with the failed step, the
recipe failure code and whether the destroy finished. Ctrl+C aborts
the request and destroys a started environment.

Paired devices cannot start a recipe create. Hosts advertise
worktree.recipe-create.v1 only when the desktop wires the recipe
service, so orcad and older hosts are refused before anything runs.

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

Co-authored-by: Justas Brazauskas <[email protected]>
nwparker added a commit that referenced this pull request Nov 9, 2026
* feat(cli): create workspaces on environment recipes

`orca worktree create --recipe <id>` creates the workspace on a new
environment from one of the repo's environment recipes, and
`orca vm recipe list` shows which recipes it accepts.

The desktop app on the provisioning computer runs the same main-side
provisioning the composer uses (write-ahead record, per-step timeouts,
cancellation), registers the project on the environment's Orca server,
then creates (orca-worktree) or adopts (provisioned-root) the
workspace there. Named progress steps ride on long-poll keepalive
frames, so the CLI prints them to stderr; older CLIs ignore them. A
failure after the VM exists destroys it through the shared cleanup and
returns recipe_workspace_create_failed with the failed step, the
recipe failure code and whether the destroy finished. Ctrl+C aborts
the request and destroys a started environment.

Paired devices cannot start a recipe create. Hosts advertise
worktree.recipe-create.v1 only when the desktop wires the recipe
service, so orcad and older hosts are refused before anything runs.

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

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

* fix(cli): report the VM outcome when connecting fails; record no cross-host parent

* fix(vm-recipes): destroy the VM when recording its environment fails; reset exitCode in CLI tests

* perf(types): keep recipe orchestration out of the runtime's type graph

---------

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

nwparker commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #40108 (merged), built on the port in #39228 by @jutaz. Removal follows in #40119.

@nwparker nwparker closed this Nov 9, 2026
nwparker added a commit that referenced this pull request Nov 9, 2026
`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). provider:<id> is reserved for built-in
  providers.
- `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]>
nwparker added a commit that referenced this pull request Nov 9, 2026
`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]>
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.

5 participants