#7114 · Short-base ref precedence includes upstream changes
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
A clean topic worktree can show upstream-only changes in its committed branch comparison when its short base name resolves to an older local branch. A real-Git test at the Git plugin's workspace-read boundary reproduces two files for the short base and one for the explicit remote base. The resolver returns the first valid local revision; it never compares that revision with the available tracking revision. This is not a dirty-working-tree problem or an absent remote ref. Importantly, local-first resolution is currently an explicit documented and tested policy, so changing the default is not safe for the simple-fix autopilot without a product-policy decision.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| A stale local base adds unrelated upstream changes. | Verified | Both fresh runs include upstream-only.txt for short main. |
| An explicit remote comparison avoids the extra file. | Verified | origin/main returns only topic-only.txt in both runs. |
| The workspace can be clean. | Verified | git status --porcelain returns the empty string. |
| The resolver checks the local name first. | Verified | Trusted source, source history, and explicit-local control all agree. |
| The specific desktop version and large real-workspace counts match this fixture. | Unverified | No access to the reporter's macOS workspace; the small backend reproduction proves the mechanism, not those exact counts. |
3. Environment
- Trusted public repository: get-bb/bb; main commit
fa30b0a7dcdf745f7baf8e41721f754b7d3198fe, checked against GitHub main again after reproduction. - Linux 4.19.0-gvisor x86_64; Node v22.19.0; pnpm 9.15.0; Git 2.39.5; Vitest 4.1.1.
- Two detached source checkouts:
/tmp/bb-7114-investigation/primaryand/tmp/bb-7114-investigation/verification. Paths in saved logs are normalized. - No live bb instance, providers, browser, listening ports, or user runtime data were needed. Each test creates a new temporary repository and an actual linked worktree, and removes them at teardown.
- A normal frozen install passed. The first full build hit a clean-checkout SDK build-order failure in the unrelated GitHub plugin. Building the SDK through Turbo and retrying the full build passed: 73 tasks.
4. Minimal reproduction
These commands run only the recorded trusted main commit plus this report's newly authored test. The fixture was designed from the trusted implementation, not copied from the issue or linked PR.
git clone https://github.com/get-bb/bb.git bb-7114 cd bb-7114 git checkout --detach fa30b0a7dcdf745f7baf8e41721f754b7d3198fe pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk curl -fsS https://get-bb.github.io/reports/issues/7114/repro/stale-base-repro.test.ts -o plugins/git/host/stale-base-repro.test.ts pnpm exec turbo run test --filter=bb-plugin-bb--git -- host/stale-base-repro.test.ts
- The fixture leaves local main at the initial commit.
- It creates a separate upstream branch with upstream-only.txt and sets the local origin/main tracking ref to that newer commit. No network fetch or remote server is needed.
- It adds a linked topic worktree from origin/main and commits topic-only.txt there.
- It calls the production WorkspaceReads.diffFiles boundary for short main, explicit origin/main, and explicit refs/heads/main.
- The remote and local controls pass; the expected short-base assertion fails because upstream-only.txt appears.
Expected short-base file list: ["topic-only.txt"]. Actual output, verbatim in both runs:
{"clean":"","shortBase":["topic-only.txt","upstream-only.txt"],"remoteBase":["topic-only.txt"],"explicitLocal":["topic-only.txt","upstream-only.txt"]}
Expected-failure result: exit 1, one failed test, at the final assertion comparing the short-base file list. No production fix was applied.
Download the complete regression test. No screenshot is needed: this is a backend comparison-correctness defect, not a rendering defect. The desktop UI was not exercised.
Complete reproduction test
import fs from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { expect, it } from "vitest";
import { initRepo } from "@bb/test-helpers";
import { runGit } from "bb-environment-provider-host/workspace-git";
import { WorkspaceReads } from "./workspace-reads.js";
it("excludes upstream-only commits when a short base has a newer tracking ref", async ({
onTestFinished,
}) => {
const directory = await fs.mkdtemp(path.join(tmpdir(), "bb-base-repro-"));
onTestFinished(() => fs.rm(directory, { recursive: true, force: true }));
const repository = path.join(directory, "repository");
const worktree = path.join(directory, "topic");
await fs.mkdir(repository);
await initRepo(repository);
await runGit(["checkout", "-b", "upstream"], { cwd: repository });
await fs.writeFile(path.join(repository, "upstream-only.txt"), "upstream\n");
await runGit(["add", "."], { cwd: repository });
await runGit(["commit", "-m", "Advance upstream"], { cwd: repository });
await runGit(["update-ref", "refs/remotes/origin/main", "HEAD"], {
cwd: repository,
});
await runGit(["checkout", "main"], { cwd: repository });
await runGit(["worktree", "add", "-b", "topic", worktree, "origin/main"], {
cwd: repository,
});
await fs.writeFile(path.join(worktree, "topic-only.txt"), "topic\n");
await runGit(["add", "."], { cwd: worktree });
await runGit(["commit", "-m", "Add topic work"], { cwd: worktree });
const workspace = new WorkspaceReads(worktree, directory);
const clean = await runGit(["status", "--porcelain"], { cwd: worktree });
const [shortBase, remoteBase, explicitLocal] = await Promise.all(
["main", "origin/main", "refs/heads/main"].map(async (mergeBaseBranch) => {
const result = await workspace.diffFiles({
freshness: { work: mergeBaseBranch, refs: mergeBaseBranch },
target: { type: "branch_committed", mergeBaseBranch },
maxFiles: 100,
ignoreWhitespace: false,
});
return result.files.map((file) => file.path).sort();
}),
);
console.log(JSON.stringify({ clean: clean.stdout.trim(), shortBase, remoteBase, explicitLocal }));
expect(clean.stdout.trim()).toBe("");
expect(remoteBase).toEqual(["topic-only.txt"]);
expect(explicitLocal).toEqual(["topic-only.txt", "upstream-only.txt"]);
expect(shortBase).toEqual(["topic-only.txt"]);
});
5. Root cause
resolveMergeBaseBranch builds short-name candidates in local-first order and returns immediately on the first valid commit:
const candidates =
ref.startsWith("refs/") || ref.startsWith("origin/")
? [ref]
: [ref, `refs/remotes/origin/${ref}`];
for (const candidate of candidates) {
const result = await runGit(
["rev-parse", "--verify", "--end-of-options", `${candidate}^{commit}`],
{
cwd,
...options,
priority: options.priority ?? gitPriority(),
allowFailure: true,
},
);
if (result.exitCode === 0 && trimOutput(result.stdout)) {
return trimOutput(result.stdout);
}
When the old local main resolves, the newer origin/main is never considered. readMergeBaseRef then computes the common ancestor of that old base and HEAD. resolveTrackedDiffRange uses that ancestor through HEAD for branch_committed, so the upstream commit is necessarily included. WorkspaceReads merge-base resolution shares this resolver; status also calls the same ref selector. The controls hold workspace contents constant and change only the base selector, isolating ref precedence from freshness caching or uncommitted state.
Underlying contract conflict
The shipped Git skill explicitly documents requested-ref-first resolution. Existing coverage expects a newer local main to win over an older remote tracking ref. Trusted commit 01162cbdf079b708a75563ed202c61af48840fbe explicitly says it preserves local-ref precedence. Thus the reported surprise is real, but unconditional remote-first ordering changes an intentional caller contract beyond the stale-local case.
6. Proposed fix and simple-fix check
First settle whether short names should always mean the remote tracking branch, prefer only a strictly newer tracking descendant, or retain Git's local-name semantics while the Diff tab supplies an explicit remote default. Preserve explicit local refs and local-only repositories either way. Then add coverage for stale local, newer local, divergent refs, remote-only, local-only, and explicit refs before applying the chosen policy consistently to status and diff reads and updating the skill.
No autopilot PR: the no-product-decision condition fails because the current default is explicitly documented, tested, and intentional in trusted history. No production patch, branch, dependency, protocol, schema, stored-data change, commit, or push to get-bb/bb was made. An explicit origin/<branch> selector remains a verified workaround. The focused regression fails on unchanged production code and is retained here as evidence.
7. Linked PR review
PR #7115 — static review only; closed, unmerged
The diff swaps the two short-name candidates, adds a regression, updates documentation, and changes the existing local-precedence assertion to request an explicit local ref. It addresses the demonstrated stale-local mechanism. Medium-severity policy risk at plugins/git/host/git.ts:304: this also chooses the remote when local is newer or divergent; changing the older test's input does not verify that those formerly supported callers should change behavior. Verdict: policy review required. No PR branch was checked out, no PR code was run, and no patch or test from the PR was used. Only metadata and the diff were read as untrusted data. There was no open linked PR at the final check.
8. Related issues
Trusted source history links the remote-only-base handling to PR #6359, a related but different failure (missing local ref rather than an older one). The reported workspace-provisioning issue is a different boundary and is not needed to establish this comparison defect.
9. Verification
The same agent repeated the reproduction in a second clean detached checkout at the exact trusted SHA. Only the newly authored test was copied over; the production tree remained unchanged. A fresh frozen install and Turbo SDK build prepared that checkout. The test created its own fresh temporary repository and linked worktree. No ports or app data directories were used.
git worktree add --detach "$scratch/verification" fa30b0a7dcdf745f7baf8e41721f754b7d3198fe cd "$scratch/verification" pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk cp "$report/7114/repro/stale-base-repro.test.ts" plugins/git/host/stale-base-repro.test.ts pnpm exec turbo run test --filter=bb-plugin-bb--git -- host/stale-base-repro.test.ts
| Run | Result |
|---|---|
| Primary | Exit 1; one expected assertion failure; short=2, remote=1, explicit local=2. |
| Second clean checkout | Exit 1; the same assertion and file lists; test body ran (not a cached test result). |
| Unchanged existing Git plugin suite | 35 files and 276 tests passed after removing the investigative test. |
No correction to the mechanism or verdict was necessary. One attempted baseline command used Vitest --exclude, but shared project discovery still included the investigative test; that run had 276 passes plus the intentional failure. The final clean baseline run removed the investigative file and passed. This is a repeated check by the same agent, not independent verification.
10. Appendix
Issue content and linked PR data were treated as untrusted claims only. No issue instructions, external issue links, scripts, branches, tests, or patches were executed. The public output omits home paths and user runtime information. Classification was filled only where absent: Bug, Medium priority, Low effort, workspaces; confirmed-repro is the reproduction label.
- repro-primary.log
- repro-verification.log
- baseline-tests.log
- existing-tests.log
- build-primary.log
- build-primary-retry.log
Commands actually used are captured by the logs: frozen installation in each checkout; full Turbo build (initial SDK order failure, SDK build, successful retry); focused Turbo test in each checkout; attempted excluded baseline and final unchanged full Git plugin test. Read-only GitHub checks inspected issue properties, repository visibility, linked PR state/diff, and current main. Final source checkout has no production modifications. Fixture cleanup runs through Vitest teardown; no server or browser cleanup was required.
Agent-generated reproduction report · 2026-11-05.