Repository navigation
Cache branch picker ref listings, fetch only origin when a picker opens, and keep results while searching - #7074
Merged
ymichael merged 3 commits intoNov 5, 2026
Conversation
… opens The Git plugin's branches RPC listed every local and remote ref on each debounced keystroke and started `git fetch --all --prune` on every call. The Diff tab keeps that query live, so every ref change refetched it, and the fetch's own ref writes kept the loop going. - Core's branch listing caches the parsed refs per git common dir, keyed by a stat fingerprint of packed-refs and the refs/heads and refs/remotes directories. Refs written within the last 2 seconds, and reftable repos, skip the cache. - The plugin's branches read no longer fetches. A new fetchRemoteBranches RPC starts the throttled background fetch; the branch pickers call it when they open, and `bb git branches` still calls it before listing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oads Each search in the Git plugin's branch pickers is a new query keyed by the typed text, so the list emptied on every keystroke and the picker showed its loading skeleton until the response arrived. useGitBranches now returns the last loaded branches for the same environment and selected branch until the new search answers; the picker filters them as you type. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The background and blocking branch refresh ran `git fetch --all --prune`. It walks remotes in config order, and the 5 s background kill stops it at the first slow or unreachable remote, so remotes listed after it (often origin) never refreshed. fetchRemoteBranches now fetches origin, falls back to the single remote when there is no origin, and skips repositories with several remotes and none named origin. The Git plugin's pickers, core's project branch picker and thread placement all share this path. The 30 s throttle per common dir is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/branch-picker-re-reads-all-refs-and-fetches-per-thr_fbmhvzsajp
branch
November 5, 2026 17:50
ymichael
added a commit
that referenced
this pull request
Nov 5, 2026
…hRemoteBranches (#7132) ## What was wrong Main is red at 87a6e85. #7074 (b9ea287) and #7100 (87a6e85) merged minutes apart, and each passed CI on its own base: - #7074 added `getGitCommonDir` calls to `packages/environment-provider-host/src/branch-options.ts`. It also added the Git plugin's `fetchRemoteBranches` RPC, which calls `refreshRemoteBranches(path, …)`. - #7100 removed the `getGitCommonDir` import from `branch-options.ts` and changed `refreshRemoteBranches` to take a `GitRepo` instead of a path. On main this gives: - `Lint and typecheck`: `src/branch-options.ts(191,27): error TS2304: Cannot find name 'getGitCommonDir'`. - `ReferenceError: getGitCommonDir is not defined` in `packages-other`, `packages-host`, `plugins-2` and `integration` (Linux and Windows). Once the import is back, the Git plugin's `fetches remote branches when asked, never on a branch read` test still fails. The plugin passes a path string where `refreshRemoteBranches` now reads `repo.commonDir`, so no fetch ever starts. Opening a merge-base picker would not fetch remotes. ## Change - `branch-options.ts`: import `getGitCommonDir` again. - `plugins/git/host.ts`: `fetchRemoteBranches` resolves the repo with `readGitRepo` and skips non-repos, the same way the daemon's `host.inspect_git_source` caller does after #7100. It then calls `refreshRemoteBranches(repo, …)`. ## Verification Against origin/main 87a6e85 plus this change: - `turbo run typecheck` for `bb-environment-provider-host`, `bb-plugin-bb--git` and `@bb/host-daemon` passes. - `bb-environment-provider-host` tests: 48/48 pass, including `branch-options-cache.test.ts`, which failed on main. - `bb-plugin-bb--git` tests: 278/278 pass. `host.test.ts > fetches remote branches when asked` fails on main and fails with the import fix alone. It passes with this change, and also passed at b9ea287. - `@bb/host-daemon` `test/command/host-branches-dispatch.test.ts`: 21/21 pass. Several failed on main. - `tests/integration` `fake/smoke/environment-actions.test.ts`: 5/5 pass. It failed on main. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Finding #3 of the Nov 4 hot-path audit. The Git plugin's
branchesRPC (plugins/git/host.ts) calledlistBranchOptionswithremoteRefresh: "background". So every call listed all ofrefs/headsandrefs/remotes, in twofor-each-refprocesses using%(refname:short). It also started a throttledgit fetch --all --prune. Calls come on every debounced keystroke in a merge-base picker, and on every ref change while a Diff tab is visible: the Diff tab keeps the query live withloadOptions: isLive. A fetch that moves a ref invalidates the refs tag, which refetchesbranches, which starts the next fetch once the 30 s throttle lapses. The caller only needs about 50 names that match a query. This still held on origin/main at f3ccc8b.What changed
packages/environment-provider-host/src/branch-options.ts: the parsed ref listing is cached per git common dir, so all worktrees of a repo share one entry (LRU of 8). The cache key is a stat fingerprint: inode and mtime ofpacked-refs, plus every directory underrefs/headsandrefs/remotes. Git writes refs by lock-and-rename, so any ref add, update or delete changes one of those. Fingerprints with a timestamp less than 2 s old are treated as racy and skip the cache, like git's racy-index rule. Reftable repos always skip it. Searches filter the cached list in memory. Core'shost.list_branch_optionsuses the same function, so the project picker gets the cache too.brancheshost read now usesremoteRefresh: "none". A newfetchRemoteBranchesRPC (UI → server → host) starts the existing throttled background fetch (refreshRemoteBranches). The merge-base pickers call it when they open.bb git branchescalls it before listing (best effort), so the CLI behaves as before. Skill and README updated.fetchRemoteBranches(branch-options.ts) now runsgit fetch --prune --quiet <remote>fororigin, or for the only remote when there is noorigin. If a repo has several remotes and none is namedorigin, it fetches nothing. This is the one fetch path behind the Git plugin's pickers, core's project branch picker (host.inspect_git_sourceandhost.list_branch_options, both the background refresh and the blocking Refresh) and thread placement, so the change applies to all of them. The 30 s throttle per git common dir is unchanged.bb git branches, and by core's existing paths.origin(or the single remote) no longer refresh from the pickers, including core's project picker and its Refresh. Rungit fetch <remote>to update them.HOST_DAEMON_PROTOCOL_VERSIONbump and no plugin SDK change. The only new wire surface is the Git plugin's own RPC method. If an older plugin host lacks it, the UI ignores the error and the CLI still lists.plugins/git/ui/queries.ts:useGitBrancheskeeps the last loaded results, for the same environment and selected branch, until the next search answers. Each search is a new query keyed by the typed text, so the list used to go empty on every keystroke and show "Loading branches…". With searches now taking 50–100 ms, that showed as a flicker. The picker already filters as you type, so the old results narrow immediately and are then replaced.How you verified
Real data:
~/Projects/bb(4,476 local branches, 2,672 remote refs, 123 worktrees, 17 remotes). Load average was 15–45 from other agents, so main and branch runs were interleaved. The harness imports the reallistBranchOptionsfrom agit archivecopy of origin/main and from this branch. A PATH shim counts git spawns and turnsgit fetchinto a no-op. Scripts and raw output are outside the checkout.Search keystrokes (10 queries after the first call, per process, 4 interleaved rounds each):
for-each-refover 7.1k refs,symbolic-ref, 2×rev-parse)rev-parse×2)Fetch cost on this repo while it still had 18 remotes (17 of them contributor forks, since removed):
git fetch --all --prune --dry-runtook 147 s wall (13.8 s user, 38 s sys).git fetch origin --prune --dry-runtook 7.5 s. The background fetch is killed at 5 s, so on main a visible Diff tab could restart a mostly wasted 5 sfetch --allevery 30 s whenever refs moved. On the branch,branchesreads start no fetches (see the test below). A 10-minutepssample of the live machine saw one daemon-sidefetch --all. No Diff-tab loop was running then, so I have no live before/after for the loop; the audit's 87 slow calls and the reflog alignment are the evidence for it.for-each-refformat cost, same repo, 5 runs each:%(refname:short)382–624 ms,%(refname:lstrip=2)190–277 ms,%(refname)210–252 ms. The format is unchanged here; this is context for why the listing is slow.What
fetch --alldoes when the 5 s background kill hits it. I tested a fixture repo with local bare remotes. Remotenewbranches were added andstalebranches deleted on each remote after the first fetch. "Slow" remotes sleep 8 s inuploadpack. The "blackhole" remote isssh://[email protected], which never answers. I calledrefreshRemoteBranches(repo, {}, "background"):fetch --all --prunestalekept,newmissing)fetch --allfetches remotes one at a time in config order. When killed, every remote before the first slow one is fully updated and pruned. The slow one and every remote after it keep their old refs. There are no partial updates and no leftover.lockfiles, because the kill takes the whole process group. Every failed background attempt also marks the repo for a retry, so the next refresh within 30 s runs again. So with one slow or unreachable remote listed beforeorigin, the 5 s kill meantoriginnever refreshed.Tests (each fails before the fix and passes after; checked by reverting):
packages/environment-provider-host/test/branch-options-cache.test.tsages the ref store and then:In each case the next listing must reflect the change. A spawn-count test checks that a repeat search runs no
for-each-ref. With a constant fingerprint, the four freshness tests fail.plugins/git/host.test.ts:branchesreads never reach the remote's upload-pack, andfetchRemoteBranchesdoes. This fails whenbranchesgoes back toremoteRefresh: "background".packages/environment-provider-host/test/workspace-git-fetch.test.ts, both interactive and background:alpha,originandzeta, onlyoriginis fetched and prunedoriginare skippedOn the old
fetch --allcode, the multi-remote and skip cases fail.plugins/git/server/cli.test.tsupdated for the CLI's fetch call.plugins/git/ui/queries.test.tsx: while the next search is in flight, the previous branches stay rendered. Fails without the fix.Real app (
pnpm start:worktree, fixture repo with 4,400 local and 2,500 remote branches): a headless browser typed in the composer's merge-base picker while arequestAnimationFrameprobe counted frames showing "Loading branches". On main: 133/310 and 119/310. With the skeleton fix: 0/311 and 0/311. In the same app, opening the picker fetched a branch added to the bare origin, and it showed up in search about 2 s after opening. With the Diff tab open, three local ref changes over 26 s fetched nothing.pnpm exec turbo run typecheck --filter=bb-plugin-bb--git --filter=bb-environment-provider-host --filter=@bb/host-daemonpnpm exec turbo run typecheck lint test --filter=bb-plugin-bb--git(35 files) andpnpm exec turbo run test --filter=bb-environment-provider-host(5 files)pnpm exec turbo run test --filter=@bb/host-daemon -- test/command/host-branches-dispatch.test.ts,--filter=@bb/server -- test/public/public-project-workspace-routing.test.tsand--filter=bb-plugin-bb-guidelint clean on changed files. CI runs the full suites.
🤖 Generated with Claude Code