Skip to content

fix(worktrees): decide setup before git worktree add on the host's create - #26006

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/runtime-create-setup-decision-before-add
Oct 7, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/runtime-create-setup-decision-before-add

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​214 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​212
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​97 $\color{#cf222e}{\Huge{\mathbf{−}}}$​37 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​60

ELI5

When the phone or the CLI creates a workspace in a repo set to "ask before running setup", and the request doesn't say whether to run setup, the create fails. On main, though, the workspace has already been made by then, so a half-made workspace is left behind. Now the create refuses before making anything, the way the desktop app's create already does.

What Changed

The problem.

  • Orca has two code paths that create a git worktree:
    • the desktop window's path;
    • the host's path, which agent.launch, worktree.create, the phone and the CLI use.
  • The desktop path checks the repo's setup policy before git worktree add (worktree-remote.ts): a repo set to "ask" with no setup decision is refused with nothing created.
  • The host's path only checked after the add, in runtime-local-worktree-setup.ts, and that check could throw. So:
    • the create failed;
    • the new worktree and its branch stayed on disk;
    • the worktrees-changed event that the create sends at its end was skipped, so the workspace wasn't listed until something else refreshed it.

For users:

  • On the phone and CLI, asking for a workspace in an "ask" repo without a setup decision now fails cleanly, with "Setup decision required for this repository" and nothing created. Before, it failed the same way but left a half-made workspace.
  • A CLI or automation create in a repo whose setup policy is 'ask', with no --setup decision, now refuses before creating anything when the main checkout has a setup script, as the desktop and SSH creates already do; pass --setup run|skip.
  • The CLI's refusal now also prints Next step: Pass --setup run to run the setup script, or --setup skip to create without it. The desktop and phone choose setup in their own UI, so the host's shared error text is unchanged.
  • The desktop is unchanged; it already sends a decision.

The change:

  • The host's create checks the main checkout's setup policy before it adds the worktree, and before any other git work (base resolution, fetch, branch naming, the prepared-checkout claim). It runs just after the create records where it runs, so a refused create's failure telemetry still carries that host.
  • Both checks read the decision (runHooks → run, else the request's setupDecision, else inherit) from one helper, so they cannot disagree.
  • The later check, after the add, reads the new worktree's own orca.yaml, which can add a setup hook the main checkout lacks. That check no longer throws. Setup is skipped and the create returns its existing warning ("orca.yaml setup hook skipped …; pass --setup run to run it."), as the desktop create skips it. A create that already exists is not failed over a hook nobody was asked about.
  • The CLI's worktree create adds the --setup run|skip next step to that one refusal. It matches the host's exact message, which every host version sends, so it also helps against an older host.

Why

Deciding before the add is how the desktop create already works, so the two paths now agree. Leaving a worktree behind on a refused create is the one outcome neither path should produce.

Linked Issue

None.

Visual Proof

N/A: no UI change. The phone shows the same error text as before; the CLI adds one "Next step" line under it.

Testing

  • runtime-local-worktree-create.test.ts: an ask repo with no decision is refused before any git work: no default-base resolution, remote refresh, fetch, branch naming, prepared-checkout claim or git worktree add. The hooks are read from the main checkout only (no worktree path), and the failure telemetry still records the execution host. With an explicit decision, or with runHooks, it creates.

  • orca-runtime-tests/worktree-setup-and-startup-part-03.spec.ts (new case, through the whole managed create): an ask repo, no decision, and a setup hook only in the new worktree's orca.yaml. The create resolves, the worktrees-changed event fires, the setup receipt is { requested: 'inherit', hookFound: true, state: 'skipped' }, the warning is returned, and no setup runner is built.

  • runtime-local-worktree-setup.test.ts (new): the same skip on the in-process setup path (no window), and run still runs the hook there; nothing else covers that path.

  • index-worktree-create-target.test.ts: the CLI prints the --setup run|skip next step under the host's refusal.

  • Re-broken and watched fail: checking before the execution host is recorded, checking after base resolution, or reading the hooks with a worktree path each fail the refusal test; restoring the old throwing post-add check fails both skip tests; dropping the CLI wrapper fails the CLI test.

  • tc:node and tc:cli pass. The changed test files and every test file importing the changed modules pass (14 files, 1459 tests). The changed-code gate (oxlint scans) is clean.

  • I manually tested these changes locally

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

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Author: @BrennanKB5.

  • SSH: the host's SSH create already reuses the desktop's remote create, which checks before the add.
  • Folder workspaces have no setup step.
  • No wire change.

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)

…eate, so an undecided ask repo leaves nothing behind

The host's create (agent.launch, worktree.create, the phone and the CLI) only checked the setup policy
after adding the worktree. An ask repo with no setup decision then threw with the worktree already on
disk and no worktrees-changed event. It now refuses before the add, as the desktop create does, and a
setup hook the new branch adds (one nobody decided on) is skipped with a warning instead of failing a
create that already exists.
…fter recording its host

The pre-add refusal now runs after the create records its execution host, so a refused create's
failure telemetry still says where it ran; it still runs before any git work. Both setup checks
read the decision from one helper so they cannot disagree, and the post-add skip logs once.
The refusal test now also proves no base resolution, fetch or branch naming ran and that the
hooks came from the main checkout.
…the managed create

An ask repo with no decision, whose setup hook exists only in the new worktree's orca.yaml, now
creates, refreshes the worktree list, reports setup as skipped and returns the warning.
…decision

The host refuses an undecided create in an ask repo with "Setup decision required for this
repository", which desktop and phone answer in their own UI. The CLI now adds the next step:
pass --setup run or --setup skip.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review summary (head d15f078aa56)

The problem

On main, a workspace created from the CLI or the phone in a repo whose setup policy is "ask" fails when the request carries no setup decision ("Setup decision required for this repository"). That check ran only after git worktree add, so the failed create left a real worktree and branch on disk: a half-made workspace nobody asked for. The desktop app's own create already checks before the add, so it never had this problem.

What changes for users

  • CLI, "ask" repo, no --setup: the create is refused before anything is made. The error now adds a next step: "Pass --setup run to run the setup script, or --setup skip to create without it." (In --json it is under error.data.nextSteps.)
  • Base branch whose orca.yaml adds a setup script the main checkout doesn't have: the create now succeeds, setup is not run, and the existing warning says so ("orca.yaml setup hook skipped …; pass --setup run to run it."). On main this also failed after making the worktree.
  • Behavior change (intended): a CLI or automation create in a repo whose setup policy is "ask", with no --setup decision, now refuses before creating anything when the main checkout has a setup script, even if the chosen base branch has none. On main that create succeeded. The desktop and SSH creates already refuse this way; pass --setup run|skip.
  • Desktop and phone: unchanged in normal use. Both already ask the user and send a decision.

What review fixed

The design was kept. An independent from-scratch design arrived at the same shape: decide before the add, and never fail the create after the add (skip with a warning). It matches the desktop create and the common pattern. No split. Fixes pushed during review:

  • The early check now runs after the create records which host it runs on, so a refused create's failure telemetry keeps that field (efe4c9bf80f).
  • The setup decision (--run-hooks → run, else --setup, else inherit) is computed in one place for both checks, so they can't drift apart (efe4c9bf80f).
  • A skipped setup logs once instead of twice (efe4c9bf80f).
  • Tests:
    • the refusal test proves no git work (base lookup, fetch, naming, checkout claim, add) happens;
    • a new end-to-end test proves a hook found only on the new branch gives a successful create, a refreshed workspace list, a "skipped" setup result and the warning (efe4c9bf80f, 3c627b52a92).
  • The CLI next-step hint for the refusal (d15f078aa56). It is CLI-only on purpose: the shared host message is unchanged, because the desktop, agent.launch and the phone have no --setup flag.

Deferred

  • P2: the early check reads orca.yaml from disk on every create, even when the request already decided or the repo isn't "ask". It's cheap, and the desktop create does the same read.
  • P3: in the rare case where the phone sends no decision and the new branch adds a setup script, the phone banner shows the existing "pass --setup run" warning, a CLI-only hint. That text predates this PR (on main the same input failed and left an orphan).
  • Follow-up, not caused by this PR: other steps after the add could still fail a create that already made its worktree. A single point after which nothing can fail the create would remove that class.

Verified

  • Review: three reviewers in round 1 (the early check, the after-add skip, the architecture). A fresh round-2 reviewer on the fix commits found nothing. A readiness pass (remote/SSH, crash, security, performance, correctness, compatibility, cross-platform, code organization) found no P0 or P1.
  • Local checks: typecheck (tc:node, tc:cli) passed. 14 vitest files, every test file that imports the changed code, passed: 1459 passed, 1 skipped. Each new test failed with its fix reverted.
  • CI: green on d15f078aa56. Shard 2/5 was rerun after a CI runner shutdown, not from this PR.
  • Live CLI QA, PR vs main (macOS, hidden isolated hosts, each arm with its own CLI, a fixture repo with policy "ask"):
case main PR
main checkout has a setup script, no decision error, worktree + branch left behind refused, nothing created, next-step hint shown
same, --setup run created, setup ran created, setup ran
only the new branch has a setup script, no decision created, then error (orphan) created, setup skipped, warning returned
main checkout has a setup script, base branch doesn't, no decision created refused, nothing created (intended, matches desktop)

Final workspace lists of the two hosts after all four cases. On main the failed creates' workspaces remain (main-r1, main-r3); on the PR only the two successful creates exist.

main PR

Not verified

  • No UI, desktop-window or phone flow was exercised. The desktop path isn't changed, the PR adds no UI, and the phone sends a decision in these cases (verified in code, not on a device).
  • No Windows/WSL or SSH run. The SSH create already checked before the add on main and isn't touched. The WSL file read is the same one the desktop create does.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 7, 2026 01:17
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

Worktree creation now checks setup-hook decisions before Git operations. Setup preparation resolves the requested decision and continues with setup disabled if decision evaluation throws. The CLI adds --setup run and --setup skip guidance to matching setup-decision errors. Tests cover decision handling, creation behavior, and CLI output.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to d15f0

Worktree creation now refuses undecided setup before any git work and skips setup with a warning when a hook appears only in the new worktree. No merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 8 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 identifies the main change: the host checks setup decisions before running git worktree add.
Description check ✅ Passed The description covers the user impact, implementation, rationale, testing, visual proof, and checklist. It lists no linked issue, which may need attention if the author is an outside contributor.
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
  • Autopilot · 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.

🧹 Nitpick comments (1)
src/main/runtime/runtime-local-worktree-setup.ts (1)

49-58: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Document the intentional fallback, or narrow the catch.

The bare catch {} swallows every error from shouldRunSetupForCreate, not only the "Setup decision required" refusal. The comment explains the ask case. The only other behavior of this helper today is to throw that same error, so the practical risk is low. A future change that throws for a different reason would be silently turned into a skipped setup. The skipped-hook warning would then tell the user to pass --setup run, which would be misleading.

Consider logging the error at console.warn level before falling through. This keeps the skip safe and makes unexpected failures visible.

Proposed change
-    } catch {
+    } catch (error) {
+      console.warn(`[hooks] setup decision unresolved for ${worktreePath}:`, error)
       // Why: the new branch may add a setup hook the caller never decided on; the worktree exists,

Based on learnings: "avoid silently swallowing errors ... If a fallback is truly intentional and safe, add a comment explaining why it's safe."

Source: Learnings


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 11b374ec-bf82-497f-8486-37c50b0d2b88
📥 Commits

Reviewing files that changed from the base of the PR and between f6448a1 and d15f078.

📒 Files selected for processing (8)
  • src/cli/handlers/worktree-setup-decision-recovery.ts
  • src/cli/handlers/worktree.ts
  • src/cli/index-worktree-create-target.test.ts
  • src/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-03.spec.ts
  • src/main/runtime/runtime-local-worktree-create.test.ts
  • src/main/runtime/runtime-local-worktree-create.ts
  • src/main/runtime/runtime-local-worktree-setup.test.ts
  • src/main/runtime/runtime-local-worktree-setup.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.

@brennanb2025
brennanb2025 merged commit 7a59aa3 into main Oct 7, 2026
80 of 82 checks passed
brennanb2025 added a commit that referenced this pull request Oct 7, 2026
Resolves the conflict with #26006 in runtime-local-worktree-create.test.ts by keeping both
describe blocks. runtime-local-worktree-create.ts auto-merged: the setup check stays before
any base resolution, and the local-base decision stays after the !baseBranch check.
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