Skip to content

fix(cli): keep automated worktree creation in background - #11445

Merged
nwparker merged 1 commit into
mainfrom
nwparker/workspace-switching
Jul 30, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/workspace-switching

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Description

  • Keep orca worktree create --agent ... in the background unless the caller explicitly passes --activate.
  • Make local and federated orchestration worker-start run setup through setupDecision without also setting the legacy focus-coupled runHooks flag.
  • Update the version-matched Orca CLI guide and add regression coverage for CLI, local orchestration, and connected-server orchestration.

Root cause and version boundary

There were two overlapping activation paths:

  1. d10d01919a (June 2, before both v1.4.155 and v1.4.159) made --agent imply activate: true in the CLI.
  2. cd05f2ff93 added the composed orchestration worker path. It correctly sent activate: false, but also sent runHooks: true for setup. The runtime treats legacy runHooks as both “run setup” and “activate,” so the latter overrode the background request. That commit first appears in the v1.4.160-rc.1/v1.4.160 release line.

ELI5

Creating an automated worker should be like opening a new browser tab in the background. Orca was also pressing the new tab for you because the old “run setup” switch secretly doubled as a “show this workspace” switch. This separates those jobs: setup still runs, but only an explicit --activate changes what the user is looking at.

Proof of regression

The tests were changed and run before production code:

  • CLI regression: expected activate: false, received activate: true when only --agent was present.
  • Local orchestration regression: expected runHooks: false, received runHooks: true with setupDecision: run and activate: false.
  • Federated orchestration regression: the same runHooks: true override reproduced on the connected worker server.
  • A real Orca-supervised child worker also reported the newly created workspace as active during investigation.

Proof of fix

  • Focused regression/runtime matrix: 360 tests passed across 5 files.
  • Full unit suite: 40,858 passed, 70 skipped (3,864 files passed, 9 skipped).
  • pnpm run typecheck:node: passed.
  • pnpm run typecheck:cli: passed.
  • pnpm run check:code-quality:changed: 0 new findings.
  • pnpm run verify:bundled-skill-guides: passed.

Proof of no regression

  • Explicit --activate still sends activate: true.
  • Legacy --run-hooks still runs setup and activates, preserving its documented compatibility behavior.
  • setup=run|skip|inherit still produces truthful setup receipts and agent-first terminal creation.
  • Connected-server workers retain background activation, setup gating, Task ownership, and accepted dispatch input coverage.
  • Agent prompt delivery, repo inference, and generated version-matched CLI guidance remain covered.

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes two overlapping activation bugs that caused automated worktree creation (orca worktree create --agent ... and orchestration worker-start) to implicitly focus the new workspace in Orca's UI, even when the caller expected background creation.

  • CLI fix (worktree.ts): Removes Boolean(startupAgent) from the activate condition so --agent alone no longer implies activate: true; only explicit --activate or --run-hooks reveals the new worktree.
  • Orchestration fix (both local topology and federated paths): Replaces runHooks: setupDecision === 'run' with runHooks: false, decoupling repo setup (handled by setupDecision) from the legacy runHooks flag that secretly also triggered workspace activation.
  • Tests cover all three regression scenarios (CLI, local orchestration, connected-server orchestration) and verify that setup=run|skip|inherit, explicit --activate, and legacy --run-hooks still behave correctly.

Confidence Score: 5/5

Safe to merge; the changes are surgical one-liners in two production files and are fully covered by regression tests across all three affected code paths.

Each of the two root-cause sites receives a minimal, targeted fix (removing Boolean(startupAgent) from the activate expression and changing runHooks: setupDecision === 'run' to runHooks: false). The PR explicitly preserves backward-compatible behavior for --run-hooks and explicit --activate. Three independent regression test cases cover CLI, local orchestration, and federated orchestration paths; setup policy coverage (run/skip/inherit) is also verified. No existing tests were weakened — assertions were only tightened or expanded.

Files Needing Attention: No files require special attention. The production changes are in worktree.ts, orchestration-worker-topology.ts, and orchestration-federation.ts — all straightforward and consistent with each other.

Important Files Changed

