Skip to content

Preserve new checkout branch comparison bases - #5856

Merged
SawyerHood merged 2 commits into
mainfrom
slopcop/issue-5850
Oct 20, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
slopcop/issue-5850

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · new-issue-autopilot

Human comments

What was wrong

When the project-checkout provider created a new branch, it did not tell core which ref the branch was based on. Core then recorded no merge base and compared the thread against the default branch, so commits inherited from the base showed up as the thread's own changes (#5850).

The first commit made the provider report the base. That only worked for the first environment created at a checkout path. Project-checkout environments are never retired. Every later thread at the same path reuses that environment row, and core skipped merge-base writes on reused rows owned by the same provider (environment-engine.ts, the adoptedExistingEnvironment && existingProviderOwnsLifecycle guard). This had two effects:

  • A checkout that already had an environment (the usual case) still recorded no base.
  • A checkout whose first thread branched from topic-base kept topic-base for every later thread. A later thread branched from main then showed commits main gained after topic-base as its own changes. On main today, that later diff is correct. The first commit alone caused this regression.

Reproduction and root-cause report for the original bug: https://get-bb.github.io/reports/issues/5850.html

What changed

  • Provider result contract (Plugin SDK, experimental environment providers): PluginEnvironmentProviderCreateResult.mergeBaseBranch now accepts null. A string records the base, null clears it, and omitting the field keeps it. This only matters when core reuses an environment row the provider already owns at that path. The result schema accepts null. Plugin SDK patch bumped to 0.6.60, because the published declaration types change.
  • Core (apps/server/src/services/environments/environment-engine.ts): on a reused row owned by the same provider, a reported mergeBaseBranch (string or null) is now applied, and an omitted one leaves the row unchanged. New rows behave as before.
  • Project-checkout plugin (server.ts):
    • A new branch reports its base ref.
    • Switching to an existing branch reports null, so the diff falls back to the default branch. Core did the same before Environment providers: plugins own where threads run #3227.
    • Attaching without a branch switch omits the field, so the current base is kept.
    • Restoring a removed environment re-reports that environment's recorded merge base. Previously the restore dropped it.
  • Docs: the plugin README and the plugin-authoring backend reference describe the three cases.
  • No host/daemon wire change, migration, or CLI change.

How you verified

  • Regression tests: each one fails on the previous head of this PR and passes after the fix.
    • apps/server/test/threads/environment-providers.test.ts, "on a reused host row it …": three cases (reported, null, omitted).
      • Before the fix, the reported case fails with expected 'origin/old' to be 'origin/dev'.
      • The null case fails because the old schema rejects null.
      • The omitted case passes on both versions, as a control.
    • plugins/environment-project-checkout/server.test.ts:
      • "checkout provider merge base": existing branch reports null; attach-only omits the field.
      • The restore test asserts that the recorded base is re-reported.
    • The original real-git test server-merge-base.test.ts is kept. It fails on main and passes here.
  • End-to-end check (temporary probe in the tests/integration harness: real server, host daemon and plugin, fake agent; not committed). It reads the diff through GET /environments/:id/diff:
    • A checkout that already had an environment, then a thread on a new branch from topic-base: before, the merge base was null and the diff included base-only.txt. After, the merge base is topic-base and the diff is empty.
    • A thread from topic-base, then a later thread from main after main gained main-only.txt: with this PR's first commit alone, the merge base stays topic-base and the diff shows A main-only.txt. After the fix, the merge base is main and the diff is empty.
  • Commands:
    • pnpm exec turbo run test --filter=bb-plugin-environment-project-checkout: 45 passed.
    • pnpm exec turbo run test --filter=@bb/server -- test/threads/environment-providers.test.ts: 68 passed.
    • pnpm exec turbo run typecheck lint --filter='...[origin/main]' --continue: 139 of 139 tasks passed.
    • node .github/workflows/check-plugin-sdk-version.mjs and node packages/plugin-sdk/scripts/check-npm-version-guard.mjs: both pass.

Fixes #5850

AGENT GENERATED

🤖 Generated with Claude Code

@alexandre-vl

Copy link
Copy Markdown
Contributor

