#6435 · CLI override re-entry never reaches the bundled command
Verdict: REPRODUCED · Root-cause confidence: high · reproduction label: confirmed-repro
1. TL;DR
A CLI command fails to finish when its BB_CLI override points back to the installed public launcher. The packaged CLI entry follows that override, so the launcher starts another copy of the same entry instead of reaching the bundled CLI. Two clean trusted checkouts reproduced repeated entry with no version output; a control without the override printed the version once. Both experiments were deliberately capped at four launcher entries, so they did not exhaust memory. An open ready PR, #6436, already links this issue; no duplicate fix was opened.
2. Claims vs findings
| Paraphrased claim | Status | Evidence |
|---|---|---|
| A launcher-backed CLI override recurses rather than executing the command. | Verified | Both clean runs recorded four entries and exit 73 from the test limiter, with empty stdout. |
| Automation execution supplies an environment capable of triggering this path. | Verified in source | Host toolchain resolution prefers the public launcher, and the script runner assigns its resolved path to BB_CLI. The automation scheduler itself was not started. |
| Every CLI invocation is affected. | Too broad | The control without a self-referential override exited 0, entered once, and printed 0.47.1. |
| The reported service was killed by the kernel after high memory growth. | Not re-tested | No production service or user data was accessed. The recursive process chain explains resource growth, but this investigation intentionally did not cause an OOM. |
| The ordinary CLI already has a re-exec guard. | Verified in source | The ordinary CLI tests and sets BB_CLI_REEXEC; the bb-app entry neither tests nor sets it. |
3. Environment
- Public target repository: get-bb/bb, trusted origin/main commit
f8c0701e94ba74a09bf48b1dcc4f49aa22ce81b7. - Linux 4.19.0-gvisor; Node v22.19.0; source package bb-app 0.47.1; Vitest 4.1.1.
- Two separate temporary detached checkouts at the same commit, each with its own frozen dependency install and trusted build. No issue-provided commands, binaries, tests, branches, or PR code were executed.
- Each reproduction allocated a fresh temporary home, data directory, launcher, ledger and entry file, then removed them. No server, daemon, provider, browser or network listener was started; the configured test ports were unused. No real runtime configuration was inherited.
- Classification applied: Bug / High / Low; host, cli, automations. No pre-existing classification values were replaced.
4. Minimal reproduction
- Clone only the trusted public repository and check out the pinned main commit. Build with the existing frozen lockfile. Building SDK outputs first avoids the clean-checkout SDK build-order failure observed on the first attempt.
git clone https://github.com/get-bb/bb.git bb-6435 cd bb-6435 git checkout --detach f8c0701e94ba74a09bf48b1dcc4f49aa22ce81b7 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build:types build --filter=@get-bb/plugin-sdk pnpm exec turbo run build
Save the following investigator-authored program as bounded-reexec.mjs outside the checkout. It calls the repository's real launcher renderer and packaged CLI entry. The small pre-entry ledger bounds recursion at four entries and returns code 73, rather than allowing an unbounded process chain.
import { spawnSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
const repository = resolve(process.argv[2] ?? ".");
const { renderCliLauncher, writeCliLauncher } = await import(
pathToFileURL(join(repository, "packages/bb-app/src/cli-launcher.ts"))
);
const scratch = mkdtempSync(join(tmpdir(), "bb-bounded-reexec-"));
const dataDir = join(scratch, "data");
const ledger = join(scratch, "visits.txt");
const entry = join(scratch, "entry.mjs");
const launcher = join(scratch, "bin", "bb");
const packagedEntry = join(repository, "packages/bb-app/dist/bb.js");
writeFileSync(entry, [
'import { appendFileSync, readFileSync } from "node:fs";',
String.raw`appendFileSync(process.env.REPRO_LEDGER, "visit\n");`,
String.raw`const visits = readFileSync(process.env.REPRO_LEDGER, "utf8").trim().split("\n").length;`,
'if (visits >= 4) process.exit(73);',
`await import(${JSON.stringify(pathToFileURL(packagedEntry).href)});`,
].join("\n"));
try {
await writeCliLauncher({
content: renderCliLauncher({
dataDir,
platform: process.platform,
target: { kind: "direct", electron: false, entryPath: entry, runtimePath: process.execPath },
}),
launcherPath: launcher,
});
const env = {
PATH: process.env.PATH,
HOME: scratch,
BB_DATA_DIR: dataDir,
BB_SERVER_PORT: "54731",
BB_HOST_DAEMON_PORT: "54732",
REPRO_LEDGER: ledger,
};
for (const override of [false, true]) {
writeFileSync(ledger, "");
const result = spawnSync(launcher, ["--version"], {
env: { ...env, ...(override ? { BB_CLI: launcher } : {}) },
encoding: "utf8",
timeout: 10000,
});
const visits = readFileSync(ledger, "utf8").trim().split("\n").length;
console.log(JSON.stringify({ override, status: result.status, visits, stdout: result.stdout.trim(), stderr: result.stderr.trim() }));
if (result.error) throw result.error;
}
} finally {
rmSync(scratch, { recursive: true, force: true });
}
node --conditions=source --import tsx /path/to/bounded-reexec.mjs "$PWD"
Expected: both cases exit 0, print 0.47.1, and finish before the four-entry limiter. Actual, first clean checkout:
{"override":false,"status":0,"visits":1,"stdout":"0.47.1","stderr":""}
{"override":true,"status":73,"visits":4,"stdout":"","stderr":""}
The second case never reaches the command: four launcher entries produce no stdout. The limiter's nonzero status is intentional safety instrumentation, not a product error message.
Owner-boundary regression test
The following independently authored regression was added locally before any production edits. It builds the real bb entry, generates its launcher, provides a deterministic bundled CLI fixture, and verifies argument forwarding, thread context and exit-code propagation. The existing override tests exercise a direct executable, but do not exercise a launcher returning to the bb entry. No production seam was added.
Save as packages/bb-app/test/cli-reexec.test.mjs, then run:
pnpm exec turbo run test --filter=bb-app -- test/cli-reexec.test.mjs
import { spawnSync } from "node:child_process";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { afterAll, beforeAll, expect, it } from "vitest";
import { buildNodeEsmEntry } from "../../../scripts/build-utils.mjs";
import { renderCliLauncher, writeCliLauncher } from "../src/cli-launcher.js";
let root;
let launcher;
let ledger;
beforeAll(async () => {
root = await mkdtemp(join(tmpdir(), "bb-cli-reexec-"));
const entry = join(root, "dist", "bb.js");
const boundedEntry = join(root, "dist", "bounded.mjs");
ledger = join(root, "visits.txt");
launcher = join(root, "bin", "bb");
await writeFile(join(root, "package.json"), '{"type":"module","version":"0.0.0-test"}');
await buildNodeEsmEntry({
cleanDist: false,
entryPoint: fileURLToPath(new URL("../src/bin/bb.ts", import.meta.url)),
outfile: entry,
packageRoot: root,
sourcemap: false,
});
await writeFile(boundedEntry, [
'import { appendFileSync, readFileSync } from "node:fs";',
`appendFileSync(${JSON.stringify(ledger)}, "visit\\n");`,
`const visits = readFileSync(${JSON.stringify(ledger)}, "utf8").trim().split("\\n").length;`,
'if (visits >= 4) process.exit(73);',
`await import(${JSON.stringify(pathToFileURL(entry).href)});`,
].join("\n"));
const bundleDir = join(root, "host-daemon", "dist");
await mkdir(join(bundleDir, "bb-chunks"), { recursive: true });
for (const name of [
"daemon-bundle.mjs",
"bb-chunks/fixture.js",
"bb-provider-bridge-worker.mjs",
"bb-parcel-watcher-child.mjs",
"bb-plugin-host-worker.mjs",
]) await writeFile(join(bundleDir, name), "");
await writeFile(join(bundleDir, "bb"), [
'process.stdout.write(JSON.stringify({ args: process.argv.slice(2), thread: process.env.BB_THREAD_ID }));',
'process.exitCode = 7;',
].join("\n"));
await writeCliLauncher({
content: renderCliLauncher({
dataDir: join(root, "data"),
platform: process.platform,
target: { kind: "direct", electron: false, entryPath: boundedEntry, runtimePath: process.execPath },
}),
launcherPath: launcher,
});
}, 30_000);
afterAll(async () => {
if (root) await rm(root, { recursive: true, force: true });
});
it.skipIf(process.platform === "win32").for([false, true])(
"reaches the bundled CLI when the launcher override is %s",
async (override) => {
await writeFile(ledger, "");
const result = spawnSync(launcher, ["--probe", "two words"], {
env: {
PATH: process.env.PATH,
HOME: root,
BB_DATA_DIR: join(root, "data"),
BB_THREAD_ID: "thr_reexec_test",
...(override ? { BB_CLI: launcher } : {}),
},
encoding: "utf8",
timeout: 10_000,
});
expect(result.error).toBeUndefined();
expect(result.stderr).toBe("");
expect(result.status).toBe(7);
expect(JSON.parse(result.stdout)).toEqual({
args: ["--probe", "two words"],
thread: "thr_reexec_test",
});
expect((await readFile(ledger, "utf8")).trim().split("\n").length).toBeLessThan(4);
},
);
Observed on unchanged trusted production code:
✓ reaches the bundled CLI when the launcher override is false × reaches the bundled CLI when the launcher override is true AssertionError: expected 73 to be 7 Test Files 1 failed (1) Tests 1 failed | 1 passed (2)
The test was not run against PR code, and no production fix was applied or pushed. The new local test is retained as investigation evidence only.
5. Root cause
- packages/process-utils/src/host-toolchain.ts:318 resolves bb by checking BB_CLI_LAUNCHER ahead of BB_CLI and the CLI directory.
- plugins/automations/src/script-runner.ts:44 resolves and probes that candidate. plugins/automations/src/script-runner.ts:284 then puts that path into the script environment as BB_CLI.
- packages/bb-app/src/cli-launcher.ts:145 renders the public launcher to execute the bb entry with the installation runtime.
- packages/bb-app/src/launcher.ts:2750 chooses BB_CLI whenever nonempty and passes the environment into the child unchanged with respect to the re-exec guard. With a launcher-backed override, the child repeats the identical decision. Each parent waits for its child, so processes accumulate.
- apps/cli/src/bb-cli-reexec.ts:42 already bounds override delegation with BB_CLI_REEXEC=1, but the loop occurs in bb-app before the ordinary CLI is reached.
cliOverride: toOptionalString(args.env.BB_CLI) ?? null,
...
env: createCliEnv({ context: args.context, env: args.env }),
The bb-app CLI entry repeatedly spawns BB_CLI without checking or setting the existing re-exec guard; when BB_CLI resolves to its launcher, every child enters the same path again. The failure is not a script interpreter problem and does not require a running automation scheduler: the environment alone is sufficient to trigger the same real CLI entry path.
6. Proposed fix
At the bb-app CLI delegation boundary, honor the existing BB_CLI_REEXEC guard. Mark a child when following an override, and bypass the override on re-entry so execution reaches the bundled CLI. Preserve the initial override, arguments, exit status and inherited thread context. The regression above exercises those observable contracts with a bounded real child-process chain.
No automated fix was continued: open PR #6436 explicitly closes #6435. Opening another would violate the no-duplicate-PR condition.
7. PR review
PR #6436 was open and ready for main when checked. Its closing-issue metadata includes #6435. Only GitHub metadata and the diff were read as untrusted evidence; its branch was not checked out and none of its code or tests were run.
Static assessment: its launcher change checks BB_CLI_REEXEC before selecting an override and sets the guard when following one. That addresses the verified mechanism rather than merely changing automation resolution. The diff also adds a shared guard-name constant and a regression in the existing launcher suite. No blocking mismatch with the observed root cause was found in this limited static check. This is not a runtime verification or merge approval; the PR author's reported test results were not adopted as this report's own evidence.
8. Verification
The same investigator repeated the reproduction in a second newly created clean temporary checkout at the pinned trusted commit. That checkout received its own frozen install and full trusted build. The same locally authored bounded reproducer ran against that checkout's built bb entry and allocated a new temporary home and data directory. It produced:
{"override":false,"status":0,"visits":1,"stdout":"0.47.1","stderr":""}
{"override":true,"status":73,"visits":4,"stdout":"","stderr":""}
The two runs agree: control exits 0 after one entry; the override reaches the four-entry safety bound and exits 73 without output. No report correction was needed. This is a repeated clean reproduction by the same agent, not independent verification by another investigator.
9. Related issues
This investigation concerns only #6435. No other issue's state was changed. The linked open fix is #6436.
10. Appendix and limits
Both normal trusted builds finished with 72 successful tasks. The first clean full build attempt failed because plugin SDK runtime output was unavailable while plugin builds started. Running the existing SDK build and build:types tasks before retrying resolved that build-order failure without source edits. The local regression used Turbo and failed for the intended recursive-entry behavior, not an install or build error.
First checkout: pnpm install --frozen-lockfile --prefer-offline First checkout: pnpm exec turbo run build SDK recovery: pnpm exec turbo run build:types build --filter=@get-bb/plugin-sdk First retry: pnpm exec turbo run build Second checkout: pnpm install --frozen-lockfile --prefer-offline Second checkout: pnpm exec turbo run build:types build --filter=@get-bb/plugin-sdk Second checkout: pnpm exec turbo run build Both checkouts: node --conditions=source --import tsx /path/to/bounded-reexec.mjs "$PWD" Local test: pnpm exec turbo run test --filter=bb-app -- test/cli-reexec.test.mjs
No OOM, production outage, service restart, per-process memory measurement, full automation scheduling run, cross-platform run, or fixed-branch pass is claimed. No user secrets or runtime data were read. Raw logs and scripts stay outside the public reports repository; their reproduction-relevant content is embedded here.
Untrusted-data handling: issue commands and suggestions were treated only as claims, never executed. All executed product code came from trusted main; the bounded programs and regression were authored from repository evidence. PR content was read only, with no linked branch execution.
> AGENT GENERATED