← reports

#6557 · Launcher hand-off recursion is already guarded on main

BugHighEffort: Lowhost · cli · automations · no-reproIssue #6557

2026-10-29 · trusted origin/main 3bacfac9ed69d42392076e5b3da2815bec822cd8

Verdict: ALREADY FIXED · Root-cause confidence: high

1. TL;DR

The reported failure is an unbounded chain of CLI launches when an automation's CLI override resolves back to the public launcher. Historically the app entry followed that override on every invocation, leaving each parent waiting for another copy. Trusted main already contains the guard from merged PR #6436: mark the first override hand-off and ignore the override on re-entry. Two clean source checkouts each completed a bounded real-launcher probe with exactly two app-entry visits and one successful version result. No duplicate fix is warranted.

2. Claims vs findings

ClaimFindingEvidence
An automation can select the public launcher as its CLI.Verified in sourceThe runner uses the host toolchain, whose bb lookup prefers the launcher, then sets BB_CLI.
App-entry delegation can repeatedly launch itself.Historical cause supported; not present on tested mainThe trusted merge adds the missing handshake. Both runtime probes stop after two entry visits.
The reported desktop installation consumed extreme memory.Unverified hereNo macOS installation or unbounded resource-exhaustion experiment was run.
Main needs another recursion fix.Refuted for tested pathThe landed guard, existing regression, and real generated launcher checks pass.

3. Environment

4. Minimal reproduction / regression check

This checks the launcher cycle directly, not the desktop automation schedule. A tiny entry trampoline logs visits, caps them at four, and immediately imports the actual built app CLI. The production renderer generates the shell launcher; the real built app entry and bundled CLI execute. A process-group timeout adds a second safety bound.

  1. From a clean get-bb/bb checkout:
    git fetch origin main
    git checkout --detach 3bacfac9ed69d42392076e5b3da2815bec822cd8
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build:types build --filter=@get-bb/plugin-sdk
    pnpm exec turbo run build
  2. Save the complete inline artifact below as launcher-reentry.mjs outside the checkout. Set REPRO to its absolute path, then run from the checkout:
    node --conditions=source --import tsx "$REPRO" "$PWD"
    pnpm exec turbo run test --filter=bb-app -- test/index.test.ts

Expected: exit 0, initial unmarked entry, one marked override re-entry, one version line, no further launches.

Actual, first run:

{"status":"PASS","code":0,"entries":[{"depth":1,"reexec":null},{"depth":2,"reexec":"1"}],"stdout":"0.48.0","safetyEntryCap":4,"timeoutMs":15000}

Actual, second clean run:

{"status":"PASS","code":0,"entries":[{"depth":1,"reexec":null},{"depth":2,"reexec":"1"}],"stdout":"0.48.0","safetyEntryCap":4,"timeoutMs":15000}

The existing app-entry suite passes 69/69 tests in each checkout, including its launcher re-entry regression. Both complete builds pass 72/72 tasks after the SDK prerequisite.

Complete safe reproduction artifact
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";

const checkout = resolve(process.argv[2] ?? process.cwd());
const { renderCliLauncher } = await import(
  pathToFileURL(join(checkout, "packages/bb-app/src/cli-launcher.ts")).href
);
const scratch = await mkdtemp(join(tmpdir(), "bb-6557-reentry-"));
const cliEntry = join(checkout, "packages/bb-app/dist/bb.js");
const launcherPath = join(scratch, "bin/bb");
const entryPath = join(scratch, "entry.mjs");
const tracePath = join(scratch, "trace.jsonl");
await mkdir(join(scratch, "bin"));
await mkdir(join(scratch, "home"));
await writeFile(
  entryPath,
  [
    'import { appendFileSync } from "node:fs";',
    `const tracePath = ${JSON.stringify(tracePath)};`,
    'const depth = Number(process.env.REPRO_ENTRY_DEPTH ?? "0") + 1;',
    'appendFileSync(tracePath, JSON.stringify({ depth, reexec: process.env.BB_CLI_REEXEC ?? null }) + "\\n");',
    'if (depth > 4) { process.stderr.write("re-entry safety cap reached\\n"); process.exit(90); }',
    'process.env.REPRO_ENTRY_DEPTH = String(depth);',
    `await import(${JSON.stringify(pathToFileURL(cliEntry).href)});`,
  ].join("\n"),
);
await writeFile(
  launcherPath,
  renderCliLauncher({
    dataDir: join(scratch, "data"),
    platform: process.platform,
    target: { kind: "direct", electron: false, runtimePath: process.execPath, entryPath },
  }),
  { mode: 0o755 },
);

