Skip to content

fix(cli): worktree create sends the host --project/--host selected - #31066

Merged
nwparker merged 3 commits into
mainfrom
nwparker/cli-create-selected-host
Oct 20, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/cli-create-selected-host

Conversation

@nwparker

@nwparker nwparker commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​377 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​376
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​129 $\color{#cf222e}{\Huge{\mathbf{−}}}$​51 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​78

ELI5

orca worktree create --project X --host local picks the right copy of a project when it is set up on more than one machine. Then it sent the server only the project's id. If that id existed on two machines, the server couldn't tell which one was meant and refused with selector_ambiguous. The CLI now tells the server which machine it chose.

What Changed

  • Before:
    • --project … --host … resolved the right setup, then sent only repo: id:<repoId>. When the same repo id was set up on two hosts, worktree.create failed with selector_ambiguous.
    • --project-host-setup <id> ignored --host. When setup ids repeated across hosts, it took the first match.
  • After:
    • Wire: worktree.create and agent.launch (which reuses the same schema) accept a new optional repoHostId, and so does repo.show. The CLI builds one CliRepoTarget ({ repo, repoHostId? }) and spreads it into every call that looks the repo up: the GitLab-link check's repo.show, and the create itself.
    • Host: RuntimeRepoSelector (src/main/runtime/runtime-repo-selector.ts) carries the host along with the selector. resolveRepoSelector, showRepo and the runtime create's repoSelector all take it. Every later lookup therefore keeps the caller's host, including the startup-agent and startup-draft resolution, and nothing can drop it by forgetting a second parameter. The create dedupe key includes the host.
    • --project-host-setup: it now goes through the same host selection as --project. With --host, it picks that host's setup. Without it, when the id names setups on two hosts, it asks for --host instead of guessing. A miss names the host.

Why

  • Wire compatibility: clients and hosts update independently, so this adds one optional field and changes nothing else on the wire.
    • An older host drops the unknown field and behaves exactly as before: it still refuses an ambiguous id.
    • An older CLI sends no repoHostId, and a new host behaves exactly as before.
  • Field shape: the field follows the existing hostId-beside-an-id pattern that worktree.rm and the project IPC handlers use, rather than inventing a host-qualified selector string. An older host would reject a new selector string outright.

Codex review 6, item #6.

Linked Issue

N/A (internal review finding: Codex review 6 #6).

Visual Proof

N/A. CLI and RPC routing only.

Testing

  • Automated tests added/updated, or explained why not below
  • New src/cli/index-worktree-create-repo-host.test.ts:
    • --project --host local sends repoHostId.
    • A repeated --project-host-setup id with --host picks that host; without --host it asks.
    • --repo stays selector-only.
    • The GitLab-link repo.show carries the host.
    • A --project-host-setup miss names the host.
  • New src/main/runtime/runtime-worktree-create-repo-host.test.ts, at handler level through the real RpcDispatcher and OrcaRuntimeService:
    • repo.show resolves the row on the named host, and a bare duplicate id is still refused.
    • worktree.create keeps the host as plain, with startupAgent, and with startupDraft.
    • The agent.launch create-worktree path keeps the host.
    • The dedupe key separates hosts.
    • Reverting the startup-agent lookup fails two of these.
  • On main, the six new behaviour tests fail. All pass with the fix.
  • Existing CLI create and automation target suites still pass (552 tests across worktree RPC, workspaces and CLI create folders).
  • Live verification: none. The behaviour is in argument building and selector narrowing, which the tests drive end to end through main() and the real runtime selector.

Review

  • Codex (gpt-6.1-sol, high), round 1: two P2s. The startup-agent lookup and the GitLab-link repo.show dropped the host.
  • Opus, round 1: the same two P2s, plus three P3s: the dedupe key, the miss message, and no handler tests.
  • Fix: all of these are addressed as one class. The selector carries the host, rather than being patched call site by call site.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH and mixed versions: covered above.
  • Mobile: unchanged; it doesn't send the field.
  • Follow-up: automations (orca automation create --project … --host …) still persist a repo id without a host. That needs a stored-schema change, so it is out of scope here.

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)

Codex review 6 #6: the CLI picked the right setup but sent only its repo id,
so a repo id set up on two hosts failed as selector_ambiguous; and
--project-host-setup ignored --host when setup ids repeated.

worktree.create gains optional repoHostId (older hosts drop it and keep the
old behaviour); the runtime narrows the repo selector to that host.
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f314a6bb-a9b2-4f65-9c50-61862a3c1878
📥 Commits

Reviewing files that changed from the base of the PR and between d74d2ec and e99dca4.

📒 Files selected for processing: 2
  • src/main/runtime/runtime-worktree-create-repo-host.test.ts
  • src/main/runtime/terminal/launch/terminal-create-deduplication.ts
🚧 Files skipped from review as they are similar to previous changes: 2
  • src/main/runtime/runtime-worktree-create-repo-host.test.ts
  • src/main/runtime/terminal/launch/terminal-create-deduplication.ts

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

📝 Walkthrough

The CLI now resolves project-derived repository targets with an optional host ID and passes that target to worktree creation and GitLab link validation. Runtime repository selection accepts host-qualified selectors and filters matches by host. Worktree creation uses the host-qualified selector for repository lookup and deduplication. When no host ID is provided, selector-only lookup remains available.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to e99dc

Creating a worktree from a paired runtime may fail with repo_not_found when the host ID sent by the CLI differs from the one the server stores. Confirm that paired host IDs are translated before host filtering, or accept this risk, before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 38.89% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 21 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: worktree create now sends the host selected by --project and --host.
Description check Passed The description is complete and covers the user impact, implementation, rationale, linked issue context, testing, compatibility, scope, and checklist. It also clearly states that full lint, typecheck,…
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 is complete and covers the user impact, implementation, rationale, linked issue context, testing, compatibility, scope, and checklist. It also clearly states that full lint, typecheck, test, and build results were not reported as passing.

  • 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.

…ookup

Review follow-up (Codex + Opus on #31066): a separate repoHostId was dropped
by the startup-agent lookup, the CLI's GitLab link check and the create
dedupe key. RuntimeRepoSelector now carries the host with the selector, so
showRepo/resolveRepoSelector and startup-agent resolution keep it; the
create dedupe key includes it; repo.show gains the same optional
repoHostId; the CLI spreads one CliRepoTarget into every repo lookup.
Handler-level tests cover worktree.create (plain, startupAgent,
startupDraft), agent.launch, repo.show and the dedupe key.

@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: 2c7e2543-63e3-4f30-ae3f-679f20846bcb
📥 Commits

Reviewing files that changed from the base of the PR and between 46d0a00 and d74d2ec.

⛔ Files ignored due to path filters: 1
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing: 21
  • src/cli/handlers/worktree-gitlab-link-context.ts
  • src/cli/handlers/worktree.ts
  • src/cli/index-worktree-create-repo-host.test.ts
  • src/cli/index-worktree-create-target.test.ts
  • src/cli/worktree-project-target.ts
  • src/main/ipc/repos/repo-ipc-wsl-move-fence.test.ts
  • src/main/runtime/construction/runtime-construction-services.ts
  • src/main/runtime/construction/runtime-file-command-state.ts
  • src/main/runtime/rpc/methods/agent-launch-worktree-creation.ts
  • src/main/runtime/rpc/methods/agent-launch.ts
  • src/main/runtime/rpc/methods/repo.ts
  • src/main/runtime/rpc/methods/worktree-create-args.ts
  • src/main/runtime/rpc/methods/worktree.ts
  • src/main/runtime/runtime-managed-worktree-create-types.ts
  • src/main/runtime/runtime-repo-selector.ts
  • src/main/runtime/runtime-repository-settings-controller.ts
  • src/main/runtime/runtime-worktree-create-repo-host.test.ts
  • src/main/runtime/terminal/launch/terminal-create-deduplication.ts
  • src/main/runtime/workspaces/workspace-selectors.ts
  • src/shared/rpc-contract/github-repo-target-params.ts
  • src/shared/rpc-contract/worktree-create-params.ts

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

Comment on lines +16 to +20
export function worktreeCreateRepoSelector(
params: Pick<WorktreeCreateParams, 'repo' | 'repoHostId'>
): RuntimeRepoSelector {
return hostQualifiedRepoSelector(params.repo, params.repoHostId)
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C8 '\bresolvePairedCallerHostId\s*\(' --type=ts -g '!**/*.test.ts'
rg -nP -C5 "'projectHostSetup\.list'" --type=ts -g '!**/*.test.ts'
rg -nP -C3 'runtime:gpu' src/cli/index-worktree-create-target.test.ts

Repository: stablyai/orca

Length of output: 14601


🏁 Script executed:

set -e
printf '%s\n' '--- paired-caller mapper ---'
nl -ba src/main/runtime/rpc/methods/paired-caller-host-id.ts
printf '%s\n' '--- project runtime RPC methods ---'
nl -ba src/main/runtime/rpc/methods/project-runtime-rpc-methods.ts | sed -n '1,70p'
printf '%s\n' '--- setup listing definitions/usages ---'
rg -n -F --glob '*.ts' -e 'listProjectHostSetups' -e 'listRepos()' -e 'getRepoExecutionHostId' src/main src/shared
printf '%s\n' '--- runtime setup/repo implementation blocks ---'
rg -n -C8 -F --glob '*.ts' 'listProjectHostSetups' src/main
printf '%s\n' '--- create selector and handlers ---'
nl -ba src/main/runtime/rpc/methods/worktree-create-args.ts
rg -n -C12 -F --glob '*.ts' -e "'worktree.create'" -e "'agent.launch'" -e "'repo.show'" src/main/runtime/rpc/methods

Repository: stablyai/orca

Length of output: 42626


🏁 Script executed:

set -e
printf '%s\n' '--- listProjectHostSetups declarations and callers ---'
rg -n -C12 -F --glob '*.ts' -e 'listProjectHostSetups' -e 'listSetups' src/main
printf '%s\n' '--- project host setup handler ---'
nl -ba src/main/ipc/repos/project-host-setup-handlers.ts | sed -n '1,115p'
printf '%s\n' '--- execution-host representation ---'
nl -ba src/shared/execution-host.ts | sed -n '200,310p'
printf '%s\n' '--- host-qualified selector ---'
rg -n -C12 -F --glob '*.ts' -e 'function hostQualifiedRepoSelector' -e 'const hostQualifiedRepoSelector' -e 'resolveRepoSelector' src/main src/shared
printf '%s\n' '--- runtime host-list RPC binding ---'
rg -n -C15 -F --glob '*.ts' -e "'host.listSetups'" -e 'host.listSetups' src/main src/shared

Repository: stablyai/orca

Length of output: 41996


🏁 Script executed:

set -e
printf '%s\n' '--- setup creation and storage ---'
rg -n -C10 -F --glob '*.ts' -e 'createProjectHostSetup' -e 'getProjectHostSetups' -e 'hostId: getRepoExecutionHostId' src/main src/shared
printf '%s\n' '--- selector implementation ---'
rg -n -C15 -F --glob '*.ts' -e 'function resolveRepoSelector' -e 'function hostQualifiedRepoSelector' -e 'type RuntimeRepoSelector' src/main src/shared
printf '%s\n' '--- affected RPC handlers ---'
rg -n -C20 -F --glob '*.ts' -e 'worktreeCreateRepoSelector' -e 'hostQualifiedRepoSelector(params.repo' -e 'repoHostId' src/main/runtime/rpc/methods
printf '%s\n' '--- deduplication key and create path ---'
rg -n -C15 -F --glob '*.ts' -e 'dedupeWorktreeCreate' -e 'clientMutationId' -e 'repoHostId' src/main/runtime

Repository: stablyai/orca

Length of output: 45663


🏁 Script executed:

set -e
printf '%s\n' '--- selector implementation ---'
rg -n -C10 -F --glob '*.ts' -e 'resolveRepoSelector(selector' -e 'hostQualifiedRepoSelector' src/main/runtime src/shared
printf '%s\n' '--- worktree create args and handler ---'
nl -ba src/main/runtime/rpc/methods/worktree-create-args.ts
rg -n -C18 -F --glob '*.ts' -e 'worktreeCreateRepoSelector' -e 'dedupeWorktreeCreate' src/main/runtime/rpc/methods src/main/runtime
printf '%s\n' '--- agent launch and repo show host-qualified calls ---'
rg -n -C18 -F --glob '*.ts' -e 'hostQualifiedRepoSelector(params.repo' -e 'repoHostId' src/main/runtime/rpc/methods/agent-launch.ts src/main/runtime/rpc/methods/repo.ts src/main/runtime/rpc/methods/worktree.ts

Repository: stablyai/orca

Length of output: 45665


Translate paired host IDs before host filtering.

projectHostSetup.list can return local for a setup on the paired server, while the CLI sends runtime:<id>. The host-qualified selector then finds no repository because it compares the raw ID with getRepoExecutionHostId(repo), and the operation can fail with repo_not_found.

Use resolvePairedCallerHostId before building the selector in worktree.create, agent.launch create-worktree, and repo.show. Use the translated ID in the deduplication key as well.

@nwparker
nwparker merged commit abd1fcf into main Oct 20, 2026
44 checks passed
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