Repository navigation
fix(worktrees): decide setup before git worktree add on the host's create - #26006
Conversation
…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.
📝 WalkthroughWalkthroughWorktree 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 Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/runtime-local-worktree-setup.ts (1)
49-58: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDocument the intentional fallback, or narrow the catch.
The bare
catch {}swallows every error fromshouldRunSetupForCreate, not only the "Setup decision required" refusal. The comment explains theaskcase. 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.warnlevel 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
📒 Files selected for processing (8)
src/cli/handlers/worktree-setup-decision-recovery.tssrc/cli/handlers/worktree.tssrc/cli/index-worktree-create-target.test.tssrc/main/runtime/orca-runtime-tests/worktree-setup-and-startup-part-03.spec.tssrc/main/runtime/runtime-local-worktree-create.test.tssrc/main/runtime/runtime-local-worktree-create.tssrc/main/runtime/runtime-local-worktree-setup.test.tssrc/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.
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.


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.
agent.launch,worktree.create, the phone and the CLI use.git worktree add(worktree-remote.ts): a repo set to "ask" with no setup decision is refused with nothing created.runtime-local-worktree-setup.ts, and that check could throw. So:For users:
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 change:
runHooks→ run, else the request'ssetupDecision, else inherit) from one helper, so they cannot disagree.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.worktree createadds the--setup run|skipnext 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 orgit 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 withrunHooks, 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'sorca.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), andrunstill runs the hook there; nothing else covers that path.index-worktree-create-target.test.ts: the CLI prints the--setup run|skipnext 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:nodeandtc:clipass. 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
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Author: @BrennanKB5.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)