try {
  const result = await new Promise((resolveResult, rejectResult) => {
    const child = spawn(launcherPath, ["--version"], {
      cwd: checkout,
      detached: true,
      env: {
        PATH: "/usr/bin:/bin",
        HOME: join(scratch, "home"),
        BB_DATA_DIR: join(scratch, "data"),
        BB_CLI: launcherPath,
        BB_CLI_LAUNCHER: launcherPath,
        BB_SERVER_URL: "http://127.0.0.1:1",
        BB_CLI_ERROR_LOG: "0",
      },
      stdio: ["ignore", "pipe", "pipe"],
    });
    let stdout = "";
    let stderr = "";
    const timer = setTimeout(() => {
      process.kill(-child.pid, "SIGKILL");
      rejectResult(new Error("launcher exceeded 15-second safety timeout"));
    }, 15_000);
    child.stdout.setEncoding("utf8").on("data", (chunk) => { stdout += chunk; });
    child.stderr.setEncoding("utf8").on("data", (chunk) => { stderr += chunk; });
    child.once("error", (error) => { clearTimeout(timer); rejectResult(error); });
    child.once("close", (code, signal) => {
      clearTimeout(timer);
      resolveResult({ code, signal, stdout, stderr });
    });
  });
  const entries = (await readFile(tracePath, "utf8")).trim().split("\n").map((line) => JSON.parse(line));
  const { version } = JSON.parse(await readFile(join(checkout, "packages/bb-app/package.json"), "utf8"));
  assert.equal(result.code, 0, result.stderr);
  assert.equal(result.signal, null);
  assert.deepEqual(entries, [{ depth: 1, reexec: null }, { depth: 2, reexec: "1" }]);
  assert.equal(result.stdout.trim(), version);
  assert.equal(result.stderr, "");
  console.log(JSON.stringify({ status: "PASS", code: result.code, entries, stdout: result.stdout.trim(), safetyEntryCap: 4, timeoutMs: 15000 }));
} finally {
  await rm(scratch, { recursive: true, force: true });
}

5. Root cause

resolveBbBinary selects the host toolchain's bb executable. Toolchain lookup prefers the public launcher over the direct CLI. The script runner sets BB_CLI to that path. This is safe only if entry-point delegation is loop-safe.

The generated direct launcher replaces its shell with the app CLI runtime. The app CLI entry calls runBbCli, which delegates through runBundledCliCommand. Historically this honored BB_CLI every time without remembering the prior hand-off. A launcher-valued override therefore recursively launched the same path, leaving a waiting parent at each step.

Current main prevents this at the app-entry owner boundary:

const cliOverride =
  args.env[CLI_REEXEC_ENV_NAME] === "1"
    ? null
    : (toOptionalString(args.env.BB_CLI) ?? null);
...
if (cliOverride !== null) {
  env[CLI_REEXEC_ENV_NAME] = "1";
}

The marker is BB_CLI_REEXEC. After one override hand-off, re-entry selects the bundled CLI. The CLI's own handler respects the same marker. Trusted merge 544e49c1fe71f6374ce42dd65838446c133cdea2 added app-entry protection and its regression on October 28, 2026 at 19:07 UTC, before this issue was filed on October 29, 2026.

6. Fix assessment

The smallest fix is to mark an override hand-off and stop honoring that override on re-entry. This already exists. Preserve the existing owner regression rather than duplicating source tests. No fix branch or PR was created: the bug does not reproduce on trusted main, failing the mandatory autopilot fix gate. Whether the reporter's installed desktop build includes the landed commit was not established.

7. Landed PR evidence

#6436 is merged at 544e49c1fe71f6374ce42dd65838446c133cdea2; no open PR referencing #6557 was returned by cross-reference metadata or open-PR search. The trusted merge changes the app launcher, marker constant, and existing owner test. Current-main runtime checks support the root-cause repair. No linked PR branch was checked out or executed.

8. Related issues

#6435 tracks the historical mechanism and was closed by #6436 on October 28, 2026. #6557 was already closed when investigation began; its state was preserved.

9. Verification

The same agent repeated verification in a second clean detached clone at the exact base, with a separate frozen install, separate builds, and fresh temporary HOME/data paths. Both full builds, the 69-test owner suite, and bounded launcher probe passed. Both tracked worktrees stayed clean. No report correction was required. This is repeated verification by the same agent, not independent verification.

10. Appendix and limits

The initial first-checkout all-package build failed because SDK runtime outputs were absent; building SDK runtime/types and retrying passed all 72 tasks without source edits. The reproduction commands include that prerequisite. Raw local logs are not published, in accordance with this site's artifact policy; all reproduction code and decisive outputs are inline.

First checkout:
pnpm install --frozen-lockfile --prefer-offline: exit 0
pnpm exec turbo run build:types build --filter=@get-bb/plugin-sdk: exit 0
pnpm exec turbo run build: 72 successful, 72 total; exit 0
pnpm exec turbo run test --filter=bb-app -- test/index.test.ts: 69 passed; exit 0
bounded launcher check: PASS; exit 0
git status --porcelain: empty

Second clean checkout:
pnpm install --frozen-lockfile --prefer-offline: exit 0
pnpm exec turbo run build:types build --filter=@get-bb/plugin-sdk: exit 0
pnpm exec turbo run build: 72 successful, 72 total; exit 0
pnpm exec turbo run test --filter=bb-app -- test/index.test.ts: 69 passed; exit 0
bounded launcher check: PASS; exit 0
git status --porcelain: empty

Historical code was inspected through trusted history but not executed. The reported macOS installation, process count, memory total, and scheduler integration were not reproduced. The direct, supported conclusion is that the self-referential launcher path is guarded on the tested trusted main. This nonvisual process-control bug needs no image.

Issue content and comments were untrusted claims. No issue-supplied commands, scripts, patches, binaries, branches, or external links were executed or fetched. The safe probe was designed from trusted repository evidence.

> AGENT GENERATED