Skip to content

--base-branch resolves against the stale local ref, so spawned worktrees silently start behind #1770

Closed

Description

@MGrin

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

  1. Fetch before creating a managed worktree. This is the fix that removes the class.
  2. Resolve --base-branch <name> to the remote-tracking ref when a remote exists, or accept origin/main explicitly and document which one it uses.
  3. 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

  1. added theissue type on Aug 18, 2026
  2. added
    workspaces
    cli
    on Aug 18, 2026
  3. SawyerHood commented on Aug 18, 2026

    @SawyerHood
    Collaborator

    Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1770.html

    • Verdict: REPRODUCED · root-cause confidence: high
    • Root cause (short): A plain --base-branch name is passed verbatim to the daemon, where createWorktree only fetches remote-qualified names (resolveRemoteBaseBranch returns null for names without a remote prefix) and the server's smart origin-vs-local resolution runs only for the {kind:"default"} spec, so git worktree add … main resolves the unfetched local refs/heads/main.
    • Proposed fix: Server-side: stop returning early for named specs in resolveManagedDefaultBaseBranchForCreate (apps/server/src/services/threads/thread-create.ts) and, when the named branch is the checkout's default branch, apply resolveDefaultWorktreeBaseBranch after host.list_branches (which already fetches) so equal/local-behind resolves to origin/ while ahead/diverged keeps local; optionally extend host.list_branches to report the relation for an arbitrary selectedBranch (protocol bump). Alternatively/additionally in the daemon (packages/host-workspace/src/provisioning.ts createWorktree): for a plain…
    • Caveats: Worktree was handed to me at a108fa7 (origin/main); I checked out 16ceb3a detached before the live repro, and none of the intervening commits touch the relevant files. Bug is not visual; screenshots show the app's provisioning transcript for evidence only. Reporter's fleet numbers (7/12 checkouts behind, 65-commit anecdote) are unverifiable. Each live spawn used one tiny codex turn.

    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).

    AGENT GENERATED: by Claude Opus 5

  4. added
    confirmed-repro
    on Aug 18, 2026
  5. self-assigned this
    on Aug 21, 2026
  6. added a commit that references this issue on Aug 21, 2026
    94d0324
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cliconfirmed-reproworkspaces

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions