Skip to content

fix(sidebar): keep independent same-host checkouts of one repo as separate projects - #7237

Merged
nwparker merged 5 commits into
stablyai:mainfrom
Naxon:fix/sidebar-clone-grouping
Jul 3, 2026
Merged

nwparker merged 5 commits into
stablyai:mainfrom
Naxon:fix/sidebar-clone-grouping

Conversation

@Naxon

@Naxon Naxon commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

In the sidebar, multiple independent local checkouts of the same git repo on one host (e.g. app, app-clone-2, app-hotfix, all cloned from one github.com/owner/repo) collapse into a single project header instead of appearing as separate projects. All their worktrees nest under one arbitrarily-named project.

This is a re-regression of #5374. The sidebar groups checkouts by a host-independent project identity (github:owner/repo, derived from the git remote) so the same repo on Local + SSH shows as one project — but that same identity also collapses genuinely independent checkouts on one host. #5375 (and #6430 for WSL/Windows) fixed this by splitting same-host duplicates at the grouping layer. #6320 ("Per-Workspace Environments") then deleted that split so its new provisioned ephemeral-runtime copies would nest under one header — but it had no way to tell a provisioned copy from a genuine user checkout, so it collapsed everything.

This PR restores same-host checkout separation, scoped by the discriminator the data model already carries — ProjectHostSetup.setupMethod:

Implemented in src/renderer/src/components/sidebar/worktree-list-groups.ts:

  • isDistinctUserCheckout(setup) = setup.setupMethod !== 'provisioned'.
  • getProjectSetupSurfaceKey(setup) = projectId::hostId::{wsl:<distro> | windows-host | default}, classified by the checkout's path string (not the client OS, so SSH/remote clients holding a C:\ or \\wsl.localhost\ path for a remote host classify correctly). A Windows checkout and its WSL checkout of one project (same runtime host, different execution surfaces) are therefore not treated as duplicates.
  • buildProjectGroupingIndex counts real user checkouts per surface in one pass; a project with >1 on one surface is flagged in projectIdsRequiringSetupGroups.
  • getProjectGroupingForRepo returns the per-setup key project:${id}::setup:${repoId} only for a flagged project's distinct user checkouts; provisioned copies still return project:${id}.

The Cmd+J palette shares this grouping (via getProjectHeaderRevealTarget), so it surfaces each independent checkout as its own jump target too. The ::setup: key format is a pre-existing #5375/#6430 shape already parsed by WorktreeList.tsx reveal/drop logic (getProjectIdFromHeaderRowKey / getRepoIdsFromHeaderRowKey), so no downstream regression.

Maintainer take-over notes (@nwparker)

This PR was taken over for validation and polish. On top of the original author's work:

  • Merged latest main (no conflicts).
  • Reproduced the bug first on main with the added tests, then verified the fix flips them green (evidence below).
  • Replaced an inline Windows drive-letter regex with the shared isWindowsAbsolutePathLike helper (src/shared/cross-platform-path.ts) — deduplicates the pattern used in 8+ call sites and additionally buckets UNC \\server\share paths as a Windows surface instead of default. Safe direction: coarser bucketing can only increase splitting, never wrongly merge distinct checkouts.
  • Collapsed buildProjectGroupingIndex's two passes over projectHostSetups into one (each surface key computed once).
  • Tightened comments to AGENTS.md's two-line rule.

Reviewed under a hostile-author security screen (pure client-side, read-only grouping; no network/IPC/shell/filesystem/auth/dependency changes) — clean.

Evidence

Reproduced-before (fix reverted to main, PR tests kept) — 4 split assertions fail:

× splits independent same-host checkouts of one project into per-setup keys
× splits same-host checkouts of one project into separate per-setup groups
× splits all project setups when one host has duplicate checkouts
× splits duplicate user checkouts while a provisioned copy nests, on one host

AssertionError: expected [ 'project:project-1' ] to deeply equal [ …(2) ]
AssertionError: expected [ { type: 'header', …(7) } ] to have a length of 2 but got 1
AssertionError: expected [ 'project:github:stablyai/orca' ] to deeply equal [ …(3) ]
 Test Files  2 failed (2)
      Tests  4 failed | 119 passed (123)

The collapse is visible directly: same-host checkouts resolve to a single project:github:stablyai/orca header instead of one header per checkout.

Fixed-after (this branch) — all green:

 Test Files  2 passed (2)
      Tests  123 passed (123)
  • pnpm typecheck (node + cli + web) — pass
  • oxlint on touched files — pass
  • Downstream key round-trip verified in WorktreeList.tsx (::setup: parsing already present).

Provisioned-nesting coverage, the split×nest intersection, and the Windows+WSL-on-one-host case are all covered by the added unit tests.

ELI5

Imagine your sidebar is a shelf of labeled folders. If you download the same book (repo) into three different boxes on your desk, you want three folders on the shelf — one per box. A recent change meant to handle temporary "loaner" copies of a book accidentally started shoving all copies — including your three real ones — into a single folder with one box's name, hiding the other two. This change teaches the shelf to tell a real copy from a temporary loaner: real copies each get their own folder again, while temporary loaner copies still tuck neatly inside the main folder.

