Repository navigation
fix(worktree): collapse duplicate "Local Mac" run targets in the host picker - #10472
Conversation
… 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.
📝 WalkthroughWalkthroughAdds 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)
✨ Finishing Touches📝 Generate docstrings
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/main/git/repo.ts (1)
162-197: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTrim 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 winShorten 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
📒 Files selected for processing (8)
src/main/git/repo-detection.test.tssrc/main/git/repo.tssrc/main/ipc/repos-add-linked-worktree.test.tssrc/main/ipc/repos.tssrc/renderer/src/lib/project-host-setup-options.test.tssrc/renderer/src/lib/project-host-setup-options.tssrc/renderer/src/lib/project-host-workspace-target.test.tssrc/renderer/src/lib/project-host-workspace-target.ts
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.
… 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.
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.
resolveWorkspaceCreationTargetpicks the first matchingprojectId+hostIdsetup 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
Reporecords collapsed into a single project. Project identity is derived ingetProjectProviderIdentitywith a fallback chain —upstream→repoIcon.label→gitRemoteIdentity. A linked worktree ofstablyai/orcacarriesrepoIcon.label: "stablyai/orca", identical to the main checkout, so all three landed on projectgithub:stablyai/orca. The projection then emits oneProjectHostSetupperRepo, giving threereadysetups onhostId: local, and the picker labels each row by host.They became separate repos because
repos:adddeduped 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
src/main/git/repo.tsgetLinkedWorktreeMainRepoRoot()— returns the main checkout when a path is a linked worktree, elsenull.src/main/ipc/repos.tsaddLocalRepoFromPathreturns the tracked main checkout instead of adding a duplicate. Prevents new duplicates.src/renderer/src/lib/project-host-setup-options.tsbuildReadySetupOptionsdedupes ready options by host. Fixes existing profiles.src/renderer/src/lib/project-host-workspace-target.tsOn the detection method
getLinkedWorktreeMainRepoRootcompares--git-diragainst--git-common-dirfrom a singlerev-parseinvocation — 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-topleveltodirname(--git-common-dir)and misread main checkouts as linked worktrees on macOS — git returns--show-toplevelsymlink-resolved (/private/var/...) whileresolve()yields/var/.... Both sides are nowrealpath-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
paththe 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
localsetups in state → oneLocal Macrow rendered, and thesshhost still renders separately asopenclaw.Tests — 15 new tests across 4 files:
repo-detection.test.ts— 7 tests against realgit 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 forkind: '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·typecheckclean ·lintclean.Regressions
None found. Areas checked:
ExecutionHostId, solocaland eachssh:<id>stay distinct rows; verified on screen (openclawrenders alongsideLocal Mac). Therepos:addguard 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.repoKind === 'git'; folder workspaces never invoke worktree detection. Covered by a test.Local Mac.normalizeRuntimePathForComparison; separator-difference test included. No new platform-conditional logic.nulland falls back to current behavior.Review follow-up (found in adversarial review)
The
repos:addguard originally matched any tracked repo on the main-checkout path, including akind: '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 (commit8f4c3da).Not covered: no data migration — existing profiles keep the redundant
Reporecords, 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:
addRemoteRepoFromPathhas no equivalent linked-worktree guard.getLinkedWorktreeMainRepoRootis synchronous and local-only, while the SSH path resolves through the asyncgitProvider.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 distinctssh:<id>host keeps its own row.Made with Orca 🐋