fix(sidebar): scope project group display labels by host to prevent cross-host path collision (#8345)
Summary
Fixes #8345.
When two repos on different hosts share the same absolute path string, the sidebar group-by-Project headers show the same display name for both groups â one project's header silently overwrites the other.
Root cause: getRepoDisplayLabelsByPath() keys its map solely by item.path. A later item with the same path on another host overwrites the earlier entry. The collision-handling logic only disambiguates same-displayName items, so same-path-different-displayName collisions are never detected.
Fix
- Added
executionHostId?: string | nulltoRepoDisplayLabelItem - Exported
getRepoDisplayLabelKey()producing a composite key{executionHostId}::{path}when a host is known, falling back to barepath getRepoDisplayLabelsByPath()now uses the composite key for both storage and disambiguation updates- Callers (
withRepoSectionDisplayLabelsinworktree-list-groups.ts,NestedRepoChecklist.tsx) usegetRepoDisplayLabelKey()for map lookups
Changes
| File | Change |
|---|---|
src/renderer/src/lib/repo-display-labels.ts |
Add executionHostId to type, export key helper, use composite key |
src/renderer/src/lib/repo-display-labels.test.ts |
2 new tests: same-path-different-host + absent-hostId fallback |
src/renderer/src/components/sidebar/worktree-list-groups.ts |
Use getRepoDisplayLabelKey() for lookup |
src/renderer/src/components/repo/NestedRepoChecklist.tsx |
Use getRepoDisplayLabelKey() for lookup |
Testing
pnpm test: 6/6 pass (4 existing + 2 new)pnpm lint: 0 warnings, 0 errorspnpm typecheck: passing
No visual change
No visual change for users without cross-host same-path repos. The fix prevents label collisions that already corrupt display.
Cross-platform / SSH / remote notes
The bug is most likely to trigger on SSH hosts where home directories share the same absolute path as the local machine. The fix scopes the map key with executionHostId (local, ssh:..., or runtime:...). NestedRepoChecklist is unaffected because NestedRepoCandidate does not carry executionHostId â the key falls back to bare path, preserving existing behavior.
No actionable comments were generated in the recent review. đ
âšī¸ Recent review info
âī¸ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e8e2d53f-9c99-4666-b174-8d64091a72af
đĨ Commits
Reviewing files that changed from the base of the PR and between 1a59ed8338720fc3d5a6ebbe704f8da52d8eab07 and f7c080746456b3fc51b33b295170f0219ecf83a6.
đ Files selected for processing (4)
src/renderer/src/components/repo/NestedRepoChecklist.tsxsrc/renderer/src/components/sidebar/worktree-list-groups.tssrc/renderer/src/lib/repo-display-labels.test.tssrc/renderer/src/lib/repo-display-labels.ts
đ§ Files skipped from review as they are similar to previous changes (4)
- src/renderer/src/lib/repo-display-labels.test.ts
- src/renderer/src/components/repo/NestedRepoChecklist.tsx
- src/renderer/src/lib/repo-display-labels.ts
- src/renderer/src/components/sidebar/worktree-list-groups.ts
đ Walkthrough
Walkthrough
Repository display labels now use keys combining executionHostId and path when available, with path-only keys as a fallback. The label map populates and updates entries using this derived key. Repository checklist and sidebar group rendering use the same helper, and tests cover both host-specific collisions and missing execution host identifiers.
đĨ Pre-merge checks | â 5
â Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | â Passed | The title is concise and accurately describes the host-scoped label-key fix for sidebar project group collisions. |
| Description check | â Passed | The description covers the summary, fix, changes, testing, and notes, though several template sections are omitted. |
| Linked Issues check | â Passed | The PR implements host-scoped display-label keys, updates callers, and adds regression tests for the same-path cross-host collision in #8345. |
| Out of Scope Changes check | â Passed | The changes stay focused on repo display-label keying and related lookups, with no clear unrelated additions. |
| Docstring Coverage | â Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
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 @coderabbitai help to get the list of available commands.
Thank you so much for this fix, @sudoeren â your diagnosis was spot on. Both of our PRs converged on exactly the same idea: host-scoping the display-label map so two repos that share the same absolute path across different hosts (e.g. a local /Users/alice and an SSH host's /Users/alice) no longer overwrite each other's sidebar label.
We landed #8511 for one reason: instead of reading repo.executionHostId directly, it derives the host from the canonical getRepoExecutionHostId(repo) helper. That matters because SSH folder-repos in the reported scenario (#8345) leave executionHostId unset and only carry a connectionId â so a direct read falls back to a path-only key and the collision persists for that exact case. getRepoExecutionHostId handles it by falling back to ssh:<connectionId>, so the label map stays correctly host-scoped even when executionHostId is absent. We also added an injective-key proof and an identical-name cross-host regression test to lock the behavior in.
Your approach was on the right track and it's genuinely appreciated â please keep the contributions coming! Closing this one in favor of #8511, which is now merged.