Skip to content

fix(worktree): collapse duplicate "Local Mac" run targets in the host picker - #10472

Merged
nwparker merged 2 commits into
mainfrom
nwparker/many-local-mac-why
Jul 25, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/many-local-mac-why

Conversation

@nwparker

@nwparker nwparker commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The Run on picker in the Create Worktree dialog rendered several identical Local Mac rows for one project — same label, same icon, differing only by the path subtitle. Two of the three pointed at git worktree directories that no longer exist on disk.

Worse than the visual noise: only the first row was ever reachable. resolveWorkspaceCreationTarget picks the first matching projectId + hostId setup and ignores the rest, so clicking rows 2 or 3 selected a target that silently resolved back to row 1's path. The dialog could show one path and create the workspace in another.

Root cause

Three separate Repo records collapsed into a single project. Project identity is derived in getProjectProviderIdentity with a fallback chain — upstream → repoIcon.label → gitRemoteIdentity. A linked worktree of stablyai/orca carries repoIcon.label: "stablyai/orca", identical to the main checkout, so all three landed on project github:stablyai/orca. The projection then emits one ProjectHostSetup per Repo, giving three ready setups on hostId: local, and the picker labels each row by host.

They became separate repos because repos:add deduped on path only. A linked worktree reports itself as its own --show-toplevel, so no path check can tell that it belongs to an already-tracked repo.

ELI5

You have one toolbox in the garage. You also made two shortcuts to that toolbox on your desk. The app looked at all three, saw "toolbox," and listed three toolboxes — but only ever opened the garage one. Two shortcuts were pointing at drawers you'd already thrown away.

This PR (a) stops the app from filing a shortcut as a new toolbox, and (b) makes the list show one entry per place, so what you click is what you get.

Changes

File Change
src/main/git/repo.ts New getLinkedWorktreeMainRepoRoot() — returns the main checkout when a path is a linked worktree, else null.
src/main/ipc/repos.ts addLocalRepoFromPath returns the tracked main checkout instead of adding a duplicate. Prevents new duplicates.
src/renderer/src/lib/project-host-setup-options.ts buildReadySetupOptions dedupes ready options by host. Fixes existing profiles.
src/renderer/src/lib/project-host-workspace-target.ts A stale draft naming a hidden same-host duplicate canonicalizes to the setup the picker shows. Closes the shown-path ≠ created-path gap.

On the detection method

getLinkedWorktreeMainRepoRoot compares --git-dir against --git-common-dir from a single rev-parse invocation — git's own canonical test. A linked worktree's git dir is <common>/worktrees/<name>; a main worktree's equals the common dir.

The first implementation compared --show-toplevel to dirname(--git-common-dir) and misread main checkouts as linked worktrees on macOS — git returns --show-toplevel symlink-resolved (/private/var/...) while resolve() yields /var/.... Both sides are now realpath-ed before comparison, which also handles git answering one flag absolutely and the other relative to cwd.

Git 2.25 baseline: both flags long predate it, and a relative answer resolves against path the way older git reports it.

Evidence of fix

Visible proof — same dev profile, same three stale repo records still on disk, live-reproducing. Uncropped app state, one Local Mac row, correctly resolved to the real main checkout /Users/nwparker/projects/orca:

Store state at capture time confirms the duplicates were still present and the fix is a display + resolution correction, not a data migration:

{"projectId": "github:stablyai/orca", "setups": [
  {"host":"local", "path":"/Users/nwparker/projects/orca",                                 "state":"ready"},
  {"host":"local", "path":".../workspaces/orca/pr-3235-terminal-file-link-actions",        "state":"ready"},
  {"host":"local", "path":".../workspaces/orca/pr-1908-external-editor-links",             "state":"ready"},
  {"host":"ssh:ssh-1784717562259-ryvoxs", "path":"/home/neil/Documents/orca",              "state":"ready"}
]}

Three local setups in state → one Local Mac row rendered, and the ssh host still renders separately as openclaw.

Tests — 15 new tests across 4 files:

  • repo-detection.test.ts — 7 tests against real git worktree add: linked worktree, main checkout, nested dir, bare repo, non-repo, missing path, git-unavailable. 31/31 pass.
  • repos-add-linked-worktree.test.ts (new) — 6 tests: returns tracked main checkout; still adds when main checkout is untracked; adds a normal repo; skips detection for kind: 'folder'; matches across Windows/POSIX separators; does not match a tracked SSH repo sharing the local path.
  • project-host-setup-options.test.ts — dedupe keeps the setup creation actually uses; one choice per host across multiple hosts.
  • project-host-workspace-target.test.ts — stale same-host id canonicalizes; a sole-on-host explicit id is preserved.

Guard against vacuous tests: stashed the 3 source files and confirmed exactly 5 of the new tests fail without the fix, then restored.

Full sweep: 1049 test files / 10973 tests passed, 0 failures · typecheck clean · lint clean.

Regressions

None found. Areas checked:

  • SSH / remote hosts — dedupe is keyed on ExecutionHostId, so local and each ssh:<id> stay distinct rows; verified on screen (openclaw renders alongside Local Mac). The repos:add guard filters on !repo.connectionId, so a tracked SSH repo whose remote path coincides with a local main checkout is not matched — covered by a dedicated test.
  • Folder workspaces — the guard is gated on repoKind === 'git'; folder workspaces never invoke worktree detection. Covered by a test.
  • Multi-host projects — one row per host preserved; not collapsed to a single row.
  • Legitimately distinct projects — dedupe is scoped per project's ready options, so two different projects each keep their own Local Mac.
  • Adding a worktree of an untracked repo — still adds normally; the guard only fires when the main checkout is already tracked.
  • Cross-platform — path comparison goes through the existing normalizeRuntimePathForComparison; separator-difference test included. No new platform-conditional logic.
  • Git compatibility — no flags newer than the 2.25 baseline; every git failure path returns null and falls back to current behavior.

