Repository navigation
Conversation
When a provider answers attach with a path an existing ready environment already holds, core adopts that row and refreshes its branch before the first turn. The refresh used host.inspect_git_source with a background remote refresh: a full status -uall, default-branch ref reads, and fetch --all --prune. It only needs the current branch, so it now uses host.inspect_git_checkout and leaves defaultBranch to provisioning and the workspace watch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/follow-up-6-cheap-branch-refresh-for-reused-chec-thr_442866cf7g
branch
November 5, 2026 17:36
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
Sometimes an environment provider answers attach with a path that an existing ready environment already holds. This happens for threads in the project's own checkout, or for a worktree thread pointed at an existing worktree. Core then adopts that row (
bindEnvironmentPath) and callsrefreshAttachedEnvironmentBranchbefore the first turn. That function usedhost.inspect_git_sourcewithremoteRefresh: "background". The daemon then ran:git status --porcelain=v1 --untracked-files=allsymbolic-ref origin/HEAD,for-each-ref,show-ref,rev-parse×2)git fetch --all --pruneThe refresh only needs the branch currently checked out. Finding #6 in the Nov 4 hot-path audit.
What changed
apps/server/src/services/threads/thread-environment-placement.ts:refreshAttachedEnvironmentBranchnow callshost.inspect_git_checkout(repo check,symbolic-ref HEAD,rev-parse HEAD) and records onlybranchName. No fetch.packages/db/src/data/environments.ts:recordEnvironmentCurrentBranchno longer acceptsdefaultBranch, because its only caller no longer passes it.host.inspect_git_checkoutalready exists, soHOST_DAEMON_PROTOCOL_VERSIONis unchanged.Left out, and why:
defaultBranchon reuse. The row keeps the value set at provisioning. The daemon workspace watch reportsdefaultBranchchanges while the environment is watched, and the git plugin reads the default branch live (workspaceDefaultBranchbefore the row value). Re-reading it here would need the extra ref reads or a new daemon field. The old code also wrote the current branch intodefaultBranchwhen no default could be found.git statusruns. The branch build still shows two copies of the checkout read (2 ×symbolic-ref+rev-parse). The fix for that is in the advancement scheduling and is out of scope here. At about 8 ms per process it is now cheap.How you verified
Measured on the real
~/Projects/bb(4,489 local branches, 1 remote). Two source servers, origin/mainfa30b0a7dcand this branch, each on a fresh data dir and run at the same time.GIT_TRACE2_EVENTrecorded every git process. Each sample creates a thread withenvironment: {type: "provider", environmentProviderId: "project-checkout"}(what the composer sends) against an existing ready project-checkout row. Wall time runs from the thread'screated_atto itsturn/startedevent. There were 10 interleaved pairs, with a 16 s gap so main's background fetch finished before the next sample.git status -uallbefore the first turnfetch --all --prunestartedWhen the fetch ran on main, it took about 3.3 s in the background, plus a
rev-list --objects --allchild (~1 s) andmaintenance run --auto. Load average during the series fell from 31 to 4. The branch outliers (338 ms, 584 ms) came at the highest load.Branch correctness, live on the branch server: in a scratch repo project I created thread 1, ran
git switch -c feature/live-check, then created thread 2. The reused row changed tobranch_name = feature/live-checkanddefault_branchstayedmain.Tests:
apps/servertest/threads/environment-providers.test.ts: the reused-row refresh test now asserts that exactly onehost.inspect_git_checkoutruns, that nohost.inspect_git_sourceruns, and thatdefaultBranchis preserved. This fails on main. The ordering test and the merge-base reuse tests now observe the checkout read.apps/servertest/threads/,test/environments/,test/public/public-threads.project-default.test.ts,test/public/public-project-workspace-routing.test.ts: 678 passed.packages/dbtest/data/environments.test.ts: 16 passed.pnpm exec turbo run typecheck --filter=@bb/server --filter=@bb/db: passed.🤖 Generated with Claude Code