Repository navigation
perf(git): skip the sparse probe for worktree listings that never read it - #18050
Conversation
…d it Three main-process call sites list a repo's worktrees to read `worktree.path` and nothing else, but went through the annotated listing, so each one paid a sparse-checkout probe per worktree and cached the result nobody consumed: - `registered-worktree-roots-cache.ts` rebuilds the filesystem-auth authorized roots. `invalidateAuthorizedRootsCache()` fires on every worktree create and remove, plus repo add/clone/settings changes, so this reruns constantly. - `filesystem-source-control-ai-targets.ts` checks whether a local repo owns a worktree path. - `hosted-review.ts` verifies a worktree belongs to the repo before granting access. The probe is an `fs.stat` of the per-worktree `info/sparse-checkout` plus, when that file is non-empty, a git config read. On a WSL-hosted repo both cross 9p. #17859 cached it and #17932 keyed that cache on the distro, which fixed a wrong answer but also meant the distro-less callers above populate a second entry per worktree — probed cold, revalidated on their own five-minute loop, and read by nobody. Worktree create/remove clears the sparse cache and dirties the roots cache together, so both variants go cold at once and the discarded half is re-probed in full on the next auth check. `listRepoWorktreeGraph` routes those callers to `listWorktreeGraph`, which already existed as the annotation-free listing (#17655). Doing only that would have cost a second `git worktree list`. The scan cache keys in-flight scans on a `kind`, and graph and lenient were separate kinds, so a roots rebuild overlapping a sidebar refresh would spawn its own subprocess where the two previously coalesced. That is a real regression on macOS, Linux and native Windows, where `getLocalProjectWorktreeGitOptions` returns `{}` and both callers land on the identical key; on WSL they already differ by distro and never shared. So the annotated listing is now the graph listing plus annotation, rather than a parallel scan of its own: `listWorktrees` awaits `listWorktreeGraph` and annotates the rows it returns. Both soften a Git failure to `[]`, so they can share one listing; strict keeps its own because it must be able to reject. The two kinds ran Git twice before and now run it once, so the overlap case gets strictly faster instead of paying for the opt-out. An annotated scan holds two in-flight entries now (its own, plus the graph listing it shares). Keeping its own entry matters: `detectSparseCheckoutCached` dedupes revalidation but not the initial fill, so two concurrent badge readers sharing only the graph scan would both probe. Per-platform delta: - macOS/Linux: fewer probes on the three call sites; one `git worktree list` instead of two when a graph and an annotated scan overlap. - native Windows, no WSL: same, and the saved subprocess is the expensive half. - Windows + WSL: the largest win. The discarded probes were 9p round-trips re-paid cold after every worktree create/remove. - SSH/relay: none. `listRepoWorktreeGraph` returns through the same provider branch as `listRepoWorktrees` before reaching local Git. - folder workspaces: none. Both return the same synthetic folder worktree. Not in this change: - The badge listing itself. It still probes, still annotates, and still keys on the distro exactly as #17932 left it. - The remaining `listRepoWorktrees` callers. They read `isSparse`, or feed rows to something that does.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (13)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe change adds graph-only worktree listing through Merge Risk: ⚪ Minimal · up to This change skips unnecessary sparse-checkout probing for path-only worktree lookups while preserving authorization paths and annotated listings. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed ELI5, change rationale, implementation scope, platform impact, verification results, and test coverage. However, it omits the required Linked Issue reference and several template sections, including Visual Proof with an N/A explanation, the Testing checklist, Review, Notes, Agent skill upstream boundary, and final Checklist. Resolution Add the required issue reference after "Fixes #". Add the missing template sections. For Visual Proof, state N/A and explain that there is no UI or interaction change. Complete the Testing checkboxes and document tested platforms. Complete the AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections as applicable.
✨ Finishing Touches 💡 1📝 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.
✅ No new issues found.
Reviewed changes
- Route path-only callers to the probe-free listing —
listRepoWorktreeGraphinrepo-worktrees.tsmirrorslistRepoWorktreesbut callslistWorktreeGraph, and the three callers that only readworktree.path(registered-worktree-roots-cache.ts,filesystem-source-control-ai-targets.ts,hosted-review.ts) now use it. - Layer annotation over the shared graph scan —
runAnnotatedWorktreeScaninworktree-scan-cache.tsmakeslistWorktreesbuild onlistWorktreeGraphinstead of running its owngit worktree list, so an overlapping graph and badge reader share one subprocess and only the badge reader pays the probe. - Tests —
worktree-scan-cache-annotation-reuse.test.ts(new) pins the probe-free/annotated split and the resolve-without-wait guarantee;worktree-scan-cache-sharing.test.tsandrepo-worktrees.test.tsupdate in-flight counts and delegation assertions for the nested entry.
I verified the three failure-softening and sharing invariants the layering depends on hold: detectSparseCheckout never throws (so listWorktrees still never rejects), annotateSparseCheckoutStatus copies the array before mutating (so the shared graph result is never polluted), and the nested graph entry is created synchronously before the outer lenient entry awaits, keeping both on the same generation. The three touched test files pass locally (34 tests).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…d it (stablyai#18050) Three main-process call sites list a repo's worktrees to read `worktree.path` and nothing else, but went through the annotated listing, so each one paid a sparse-checkout probe per worktree and cached the result nobody consumed: - `registered-worktree-roots-cache.ts` rebuilds the filesystem-auth authorized roots. `invalidateAuthorizedRootsCache()` fires on every worktree create and remove, plus repo add/clone/settings changes, so this reruns constantly. - `filesystem-source-control-ai-targets.ts` checks whether a local repo owns a worktree path. - `hosted-review.ts` verifies a worktree belongs to the repo before granting access. The probe is an `fs.stat` of the per-worktree `info/sparse-checkout` plus, when that file is non-empty, a git config read. On a WSL-hosted repo both cross 9p. stablyai#17859 cached it and stablyai#17932 keyed that cache on the distro, which fixed a wrong answer but also meant the distro-less callers above populate a second entry per worktree — probed cold, revalidated on their own five-minute loop, and read by nobody. Worktree create/remove clears the sparse cache and dirties the roots cache together, so both variants go cold at once and the discarded half is re-probed in full on the next auth check. `listRepoWorktreeGraph` routes those callers to `listWorktreeGraph`, which already existed as the annotation-free listing (stablyai#17655). Doing only that would have cost a second `git worktree list`. The scan cache keys in-flight scans on a `kind`, and graph and lenient were separate kinds, so a roots rebuild overlapping a sidebar refresh would spawn its own subprocess where the two previously coalesced. That is a real regression on macOS, Linux and native Windows, where `getLocalProjectWorktreeGitOptions` returns `{}` and both callers land on the identical key; on WSL they already differ by distro and never shared. So the annotated listing is now the graph listing plus annotation, rather than a parallel scan of its own: `listWorktrees` awaits `listWorktreeGraph` and annotates the rows it returns. Both soften a Git failure to `[]`, so they can share one listing; strict keeps its own because it must be able to reject. The two kinds ran Git twice before and now run it once, so the overlap case gets strictly faster instead of paying for the opt-out. An annotated scan holds two in-flight entries now (its own, plus the graph listing it shares). Keeping its own entry matters: `detectSparseCheckoutCached` dedupes revalidation but not the initial fill, so two concurrent badge readers sharing only the graph scan would both probe. Per-platform delta: - macOS/Linux: fewer probes on the three call sites; one `git worktree list` instead of two when a graph and an annotated scan overlap. - native Windows, no WSL: same, and the saved subprocess is the expensive half. - Windows + WSL: the largest win. The discarded probes were 9p round-trips re-paid cold after every worktree create/remove. - SSH/relay: none. `listRepoWorktreeGraph` returns through the same provider branch as `listRepoWorktrees` before reaching local Git. - folder workspaces: none. Both return the same synthetic folder worktree. Not in this change: - The badge listing itself. It still probes, still annotates, and still keys on the distro exactly as stablyai#17932 left it. - The remaining `listRepoWorktrees` callers. They read `isSparse`, or feed rows to something that does. Mirror-Of: a7db6c3
…d it (stablyai#18050) Three main-process call sites list a repo's worktrees to read `worktree.path` and nothing else, but went through the annotated listing, so each one paid a sparse-checkout probe per worktree and cached the result nobody consumed: - `registered-worktree-roots-cache.ts` rebuilds the filesystem-auth authorized roots. `invalidateAuthorizedRootsCache()` fires on every worktree create and remove, plus repo add/clone/settings changes, so this reruns constantly. - `filesystem-source-control-ai-targets.ts` checks whether a local repo owns a worktree path. - `hosted-review.ts` verifies a worktree belongs to the repo before granting access. The probe is an `fs.stat` of the per-worktree `info/sparse-checkout` plus, when that file is non-empty, a git config read. On a WSL-hosted repo both cross 9p. stablyai#17859 cached it and stablyai#17932 keyed that cache on the distro, which fixed a wrong answer but also meant the distro-less callers above populate a second entry per worktree — probed cold, revalidated on their own five-minute loop, and read by nobody. Worktree create/remove clears the sparse cache and dirties the roots cache together, so both variants go cold at once and the discarded half is re-probed in full on the next auth check. `listRepoWorktreeGraph` routes those callers to `listWorktreeGraph`, which already existed as the annotation-free listing (stablyai#17655). Doing only that would have cost a second `git worktree list`. The scan cache keys in-flight scans on a `kind`, and graph and lenient were separate kinds, so a roots rebuild overlapping a sidebar refresh would spawn its own subprocess where the two previously coalesced. That is a real regression on macOS, Linux and native Windows, where `getLocalProjectWorktreeGitOptions` returns `{}` and both callers land on the identical key; on WSL they already differ by distro and never shared. So the annotated listing is now the graph listing plus annotation, rather than a parallel scan of its own: `listWorktrees` awaits `listWorktreeGraph` and annotates the rows it returns. Both soften a Git failure to `[]`, so they can share one listing; strict keeps its own because it must be able to reject. The two kinds ran Git twice before and now run it once, so the overlap case gets strictly faster instead of paying for the opt-out. An annotated scan holds two in-flight entries now (its own, plus the graph listing it shares). Keeping its own entry matters: `detectSparseCheckoutCached` dedupes revalidation but not the initial fill, so two concurrent badge readers sharing only the graph scan would both probe. Per-platform delta: - macOS/Linux: fewer probes on the three call sites; one `git worktree list` instead of two when a graph and an annotated scan overlap. - native Windows, no WSL: same, and the saved subprocess is the expensive half. - Windows + WSL: the largest win. The discarded probes were 9p round-trips re-paid cold after every worktree create/remove. - SSH/relay: none. `listRepoWorktreeGraph` returns through the same provider branch as `listRepoWorktrees` before reaching local Git. - folder workspaces: none. Both return the same synthetic folder worktree. Not in this change: - The badge listing itself. It still probes, still annotates, and still keys on the distro exactly as stablyai#17932 left it. - The remaining `listRepoWorktrees` callers. They read `isSparse`, or feed rows to something that does.

ELI5
Every worktree row Orca lists carries a little "this checkout is sparse" flag. Working out that
flag means touching the disk: check whether a
sparse-checkoutpattern file exists, and if itdoes, read a git config to confirm the mode is actually on. Cheap on a local SSD. Not cheap on a
WSL repo, where every one of those touches crosses the 9p filesystem bridge.
Three places in Orca ask for the worktree list and then only ever look at
worktree.path. Theynever read the flag. But they were calling the listing that computes it, so they paid for that
disk work once per worktree and threw the answer away.
The worst of the three is the filesystem-authorization rebuild — the thing that decides which
folders Orca is allowed to open. It re-runs after every worktree create and remove. So the
loop was: create a worktree → the flag cache is dropped → the auth rebuild lists every worktree in
every repo and probes every one of them from cold → and discards all of it.
This PR gives those three callers a listing that just doesn't compute the flag.
The catch, and the reason this isn't a three-line change: Orca shares one
git worktree listbetween callers that ask at the same time, and it decides who can share with whom using a "kind"
tag. The probe-free listing and the flag-carrying listing were different kinds, so they couldn't
share — meaning "stop probing" would have quietly started a second
git worktree listwhenever the auth rebuild overlapped a sidebar refresh. On macOS, Linux and native Windows that
trade is a loss: you'd save a few cheap stats and pay for a whole extra Git process.
So instead of making them two separate scans, the flag-carrying listing is now built on top of
the probe-free one — it runs that, then adds the flag. One Git call feeds both, and only the
caller that wants the flag pays for it. Those two used to run Git twice when they overlapped, so
the overlap case comes out faster than before rather than paying a toll for the opt-out.
Analogy: a delivery van drops parcels at every house on the street, and for each house someone
also walks up the drive to check whether the porch light is on. Three of the people waiting only
ever wanted to know which houses exist — they never asked about porch lights. Before, ordering
"no porch-light check" would have sent out a second van. Now there's still one van; the porch-light
walk is just an optional extra for whoever actually asked.
What changed
listRepoWorktreeGraphroutes path-only callers tolistWorktreeGraph, which already existed asthe annotation-free listing (#17655). The three callers:
registered-worktree-roots-cache.tsresolve(worktree.path)invalidateAuthorizedRootsCache()fires on every worktree create/remove plus repo add/clone/settings changesfilesystem-source-control-ai-targets.tscomparableLocalPath(worktree.path)hosted-review.tsresolve(worktree.path)And the sharing fix that makes it free:
listWorktreesis nowlistWorktreeGraphplusannotation, rather than a parallel scan of its own. Both soften a Git failure to
[], so they canshare one listing. Strict keeps its own scan because it must be able to reject.
An annotated scan holds two in-flight entries now — its own, plus the graph listing it shares.
Keeping its own entry matters:
detectSparseCheckoutCacheddedupes revalidation but not theinitial fill, so two concurrent badge readers sharing only the graph scan would both probe.
Why the cost was doubled, not just wasted
#17859 cached the probe; #17932 keyed that cache on the WSL distro, which fixed a wrong answer but
also meant the distro-less callers above populate a second entry per worktree — probed cold,
revalidated on their own five-minute loop, read by nobody. Worktree create/remove clears the sparse
cache and dirties the roots cache together, so both variants go cold at once and the discarded half
gets re-probed in full on the next auth check.
#17932 deferred this as "a separate, larger change." It turned out smaller than expected, because
listWorktreeGraphalready existed — the work was in the sharing, not the listing.Per-platform delta
git worktree listinstead of twowhen a graph and an annotated scan overlap.
every worktree create/remove.
listRepoWorktreeGraphreturns through the same provider branch aslistRepoWorktreesbefore reaching local Git.Verification
Live on Windows 11 + WSL (Ubuntu-24.04, distro Git 2.43.0), against the layout #17932 fixed —
repo inside the distro at
/home/neil/wsl-sparse-repro/repo, worktrees on the Windows drive, sothe
.gitgitfile points at a guest path with no drive letter to derive. Distro Git emits nosparseporcelain line, so the fallback probe is genuinely the path under test.listWorktreesStrictC:\wt\sparse-x:true— unchangedlistWorktrees(now layered)C:\wt\sparse-x:true— unchangedlistWorktreeGraphrowsisSparseundefinedThat last pair is the win, measured: one probe per worktree per rebuild, gone.
Test suites
src/main/: 2948 files / 30012 passed. One unrelated flake(
ssh-remote-commands.test.ts, zero worktree references, passes in isolation).src/main/git/+ the touched IPC consumers: 11 files / 30 tests fail — identical tothe
origin/mainbaseline on the same machine (EPERM: operation not permitted, symlink,needs Developer Mode). Branch adds 7 passing tests there.
pnpm tcclean;check:code-quality:changed0 new findings.Tests added
worktree-scan-cache-annotation-reuse.test.ts— graph scan runs no probe; annotated scan stilldoes; an overlapping pair reads the Git listing once; the graph caller resolves while the
annotated one is still probing (the opt-out must not become a wait).
worktree-scan-cache-sharing.test.ts— the two former "graph and annotated run Git twice" casesnow assert one call, in both orders. In-flight count assertions updated for the nested entry.
repo-worktrees.test.ts—listRepoWorktreeGraphreaches the graph listing and never theannotated one; folder repos still return the synthetic worktree.
Not in this change
fix(wsl): resolve sparse-checkout and diff-stamp gitdirs through the caller's distro #17932 left it.
listRepoWorktreescallers — they readisSparse, or feed rows to something thatdoes.