#5850 · Preserve the selected checkout comparison base
2026-10-20 · trusted main commit e0f6fda5a02332bd4eb44183542a57f34f3263d7
Verdict: REPRODUCED · Root-cause confidence: high · reproduction label: confirmed-repro
1. TL;DR
A new project-checkout branch can inherit commits from a base other than the repository default. Git creates that branch correctly, but the server plugin does not report the chosen base in its environment result. Core persists an absent merge base and its normal fallback then compares against the default branch. The result includes changes inherited from the selected base even when the thread has changed nothing. Two clean checkouts reproduce the defect using the real plugin server and host entry plus real Git operations; a three-line server-only correction makes the regression pass.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Creating a branch from a non-default ref causes inherited changes to appear in its diff. | Verified | Both clean runs return base-only.txt\n instead of an empty diff. |
| The provider drops merge-base metadata. | Verified | Real provider result has no mergeBaseBranch; the successful new-branch host operation has run. |
| Core consequently uses the default branch. | Verified in source; fallback exercised in regression | Engine stores null for an absent result; domain resolver falls back to baseBranch/defaultBranch. |
| The same symptom occurs in the released binary, app, and CLI. | Not separately exercised | This investigation runs source at trusted main; it does not access a live user instance or launch an agent. |
| A historical refactor introduced the regression. | Unverified | Attribution is not needed to establish the current defect; no historical change is asserted here. |
3. Environment
- Source: public get-bb/bb, trusted origin/main at
e0f6fda5a02332bd4eb44183542a57f34f3263d7, fetched again before the fix with no newer main commit. - Linux 4.19.0-gvisor; Node v22.19.0; Git 2.39.5; pnpm 9.15.0; Vitest 4.1.1.
- Separate temporary base and verification clones; each uses a frozen install and Turbo build. Scratch repositories and host-data directories are created per test and removed in finally blocks.
- No HTTP server, ports, real database, enrolled machine, or agent provider is needed. The fake transport connects the actual plugin server entry to the actual host-entry harness, which executes Git.
4. Minimal reproduction
Use a disposable clone. These commands fetch the independently authored report artifact, not any issue-supplied script or linked PR code. The final command is expected to exit 1 on the recorded commit.
git clone https://github.com/get-bb/bb.git bb-5850 cd bb-5850 git checkout --detach e0f6fda5a02332bd4eb44183542a57f34f3263d7 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build curl -fsSL https://get-bb.github.io/reports/issues/5850/repro/server-merge-base.test.ts -o plugins/environment-project-checkout/server-merge-base.test.ts pnpm exec turbo run test --filter=bb-plugin-environment-project-checkout -- server-merge-base.test.ts
- The test initializes main, creates a non-default base containing one file, and assigns that commit a remote-tracking ref.
- It invokes the real registered provider to create a fresh branch from that ref, with calls routed through the real host entry.
- It confirms Git created the requested branch and that comparing it against main includes the inherited file.
- It compares using the provider result with core's documented default fallback, expecting no changes. The unchanged code fails here.
Expected: empty diff Actual: base-only.txt\n AssertionError: expected 'base-only.txt\n' to be '' // Object.is equality
Download regression test · First run log · Second clean run log
Complete reproduction test
import { execFile } from "node:child_process";
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { promisify } from "node:util";
import {
createFakePluginHost,
makeHostResponse,
makeThreadResponse,
} from "@get-bb/plugin-sdk/testing";
import { experimental_createHostEntryHarness } from "@get-bb/plugin-sdk/testing/host";
import { expect, it } from "vitest";
import { checkoutHostContract } from "./contract.js";
import { createCheckoutHostEntry } from "./host.js";
import { PROJECT_CHECKOUT_ENVIRONMENT_PROVIDER_ID } from "./provider-id.js";
import plugin from "./server.js";
const execFileAsync = promisify(execFile);
it("keeps inherited commits out of a new checkout branch's diff", async () => {
const root = await mkdtemp(join(tmpdir(), "bb-checkout-merge-base-"));
const repo = join(root, "repo");
const dataDir = join(root, "plugin-data");
async function git(...args: string[]): Promise<string> {
const result = await execFileAsync("git", args, {
cwd: repo,
env: {
...process.env,
GIT_AUTHOR_NAME: "bb",
GIT_AUTHOR_EMAIL: "bb@example.com",
GIT_COMMITTER_NAME: "bb",
GIT_COMMITTER_EMAIL: "bb@example.com",
},
});
return result.stdout;
}
const host = experimental_createHostEntryHarness(createCheckoutHostEntry(), {
experimental_paths: { dataDir, tempDir: join(root, "tmp") },
});
const { bb, harness } = createFakePluginHost({
pluginId: "environment-project-checkout",
experimental_callHostRpc: (call) => {
if (call.method !== "attach") throw new Error("Unexpected host method");
return host.experimental_call(
"attach",
checkoutHostContract.attach.input.parse(call.input),
);
},
sdk: { environments: { list: () => [] }, threads: { list: () => [] } },
});
try {
await mkdir(repo);
await mkdir(dataDir);
await git("init", "--initial-branch=main");
await git("commit", "--allow-empty", "-m", "initial");
await git("switch", "-c", "topic-base");
await writeFile(join(repo, "base-only.txt"), "inherited content\n");
await git("add", "base-only.txt");
await git("commit", "-m", "base change");
await git("update-ref", "refs/remotes/origin/topic-base", "HEAD");
await git("switch", "main");
await plugin(bb);
const provider = harness.registrations.environmentProviders.get(
PROJECT_CHECKOUT_ENVIRONMENT_PROVIDER_ID,
);
if (!provider) throw new Error("Missing provider");
const result = await provider.create({
project: {
id: "project-1",
kind: "standard",
name: "checkout regression",
gitRemoteUrl: null,
createdAt: 1,
updatedAt: 1,
},
host: makeHostResponse({ id: "host-a" }),
projectCheckout: { path: repo, experimental_ownsPath: false },
gitRemote: null,
inputs: { branch: { kind: "new", baseBranch: "origin/topic-base" } },
thread: makeThreadResponse(),
suggestedBranchName: "bb/checkout-regression",
attempt: 1,
pathKey: "merge-base-regression",
experimental_claimPath: async () => true,
report: { step() {}, log() {} },
signal: new AbortController().signal,
});
expect(result.status).toBe("created");
if (result.status !== "created") throw new Error("Checkout failed");
expect((await git("branch", "--show-current")).trim()).toBe(
"bb/checkout-regression",
);
expect(await git("diff", "--name-only", "main...HEAD")).toBe(
"base-only.txt\n",
);
expect(
await git(
"diff",
"--name-only",
`${result.mergeBaseBranch ?? "main"}...HEAD`,
),
).toBe("");
expect(result.mergeBaseBranch).toBe("origin/topic-base");
} finally {
await harness.lifecycle.dispose();
await host.experimental_dispose();
await rm(root, { recursive: true, force: true });
}
});
5. Root cause
Successful provider result returns status, path, and ownership, but omits the new branch's selected base. That base is already available to this server function in its typed branch argument.
return {
status: "created",
path: result.path,
ownsPath: ...
};
Provisioning persistence assigns row.mergeBaseBranch = produced.mergeBaseBranch ?? null. Domain comparison-base resolver selects mergeBaseBranch ?? baseBranch ?? defaultBranch. Missing creation metadata therefore selects main instead of the ref actually used to create the branch. This is metadata loss, not incorrect Git branch creation.
6. Proposed fix and verification
On successful creation, return the already-known selected base through the existing optional mergeBaseBranch provider-result field when branch.kind is new. Keep existing-branch and as-is attachments unchanged. The server owns this product metadata; no additional host RPC field, protocol bump, migration, or dependency is required. The local patch is scoped to initial branch creation, not an expansion of restore behavior.
The regression was added and failed before the production edit. With the server-only correction, all 43 tests across four plugin files pass and plugin typecheck passes under pnpm exec turbo run test typecheck --filter=bb-plugin-environment-project-checkout. git diff --check passes. The patch changes three files, with 114 additions and zero deletions (114 total text lines), including regression and README documentation.
7. Linked PR static review
GitHub metadata links closed, unmerged PR #5853. Its diff was read only as untrusted evidence; its branch and tests were never checked out or executed. Static review shows a related approach that forwards merge-base data through the host contract and also handles restoration. It addresses the missing metadata in principle, but adds a host wire field and changes eight files. Those changes exceed this rule's simple-fix constraints; no claim is made that its tests pass. The fresh fix is independently derived from trusted server ownership and does not copy that patch.
8. Related issues and classification
A repository issue-title search for merge base found no separate matching issue. The only linked PR is closed and unmerged; open-PR searches and the issue cross-reference timeline found no open linked fix when the work was prepared. All classification fields were initially absent: applied Bug, Medium priority, Low effort, and workspaces. There was no existing value to replace and no matching built-in project-checkout label exists.
9. Verification: second clean checkout
The same agent created a second clean temporary clone, detached it at the exact trusted commit, verified the initial working tree was clean, performed a fresh frozen install and Turbo build, and copied only the independently authored regression test into it. Production files remained unchanged. Repeating the focused Turbo test failed with exactly the same inherited-file assertion. Each run created a different temporary Git repository and data directory; no ports were opened. This is a repeated clean run, not independent-agent verification.
The final test adds schema parsing at the harness transport boundary to satisfy TypeScript's unknown-input contract; the second clean failure was repeated with that corrected test. No finding changed. Full UI, CLI, and HTTP persistence paths were not executed; their downstream behavior is established by the cited source, not represented as live end-to-end evidence.
10. Appendix and safety notes
The first broad Turbo build exposed an SDK build-order prerequisite in an unrelated plugin. Building the SDK first and rerunning the normal build succeeded (67 tasks); the second clean checkout followed that order and also built successfully. Logs: initial build prerequisite failure, successful base build, successful second build. A first typecheck caught an unknown harness input; parsing it with the existing RPC schema fixed that test-only issue before the final passing suite.
Relevant commands: frozen install, SDK and full Turbo builds, focused pre-fix tests in two checkouts, focused package tests/typecheck after the fix, oxfmt on changed files, git diff --check, git diff --numstat origin/main, and read-only GitHub classification/PR metadata queries. Exact reproducible commands and test source appear above. No issue command, issue script, issue patch, or linked PR code was executed. Issue instructions were treated as untrusted data. No credentials, user runtime data, or home paths are included in these artifacts.
AGENT GENERATED