Filename Overview
src/cli/handlers/worktree.ts Removes Boolean(startupAgent) from the activate expression; --agent alone no longer focuses the new worktree. Change is minimal and correct.
src/main/runtime/rpc/methods/orchestration-worker-topology.ts Sets runHooks: false so setup is driven solely by setupDecision, eliminating the activation side-effect of the legacy runHooks flag.
src/main/runtime/rpc/methods/orchestration-federation.ts Applies the same runHooks: false fix as the local topology path for the connected-server (federated) worker creation path.
src/cli/index.test.ts Updates CLI regression tests: --agent alone now expects activate: false, and a separate test verifies --activate still produces activate: true.
src/main/runtime/rpc/methods/orchestration-workers-new-worktree.test.ts Updates setup policy test to assert runHooks: false and activate: false for all setup values (run/skip/inherit).
src/main/runtime/rpc/methods/orchestration-federation.test.ts Adds runHooks: false assertion alongside existing activate: false check; also refactors the dispatch_input effects assertion to a type-safe approach.
skill-guides/orca-cli.md Corrects the skill guide bullet to state --agent alone stays in the background; only --activate and --run-hooks reveal the new worktree.
src/cli/bundled-skill-guides.ts Regenerates the bundled ORCA_CLI_MARKDOWN constant to match the updated skill-guides/orca-cli.md.
src/main/runtime/rpc/methods/orchestration.test.ts Updates local orchestration test to expect runHooks: false and activate: false when setup=run is passed to worker-start.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[orca worktree create] --> B{flags passed?}
    B -->|--agent only| C[startupAgent set\nactivate = false\nrunHooks = false]
    B -->|--activate| D[activate = true\nrunHooks = false]
    B -->|--run-hooks| E[activate = true\nrunHooks = true\nlegacy compat]
    B -->|neither| F[activate = false\nrunHooks = false\nbackground]

    C --> G[worktree.create RPC]
    D --> G
    E --> G
    F --> G

    subgraph orchestration["Orchestration worker-start (local + federated)"]
        H[worker-start request\nsetup=run/skip/inherit] --> I[setupDecision = params.setup]
        I --> J[runHooks = false\nactivate = false\nsetupDecision passed]
        J --> K[createManagedWorktree]
        K --> L{setupDecision?}
        L -->|run| M[Setup hooks run\nno activation]
        L -->|skip| N[Setup skipped\nno activation]
        L -->|inherit| O[Repo policy\nno activation]
    end

    G --> P{activate?}
    P -->|true| Q[Workspace revealed\nin Orca UI]
    P -->|false| R[Stays in background]
Loading

Reviews (1): Last reviewed commit: "fix(cli): keep automated worktree creati..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f406c5d4-9a9d-45df-913d-126057572bba

📥 Commits

Reviewing files that changed from the base of the PR and between 32926bc and 22fdd01.

📒 Files selected for processing (9)
  • skill-guides/orca-cli.md
  • src/cli/bundled-skill-guides.ts
  • src/cli/handlers/worktree.ts
  • src/cli/index.test.ts
  • src/main/runtime/rpc/methods/orchestration-federation.test.ts
  • src/main/runtime/rpc/methods/orchestration-federation.ts
  • src/main/runtime/rpc/methods/orchestration-worker-topology.ts
  • src/main/runtime/rpc/methods/orchestration-workers-new-worktree.test.ts
  • src/main/runtime/rpc/methods/orchestration.test.ts

📝 Walkthrough

Walkthrough

Updated worktree creation semantics so agent startup remains backgrounded unless activation is explicit. The CLI handler now derives activation only from --activate or --run-hooks, with tests and bundled documentation updated. Federated and worker orchestration paths now always pass runHooks: false, and related tests verify explicit activation and hook settings.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it does not follow the required template or include Screenshots, Testing, AI Review Report, Security Audit, or Notes. Rewrite it to use the repository template and add the missing sections, including screenshots/No visual change, testing checklist, AI review, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: automated worktree creation stays backgrounded unless explicitly activated.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@nwparker
nwparker merged commit 78b8a37 into main Jul 30, 2026
85 of 87 checks passed
@nwparker
nwparker deleted the nwparker/workspace-switching branch July 30, 2026 00:45
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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