Skip to content

perf(git): skip the sparse probe for worktree listings that never read it - #18050

Merged
nwparker merged 1 commit into
mainfrom
nwparker/WSL-parse-follow
Sep 2, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/WSL-parse-follow

Conversation

@nwparker

@nwparker nwparker commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​197 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​164
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53 $\color{#cf222e}{\Huge{\mathbf{−}}}$​13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​40

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-checkout pattern file exists, and if it
does, 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. They
never 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 list
between 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 list
whenever 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

listRepoWorktreeGraph routes path-only callers to listWorktreeGraph, which already existed as
the annotation-free listing (#17655). The three callers:

Call site What it reads Why it runs
registered-worktree-roots-cache.ts resolve(worktree.path) filesystem-auth authorized roots; invalidateAuthorizedRootsCache() fires on every worktree create/remove plus repo add/clone/settings changes
filesystem-source-control-ai-targets.ts comparableLocalPath(worktree.path) does this local repo own this worktree path
hosted-review.ts resolve(worktree.path) worktree-belongs-to-repo check before granting access

And the sharing fix that makes it free: listWorktrees is now listWorktreeGraph plus
annotation, rather than a parallel scan of its own. Both soften a Git failure to [], so they can
share 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: detectSparseCheckoutCached dedupes revalidation but not the
initial 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
listWorktreeGraph already existed — the work was in the sharing, not the listing.

Per-platform delta

  • macOS / Linux — fewer probes at 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.

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, so
the .git gitfile points at a guest path with no drive letter to derive. Distro Git emits no
sparse porcelain line, so the fallback probe is genuinely the path under test.

Check Result
sparse badge via listWorktreesStrict C:\wt\sparse-x:true — unchanged
sparse badge via listWorktrees (now layered) C:\wt\sparse-x:true — unchanged
listWorktreeGraph rows same 3 rows, every isSparse undefined
sparse-cache entries after a roots-rebuild-style read 0
sparse-cache entries after a badge read 3 (one per worktree)

That last pair is the win, measured: one probe per worktree per rebuild, gone.

Test suites

  • macOS full src/main/: 2948 files / 30012 passed. One unrelated flake
    (ssh-remote-commands.test.ts, zero worktree references, passes in isolation).
  • Windows src/main/git/ + the touched IPC consumers: 11 files / 30 tests fail — identical to
    the origin/main baseline on the same machine
    (EPERM: operation not permitted, symlink,
    needs Developer Mode). Branch adds 7 passing tests there.
  • pnpm tc clean; check:code-quality:changed 0 new findings.

Tests added

  • worktree-scan-cache-annotation-reuse.test.ts — graph scan runs no probe; annotated scan still
    does; 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" cases
    now assert one call, in both orders. In-flight count assertions updated for the nested entry.
  • repo-worktrees.test.ts — listRepoWorktreeGraph reaches the graph listing and never the
    annotated one; folder repos still return the synthetic worktree.

Not in this change

…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.
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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: Team

Run ID: 80b3bd41-17de-4985-81f9-af715ebebb57

📥 Commits

Reviewing files that changed from the base of the PR and between fd33f9b and b53c1c2.

📒 Files selected for processing (13)
  • src/main/git/worktree-listing.ts
  • src/main/git/worktree-scan-cache-annotation-reuse.test.ts
  • src/main/git/worktree-scan-cache-sharing.test.ts
  • src/main/git/worktree-scan-cache.ts
  • src/main/ipc/created-worktree-root-prune.test.ts
  • src/main/ipc/filesystem-auth.test.ts
  • src/main/ipc/filesystem-test-harness.ts
  • src/main/ipc/filesystem/filesystem-source-control-ai-targets.ts
  • src/main/ipc/hosted-review.test.ts
  • src/main/ipc/hosted-review.ts
  • src/main/ipc/registered-worktree-roots-cache.ts
  • src/main/repo-worktrees.test.ts
  • src/main/repo-worktrees.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The change adds graph-only worktree listing through listRepoWorktreeGraph and listWorktreeGraph. The scan cache now shares graph listings between graph-only and annotated scans, while annotated scans still apply sparse-checkout status. IPC callers and test mocks now use the graph-only APIs. Tests cover delegation, scan coalescing, probe behavior, pending probes, and cache accounting.

Merge Risk: ⚪ Minimal · up to b53c1

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 seve… 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 …
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main performance change: skipping unnecessary sparse-checkout probes during worktree listings.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Route path-only callers to the probe-free listing — listRepoWorktreeGraph in repo-worktrees.ts mirrors listRepoWorktrees but calls listWorktreeGraph, and the three callers that only read worktree.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 — runAnnotatedWorktreeScan in worktree-scan-cache.ts makes listWorktrees build on listWorktreeGraph instead of running its own git 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.ts and repo-worktrees.test.ts update 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).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit a7db6c3 into main Sep 2, 2026
29 checks passed
@nwparker
nwparker deleted the nwparker/WSL-parse-follow branch September 2, 2026 03:19
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Sep 3, 2026
…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
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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.

1 participant