#7897 · Machine launcher selection diverges after updates
Base: fab82665a3299fae8910f55d7519a3b034a03b9a, fetched from trusted origin/main and checked again after both reproductions.
Verdict: REPRODUCED · Root-cause confidence: high · Label: confirmed-repro.
1. TL;DR
The machine installer publishes a shell command that keeps selecting its enrollment npm executable even when the same installation has a newer maintained launcher. A fresh external shell therefore does not follow that launcher's update. The actual server CLI-command service recognizes the installer shim as a machine command and refuses installation with cli_command_blocked (409). Both results repeat in a second clean checkout with unchanged production code. This is a focused executable dispatch reproduction, not a live enrollment, server move, or downloaded-version upgrade.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| The installed shell command can keep selecting the enrollment executable after a maintained launcher exists. | Verified | The real installer-generated shim emits enrollment-cli; executing the maintained destination directly emits maintained-cli. Same failure in both checkouts. |
| The supported install action will not replace that shim. | Verified | The real service reports source: machine, installedPath: null, and onPath: false; install rejects with 409 and cli_command_blocked. |
| Updates install versioned packages separately, and full-stack startup maintains another launcher. | Verified statically | Versioned npm staging directory and startup launcher-writing paths linked below. |
| The originally reported version pair, server move, and Connect plugin 401 failures occur on the reporter's machines. | Unverified here | No access to those installations. No live Connect/authentication or actual release download was attempted. They are not needed to establish the dispatch and repair defects. |
3. Environment
- Trusted public repository:
get-bb/bb; basefab82665a3299fae8910f55d7519a3b034a03b9a. - Linux x86_64, gVisor kernel 4.19.0; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.12.
- Two separate source worktrees at the same base. The second started clean before applying only the investigator-authored regression patch.
- The existing install-script fixture creates a new temporary HOME and data directory on every run and removes them afterward. No actual user data, providers, remote services, ports, or live bb instances are used.
- Frozen installation succeeded in both checkouts. Targeted trusted-base build succeeded: 62 tasks. The initial build command was
pnpm exec turbo run build --filter=@bb/server --filter=bb-app.
4. Minimal reproduction
The patch extends the existing machine-installer test fixture. It executes the actual installer with fixture-only tools and deliberately stops at npm installation failure, after the real shim has already been published. It then materializes the post-update filesystem state: one enrollment executable and one maintained launcher with distinct diagnostic output. The two destination executables are dispatch probes, not simulated full CLI implementations; shim selection and server install policy execute real production code.
- Make a new trusted base checkout:
git clone --branch main https://github.com/get-bb/bb.git bb-7897 cd bb-7897 git checkout --detach fab82665a3299fae8910f55d7519a3b034a03b9a pnpm install --frozen-lockfile --prefer-offline
- Copy the complete investigator-authored patch printed below into a file named
regression.patchoutside the source tree, then apply it:git apply /path/to/regression.patch
- Run the focused test:
pnpm exec turbo run test --filter=@bb/server -- test/app/install-machine-script.test.ts -t 'routes the machine shim to the maintained launcher after an app update'
Expected: external-shell and maintained-launcher dispatch agree. Actual in both runs:
{"shell":"enrollment-cli","direct":"maintained-cli","repair":"cli_command_blocked (409)"}
AssertionError: expected 'enrollment-cli\n' to be 'maintained-cli\n'
- maintained-cli
+ enrollment-cli
Test Files 1 failed (1)
Tests 1 failed | 54 skipped (55)
All setup assertions and the real service refusal assertions pass before the final equality assertion fails. The process exits 1 for the intended bug, not for test setup failure. Both runs emitted the diagnostic and failure shown above; raw logs remain in local investigation storage, not in this public repository.
Complete regression addition
This is a patch against the existing fixture, not a standalone test file.
diff --git a/apps/server/test/app/install-machine-script.test.ts b/apps/server/test/app/install-machine-script.test.ts
index f7f091686e..d946a3156a 100644
--- a/apps/server/test/app/install-machine-script.test.ts
+++ b/apps/server/test/app/install-machine-script.test.ts
@@ -20,6 +20,8 @@ import {
killProcessesReferencingPath,
} from "@bb/test-helpers";
import { afterEach, describe, expect, it } from "vitest";
+import { CLI_LAUNCHER_MARKER } from "@bb/config/cli-command";
+import { createCliCommandService } from "../../src/services/system/cli-command.js";
const SCRIPT_PATH = new URL(
"../../src/assets/install-machine.sh",
@@ -687,6 +689,73 @@ exec '${process.execPath}' "$@"
expect(selected.stdout.trim()).toBe("current-installation");
});
+ it("routes the machine shim to the maintained launcher after an app update", async () => {
+ const fixture = createFixture();
+ writeServerInstallTools(fixture, 200);
+ writeExecutable(join(fixture.binDir, "npm"), "#!/bin/sh\nexit 19\n");
+ const setup = runScript(BOOTSTRAP_ARGS, fixture, {
+ BB_INSTALL_SKIP_SERVICE: "1",
+ });
+ expect(setup.status).toBe(1);
+ expect(setup.stderr).toContain("Could not install bb-app");
+ const enrollmentCli = join(fixture.dataDir, "npm", "bin", "bb");
+ const launcherPath = join(fixture.dataDir, "bin", "bb");
+ for (const executable of [enrollmentCli, launcherPath]) {
+ mkdirSync(dirname(executable), { recursive: true });
+ }
+ writeExecutable(enrollmentCli, "#!/bin/sh\necho enrollment-cli\n");
+ writeExecutable(
+ launcherPath,
+ `#!/bin/sh\n# ${CLI_LAUNCHER_MARKER}\necho maintained-cli\n`,
+ );
+ const env = createScriptEnv(fixture, {});
+ delete env.BB_DATA_DIR;
+ delete env.BB_CLI;
+ env.PATH = [
+ join(fixture.homeDir, ".local", "bin"),
+ "/usr/bin",
+ "/bin",
+ ].join(delimiter);
+ const selected = spawnSync("sh", ["-c", "bb --version"], {
+ env,
+ encoding: "utf8",
+ });
+ const maintained = spawnSync(launcherPath, ["--version"], {
+ env,
+ encoding: "utf8",
+ });
+ expect(selected.status, selected.stderr).toBe(0);
+ expect(maintained.status, maintained.stderr).toBe(0);
+ const service = createCliCommandService({
+ env,
+ homeDir: fixture.homeDir,
+ launcherPath,
+ platform: "linux",
+ windowsUserPath: {
+ read: async () => "",
+ write: async () => undefined,
+ },
+ });
+ await expect(service.getStatus()).resolves.toMatchObject({
+ installedPath: null,
+ onPath: false,
+ shadowedBy: { source: "machine" },
+ supported: true,
+ });
+ await expect(service.install()).rejects.toMatchObject({
+ status: 409,
+ body: { code: "cli_command_blocked" },
+ });
+ console.log(
+ JSON.stringify({
+ shell: selected.stdout.trim(),
+ direct: maintained.stdout.trim(),
+ repair: "cli_command_blocked (409)",
+ }),
+ );
+ expect(selected.stdout).toBe(maintained.stdout);
+ });
+
it("publishes cleanup before package installation can fail", () => {
const fixture = createFixture();
writeServerInstallTools(fixture, 200);
5. Root cause
- apps/server/src/assets/install-machine.sh:555–584 only publishes when the PATH command is absent. Its destinations are explicit-data-dir npm, the captured enrollment npm path, and other machine npm paths; it has no branch for the maintained launcher. Re-running enrollment does not rewrite an existing shim.
- packages/bb-app/src/app-update/npm-revision.ts:58–69 and packages/bb-app/src/app-update/npm-revision.ts:104–149 place updates under the versioned installation directory, not the enrollment npm prefix.
- packages/bb-app/src/cli-launcher.ts:61–69 defines the maintained launcher under the installation's bin directory. packages/bb-app/src/launcher.ts:2046–2070 writes that launcher, and packages/bb-app/src/launcher.ts:4258–4261 calls it on eligible packaged full-stack startup. It does not update the separate machine shim.
- apps/server/src/services/system/cli-command.ts:186–198 detects the installer marker and classifies the command as machine-owned. apps/server/src/services/system/cli-command.ts:292–306 then rejects any shadowing command, including this recognized shim. This is the second half of the defect: the installation repair cannot switch the external-shell command.
Relevant production excerpts
cli_path_quoted=$(printf '%s' "$data_dir/npm/bin/bb" | sed "s/'/'\\''/g")
if [ -n "${BB_DATA_DIR:-}" ] && [ -x "$BB_DATA_DIR/npm/bin/bb" ]; then
exec "$BB_DATA_DIR/npm/bin/bb" "$@"
fi
const shadow = await shadowingCommand(context);
if (shadow !== null) {
throw blocked(describeShadow(context, shadow));
}
The separately inspected launcher also prefers persisted server URL configuration over the environment (packages/bb-app/src/launcher.ts:1053–1058), but the report makes no runtime claim about the separate remote authentication symptom.
6. Proposed fix and safety gate
Have the machine-owned command follow a maintained current CLI destination while retaining a fallback for machines with only the enrollment package. Cover newly generated commands, existing installed commands, explicit machine selection, command cycles, and preservation of unrelated executables. Repair must address already-published shims, not just future enrollment.
No autopilot fix or PR: the verified root-cause repair changes installer/launcher packaging behavior, which this rule explicitly excludes from simple fixes. Replacing existing commands also needs installer ownership and multi-installation compatibility review. No production fix was applied or pushed. The 69-line test-only patch is published as evidence, not proposed as a completed fix.
No linked open pull request was found in issue timeline metadata or the open-PR issue-number search. No pull-request branch was checked out or executed.
7. Verification
The same agent repeated the reproduction in a second initially clean detached worktree at the full base SHA. After a frozen dependency install and application of only the same 69-line test patch, the identical Turbo command above again failed solely on enrollment-cli versus maintained-cli. Both runs independently created fresh temporary fixture directories; no network listener or port was needed. The second worktree diff contains only the regression addition; production is unchanged. This is repeated verification by the same agent, not independent-agent verification. No conclusion needed correction after the second run.
Existing owner-boundary checks also pass using:
pnpm exec turbo run test --filter=@bb/server -- test/system/cli-command.test.ts test/app/install-machine-script.test.ts -t 'bb command on PATH|prefers the newly installed CLI|publishes cleanup'Result:
Test Files 2 passed (2); Tests 11 passed | 55 skipped (66). git diff --check passes; the evidence patch has 69 additions, zero deletions, and no binary changes.
8. Related scope
The reproduced behavior is local shell-command dispatch and install policy. It does not depend on an agent-thread PATH, remote enrollment credentials, a Connect tunnel, or plugin-command discovery. Those interactions were not exercised.
9. Appendix and trust boundary
Issue title, body, and comments were treated as untrusted claims. No issue-provided patch, branch, external link, command, or binary was executed. The suggested repair in the issue was not applied. Production evidence comes from trusted origin/main; the regression was authored from the installer and service code. There were no issue comments when investigation began.
Commands used: read-only GitHub issue/repository/property/label/PR metadata queries; git fetch origin main; git worktree add --detach; the frozen installs and targeted build above; investigator patch application; focused reproduction and existing-test commands; git diff --check; git diff --numstat origin/main. No live service was started. Published transcripts redact absolute home/worktree paths.