Repository navigation
Description
Summary
bb thread spawn --new-environment worktree --base-branch main creates the worktree from the local main ref, without fetching first. If the project checkout is behind its remote — which long-lived checkouts routinely are — every spawned thread starts on an old commit, and nothing says so.
--base-branch reads like it names a branch to base on, and the branch a user means is almost always the remote one.
Reproduced deliberately on bb 0.38.0, macOS 26.
Reproduction
$ git -C <checkout> rev-parse main 583ce1f7daf329e388e34c6f8f77b039c4ab177c
$ git -C <checkout> rev-parse origin/main c319d1a245ab4eb5f6297cdf020533349a0029c2 # 3 ahead
$ bb thread spawn --project <p> --new-environment worktree --base-branch main …
$ git -C ~/.bb/worktrees/<env>/<repo> rev-parse HEAD
583ce1f7daf329e388e34c6f8f77b039c4ab177c # local main, not origin/main
No fetch was performed and no warning printed.
How stale checkouts actually get
Measured across the 12 project checkouts on one machine, same moment:
| repo | commits behind origin/main |
|---|---|
| browser-cluster | 89 |
| ocr-service | 57 |
| motion | 65 |
| flare-client-dashboard | 53 |
| motion-client-dashboard-ops | 37 |
| luca-ai | 10 |
| flare-clients | 3 |
| 5 others | 0 |
7 of 12 were behind. A thread spawned into any of them starts that far back.
Why this is worse than starting on an old commit
The failure produces a green result on the wrong denominator.
A worker was spawned to port 7 test files and prove the total test count rose. It landed on the stale main (65 commits back). Two of those files are shorter on that commit — collect-subpage-ids has 5 it blocks there against 9 on current main; email-grammar-check 18 against 20. Had it worked from where bb placed it:
- it would have ported the older, shorter files,
- the test count would still have risen, satisfying the acceptance measure,
- every per-file target would have been met,
- and 6 assertions would have quietly left the repo with every signal green.
It was caught only because the brief happened to say "branch off origin/main, re-fetched" — boilerplate that turned out to be load-bearing.
Suggested fixes
- Fetch before creating a managed worktree. This is the fix that removes the class.
- Resolve
--base-branch <name>to the remote-tracking ref when a remote exists, or acceptorigin/mainexplicitly and document which one it uses. - At minimum, print the resolved base commit and whether it matched the remote, so a caller can see they were placed behind.
Workaround
Every spawn brief now asserts its own base before taking any measurement:
git fetch origin && [ "$(git rev-parse HEAD)" = "$(git rev-parse origin/main)" ]Cheap and mechanical, but it has to be repeated in every brief by hand, and forgetting it is invisible until something has already been measured against the wrong tree.
Activity
SawyerHood commentedon Aug 18, 2026
Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1770.html
git worktree add … mainresolves the unfetched local refs/heads/main.The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at
16ceb3a54, and repro artifacts. It was independently re-run by a second agent (see its Verification section).Resolve a named default base branch against origin before spawning
Resolve a named default base branch against origin when spawning (get…
Resolve local-vs-origin branch refs with one shared resolver (#7719)