This fixes #5850 as reported. Two things it leaves:

  1. It records the base as the inputs name it. That holds today, because a base git cannot resolve fails the create (Project checkout on a fresh clone fails for any branch but the default: "fatal: invalid reference: dev" #5851). Fixing Project checkout on a fresh clone fails for any branch but the default: "fatal: invalid reference: dev" #5851 on the host, the side that knows the clone's refs, starts the branch from origin/dev, while this still records dev. That hides the thread's commits, with no error. For a thread that committed thread.txt, in the same environment:

    ?mergeBaseBranch=dev         → "files":""                 "baseRef":null  "aheadCount":0
    ?mergeBaseBranch=origin/dev  → "files":"A\tthread.txt\n"  "aheadCount":1
    
  2. Restore still records no merge base. Restore attaches the thread's branch as an existing one (server.ts#L284-L287), and the engine stores what it reports, or null (environment-engine.ts#L510). A project checkout reaches restore once its ephemeral machine is removed (provider-orchestration.ts#L1218-L1220).

#5853 has the checkout host report the ref it made the branch from, as the worktree host reports its base, and has restore re-report the recorded merge base. #5855, stacked on it, fixes #5851. The PR gate closed both pending contributor approval.

AGENT GENERATED

Project-checkout environments are never retired, so later threads at the
same path reuse the first environment row, and core skipped merge-base
writes on reused rows its provider already owned. A checkout that already
had an environment never recorded a new branch's base, and one whose first
thread branched from another ref kept that base for every later thread,
listing the default branch's newer commits as the later thread's changes.

Provider create results may now report mergeBaseBranch as null to clear
it; omitting it keeps the recorded value. Core applies a reported value to
reused rows. The checkout provider reports the base for a new branch, null
for an existing branch, nothing for a plain attach, and the recorded base
on restore. Plugin SDK 0.6.60.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@SawyerHood
SawyerHood merged commit 9fc7153 into main Oct 20, 2026
48 checks passed
@SawyerHood
SawyerHood deleted the slopcop/issue-5850 branch October 20, 2026 17:41
@alexandre-vl

Copy link
Copy Markdown
Contributor

8b5d5da covers both gaps, and the reuse case #5853 missed too: in the harness, a second thread on the same checkout keeps origin/dev with #5853 and gets origin/release here. #5853 is superseded. I'll rebuild #5855 (#5851) on top of this, with the host reporting the ref it resolved.

AGENT GENERATED

ymichael pushed a commit that referenced this pull request Oct 20, 2026
… the clone lacks them (#5855)

## Human comments

Thanks @ymichael for rebuilding this on `main`.

## What was wrong

A project bb clones onto a machine holds only the remote's default
branch, and the picker lists origin's branches there without `origin/`.
The host passed the bare name to git. On `main` at 81b48d3, after #5856,
a new branch from `dev` fails with `fatal: invalid reference: dev`, and
an existing `release` with `Cannot checkout missing branch release`.

## What changed

- The host looks a branch up locally, then as `origin/<name>`
(`locateBranch`, on the shared `hasRef`).
- An existing branch that only origin holds is switched to with `git
switch --track origin/<name>`, so the switch does not depend on
`checkout.guess`.
- A new branch starts from `origin/<base>` when no local branch has it.
The host reports that ref, and the provider records it as the merge base
in place of the requested name. `dev` does not resolve in that clone, so
a recorded `dev` would leave the thread's diff empty. #5856's other
cases are unchanged.
- A new branch tracks nothing, as the worktree host's `worktree add
--no-track -B` makes one. Otherwise a branch made from `origin/dev`
would take it as its upstream.

## How you verified

At ebe71b6:

- `project-checkout-branches.test.ts` runs in a plain clone. A new
branch from `dev` records `origin/dev`, and `release` ends up tracking
`origin/release`. Both fail on `main` with the errors above.
- #5885's test, run here, has the thread commit in that clone: its diff
reads `A\tthread.txt`.
- These pass:
  - the plugin's tests (46)
- the smoke, multi-thread and environments integration suites, with
#5885's two tests added (43)
- #5885 makes the same fix and lists which test fails when each part is
reverted alone.

Fixes #5851

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Project checkout records no merge base for a new branch, so its diff is read against the default branch

2 participants