Review follow-up (found in adversarial review)

The repos:add guard originally matched any tracked repo on the main-checkout path, including a kind: 'folder' record. A folder repo doesn't project onto the same project as the git worktree, so matching one would have suppressed a legitimate add while deduping nothing. The guard now also requires !isFolderRepo(repo), with a regression test verified to fail without the fix (commit 8f4c3da).

Not covered: no data migration — existing profiles keep the redundant Repo records, they're just no longer rendered or resolvable as separate targets. Removing them is a separate, riskier change (they may hold per-repo settings), so it's deliberately out of scope here.

Also not covered — SSH duplicate prevention: addRemoteRepoFromPath has no equivalent linked-worktree guard. getLinkedWorktreeMainRepoRoot is synchronous and local-only, while the SSH path resolves through the async gitProvider.isGitRepoAsync; covering it needs a new provider method, so it's a separate change. The renderer dedupe still fixes the visible symptom on SSH hosts — a remote project with duplicate same-host setups renders one row, and each distinct ssh:<id> host keeps its own row.

Made with Orca 🐋

… picker

A linked worktree added as its own project projects a second ready host
setup on the same project+host, so the run-target picker rendered N
identical "Local Mac" rows differing only by path. Only the first was
reachable — resolveWorkspaceCreationTarget takes the first project+host
match — so the extras pointed at paths that may no longer exist.

- Dedupe ready setup options by host in the picker (display fix for
  profiles that already hold duplicates).
- Canonicalize a stale draft's setup id to the setup the picker shows,
  so the displayed path is the path the workspace is created in.
- Reject a linked worktree at repos:add when its main checkout is
  already tracked, preventing new duplicates.
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Git linked-worktree detection that resolves linked checkouts to their main repository root. Local repository addition now reuses an already-tracked main checkout and covers path normalization and repository-type cases. Renderer setup options and workspace targets now canonicalize duplicate ready setups by project and host, with tests covering same-host and multi-host scenarios.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly summarizes the linked-worktree duplicate run-target fix in the host picker.
Description check ✅ Passed The description covers the problem, root cause, changes, testing, risks, and screenshots, with only minor template-heading omissions.
✨ Finishing Touches
📝 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.

@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

🧹 Nitpick comments (2)
src/main/git/repo.ts (1)

162-197: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Trim the new explanatory comments. Keep only the non-obvious rationale in concise, preferably single-line comments.

  • src/main/git/repo.ts#L162-L197: condense the JSDoc and inline implementation notes.
  • src/main/ipc/repos.ts#L199-L201: reduce the rationale to one concise line.
  • src/main/ipc/repos-add-linked-worktree.test.ts#L1-L8: replace the file header with a short test-purpose comment or remove it.

As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.

Source: Coding guidelines

src/renderer/src/lib/project-host-setup-options.ts (1)

142-146: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten or remove these explanatory comments.

  • src/renderer/src/lib/project-host-setup-options.ts#L142-L146: reduce to one concise canonicalization rationale.
  • src/renderer/src/lib/project-host-workspace-target.ts#L133-L135: reduce to one concise rationale.
  • src/renderer/src/lib/project-host-setup-options.test.ts#L202-L204: remove; the test name describes the scenario.
  • src/renderer/src/lib/project-host-workspace-target.test.ts#L125-L127: remove; the test name describes the scenario.

As per coding guidelines, comments “must be concise, limited to non-obvious information, and preferably one line.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e1702293-093a-4752-bd4e-d9bc62980f3a

📥 Commits

Reviewing files that changed from the base of the PR and between 7e1d7a8 and 72c99c8.

📒 Files selected for processing (8)
  • src/main/git/repo-detection.test.ts
  • src/main/git/repo.ts
  • src/main/ipc/repos-add-linked-worktree.test.ts
  • src/main/ipc/repos.ts
  • src/renderer/src/lib/project-host-setup-options.test.ts
  • src/renderer/src/lib/project-host-setup-options.ts
  • src/renderer/src/lib/project-host-workspace-target.test.ts
  • src/renderer/src/lib/project-host-workspace-target.ts

Comment thread src/main/git/repo.ts Resolved
Review follow-up: the repos:add guard matched any tracked repo on the main
checkout path, including a folder-kind record. A folder repo does not
project onto the same project as the git worktree, so matching it would
suppress a legitimate add without deduping anything.
@nwparker
nwparker merged commit eb545aa into main Jul 25, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… picker (stablyai#10472)

* fix(worktree): collapse duplicate "Local Mac" run targets in the host picker

A linked worktree added as its own project projects a second ready host
setup on the same project+host, so the run-target picker rendered N
identical "Local Mac" rows differing only by path. Only the first was
reachable — resolveWorkspaceCreationTarget takes the first project+host
match — so the extras pointed at paths that may no longer exist.

- Dedupe ready setup options by host in the picker (display fix for
  profiles that already hold duplicates).
- Canonicalize a stale draft's setup id to the setup the picker shows,
  so the displayed path is the path the workspace is created in.
- Reject a linked worktree at repos:add when its main checkout is
  already tracked, preventing new duplicates.

* fix(worktree): only dedupe a linked worktree against a git main checkout

Review follow-up: the repos:add guard matched any tracked repo on the main
checkout path, including a folder-kind record. A folder repo does not
project onto the same project as the git worktree, so matching it would
suppress a legitimate add without deduping anything.
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