Trade-offs

Naxon added 3 commits July 3, 2026 13:59
…arate projects

Re-regression of stablyai#5374: PR stablyai#6320 removed the per-host-surface separation
added by stablyai#5375, so independent local clones of the same repo (shared origin
=> same github:owner/repo identity) collapse into one sidebar project again.

Restore the surface-key separation in worktree-list-groups.ts, scoped by
ProjectHostSetup.setupMethod: 'provisioned' (ephemeral-VM runtime copies)
still nest under the project header (preserving stablyai#6320), while real user
checkouts (legacy-repo / imported-existing-folder / cloned) each get their
own header when duplicated on one host surface.

Revert the two tests stablyai#6320 inverted and add coverage for a provisioned copy
nesting alongside a same-host user checkout.
The Cmd+J palette shares getProjectGroupingForRepo (via
getProjectHeaderRevealTarget) with the sidebar, so restoring same-host
checkout separation also splits independent `cloned` checkouts into
per-setup palette entries. Update the multi-setup test to assert the split
and add coverage that a `provisioned` runtime copy still nests under one
project key.
Guard the intersection of stablyai#5374 and stablyai#6320: when a project has two real
same-host user checkouts AND a provisioned copy, the real checkouts each get
their own per-setup header while the provisioned copy stays under the plain
project key (never a path-scoped ::setup: header). Locks the two features'
combined behavior so a future change can't silently regress either half.
@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR changes project grouping in the sidebar and command palette so same-project user checkouts on the same surface are split into separate per-setup keys, while provisioned runtime copies stay under the plain project key. worktree-list-groups.ts adds setup-surface detection, counts distinct user checkouts per project, and switches header targeting when splitting is required. The sidebar and palette tests are updated to match the new header and row-key behavior.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR changes sidebar grouping behavior, but linked issue #39 asks for an Add repo option in the repo filter dropdown. Implement the Add repo dropdown action described in #39 or update the linked issue references to match the actual work.
Out of Scope Changes check ⚠️ Warning All code changes focus on checkout grouping and Cmd+J behavior, which are unrelated to the linked Add repo dropdown requirement. Remove or relink the grouping changes, or add the missing repo-filter dropdown work so the PR scope matches the linked issue.
Description check ⚠️ Warning The description covers the change and testing, but it misses the required Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections. Add the missing template sections with a user-visible summary, screenshot note, test checklist, AI review details, security audit, and platform-specific notes.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly matches the main change: restoring separate grouping for same-host duplicate checkouts in the sidebar.

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.

🧹 Nitpick comments (1)
src/renderer/src/components/sidebar/worktree-list-groups.test.ts (1)

819-911: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Good combined-scenario coverage; consider adding WSL/Windows surface-key cases too.

This test nicely covers the intersection of split + nest behavior on one host. However, none of the added tests exercise the new getProjectSetupSurfaceKey WSL (parseWslUncPath) or Windows drive-letter branches — all fixtures use plain POSIX paths (/tmp/orca...), landing in the default surface bucket. Given these are new, non-trivial branches (case-insensitive distro matching, drive-letter regex), a couple of targeted cases would help lock in behavior, e.g.:

  • two checkouts with different WSL distros on the same host should NOT split,
  • two checkouts with the same WSL distro (or a Windows-host path) duplicated should split.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 357e6040-1227-45fa-9b83-6919372e469a

📥 Commits

Reviewing files that changed from the base of the PR and between a4f9dda and 1fe8946.

📒 Files selected for processing (3)
  • src/renderer/src/components/cmd-j/palette-results.test.ts
  • src/renderer/src/components/sidebar/worktree-list-groups.test.ts
  • src/renderer/src/components/sidebar/worktree-list-groups.ts

nwparker and others added 2 commits July 3, 2026 12:29
…ace count

Take-over polish of stablyai#7237:
- Use shared isWindowsAbsolutePathLike instead of an inline drive-letter
  regex, deduplicating the pattern and also bucketing UNC \\server\share
  paths as a Windows surface instead of falling through to default.
- Collapse buildProjectGroupingIndex's two passes over projectHostSetups into
  one, computing each surface key once and flagging ambiguous projects from
  the aggregated counts.
- Tighten why-comments to AGENTS.md's two-line rule.

No behavior change to the fix; all 123 sidebar/palette grouping tests pass.

Co-authored-by: Orca <[email protected]>
@nwparker

nwparker commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Maintainer take-over summary

I took this PR over for validation, hostile-author security screening, and polish. Summary of what I did and found:

Verdict: VALIDATED. The bug is real, still present on main, and this is the right fix.

Security screen — clean. Reviewed the full diff vs merge-base with a hostile eye: no network/exfiltration, no obfuscation, no CI/workflow/script/dependency/postinstall changes, no credential/keychain/shell/path-traversal/unicode tricks. It is pure client-side, read-only sidebar grouping logic. ProjectHostSetup.path is only classified (string-prefix + WSL UNC parse) into an in-memory React grouping key — never executed, resolved on disk, or interpolated into a command.

Root cause confirmed by git archaeology. #5375 added the same-host split; #6430 refined it for WSL/Windows; #6320 (39964149c8) deleted the exact projectIdsRequiringSetupGroups + getProjectSetupSurfaceKey mechanism and replaced it with unconditional collapse, so its new provisioned copies would nest — collapsing genuine user checkouts too. This PR restores the split gated on setupMethod !== 'provisioned', so #6320's provisioned-nesting feature survives.

Reproduced first, then verified. With the fix reverted to main (PR tests kept), the 4 split assertions fail — same-host checkouts collapse to a single project:github:stablyai/orca header. With the fix, all 123 pass. Full before/after output is in the PR body.

Changes I made on top of the author's work:

  • Merged latest main (no conflicts).
  • Reuse: swapped an inline /^[A-Za-z]:[\\/]/ drive-letter regex for the shared isWindowsAbsolutePathLike helper (used in 8+ call sites); also correctly buckets UNC \\server\share paths as a Windows surface. Verified this can only increase splitting, never wrongly merge distinct checkouts.
  • Simplification: collapsed buildProjectGroupingIndex's two passes over setups into one (each surface key computed once).
  • Trimmed comments to AGENTS.md's two-line rule.

Checks: pnpm typecheck (node+cli+web) pass · oxlint on touched files pass · 123/123 unit tests pass · two independent review rounds (correctness + cleanup/conventions, then a verify pass on my changes) — converged clean.

Not merging or approving — leaving that to a human maintainer. Also worth reopening #5374 upstream, which is currently marked completed but regressed.

@nwparker
nwparker merged commit 492306f into stablyai:main Jul 3, 2026
@nwparker

nwparker commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Merged — this passed our review bar. @Naxon thanks for the well-diagnosed fix! We confirmed the #6320 re-regression of #5374, kept your setupMethod discriminator, and folded in small polish (shared Windows-path helper, single-pass grouping index) before merging.

@nwparker

nwparker commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Thanks so much for this one, @Naxon. Independent checkouts of the same repo collapsing into each other is one of those things nobody notices until it's suddenly broken, and you pinned down exactly the right discriminator to tell them apart. Appreciate the careful work here — merged and shipped.

@nwparker

nwparker commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Hey Daniel — thank you for this one 🙏 The part that impressed me was the archaeology: tracing the collapse back to the #6320 "Per-Workspace Environments" change and realizing the provisioned discriminator was the clean seam. That's exactly the kind of root-cause instinct we love to see. Genuinely appreciate you taking the time. 🐋

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…arate projects (stablyai#7237)

* fix(sidebar): keep independent same-host checkouts of one repo as separate projects

Re-regression of stablyai#5374: PR stablyai#6320 removed the per-host-surface separation
added by stablyai#5375, so independent local clones of the same repo (shared origin
=> same github:owner/repo identity) collapse into one sidebar project again.

Restore the surface-key separation in worktree-list-groups.ts, scoped by
ProjectHostSetup.setupMethod: 'provisioned' (ephemeral-VM runtime copies)
still nest under the project header (preserving stablyai#6320), while real user
checkouts (legacy-repo / imported-existing-folder / cloned) each get their
own header when duplicated on one host surface.

Revert the two tests stablyai#6320 inverted and add coverage for a provisioned copy
nesting alongside a same-host user checkout.

* test(cmd-j): update palette grouping tests for same-host checkout split

The Cmd+J palette shares getProjectGroupingForRepo (via
getProjectHeaderRevealTarget) with the sidebar, so restoring same-host
checkout separation also splits independent `cloned` checkouts into
per-setup palette entries. Update the multi-setup test to assert the split
and add coverage that a `provisioned` runtime copy still nests under one
project key.

* test(sidebar): cover split + provisioned-nest on one host together

Guard the intersection of stablyai#5374 and stablyai#6320: when a project has two real
same-host user checkouts AND a provisioned copy, the real checkouts each get
their own per-setup header while the provisioned copy stays under the plain
project key (never a path-scoped ::setup: header). Locks the two features'
combined behavior so a future change can't silently regress either half.

* refactor(sidebar): reuse shared Windows-path helper, single-pass surface count

Take-over polish of stablyai#7237:
- Use shared isWindowsAbsolutePathLike instead of an inline drive-letter
  regex, deduplicating the pattern and also bucketing UNC \\server\share
  paths as a Windows surface instead of falling through to default.
- Collapse buildProjectGroupingIndex's two passes over projectHostSetups into
  one, computing each surface key once and flagging ambiguous projects from
  the aggregated counts.
- Tighten why-comments to AGENTS.md's two-line rule.

No behavior change to the fix; all 123 sidebar/palette grouping tests pass.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Neil <[email protected]>
Co-authored-by: Orca <[email protected]>
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.

2 participants