orca icon indicating copy to clipboard operation
orca copied to clipboard

fix(sidebar): scope project group display labels by host to prevent cross-host path collision (#8345)

Open sudoeren opened this issue 4 months ago â€ĸ 1 comments

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 | null to RepoDisplayLabelItem
  • Exported getRepoDisplayLabelKey() producing a composite key {executionHostId}::{path} when a host is known, falling back to bare path
  • getRepoDisplayLabelsByPath() now uses the composite key for both storage and disambiguation updates
  • Callers (withRepoSectionDisplayLabels in worktree-list-groups.ts, NestedRepoChecklist.tsx) use getRepoDisplayLabelKey() 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 errors
  • pnpm 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.

sudoeren avatar Jul 12 '26 09:07 sudoeren

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

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.tsx
  • src/renderer/src/components/sidebar/worktree-list-groups.ts
  • src/renderer/src/lib/repo-display-labels.test.ts
  • src/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.

â¤ī¸ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Jul 12 '26 10:07 coderabbitai[bot]

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.

nwparker avatar Jul 14 '26 01:07 nwparker