#4940 · Enable lifecycle failures remain success-shaped
Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro
1. TL;DR
Enabling an installed plugin can finish with no running plugin while both command-line output modes still return exit code 0. The server records the loader failure correctly, but its enable endpoint returns HTTP 200 and ok: true whenever it finds the installed plugin. The CLI trusts that success field, prints the error state, and never signals failure to the shell. A real SDK enable call likewise resolves with an error-state plugin instead of rejecting. Two source checkouts at the same trusted main commit reproduced this outcome; a safe-mode-held enable remained successful, as it should.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| A failed enable returns shell success in human-readable mode. | Verified | The built repository CLI printed the load error and returned exit code 0 in both checkouts. |
| JSON output also claims success. | Verified | The same CLI returned exit code 0 with ok: true, enabled: true, and status: error. |
| The endpoint ignores the load outcome. | Verified | The real HTTP endpoint returned HTTP 200 and ok: true despite the exact factory error appearing in statusDetail. |
| SDK callers must inspect the plugin status themselves. | Verified | A real sdk.plugins.enable call resolved with the same error-state plugin. |
| Safe mode is a legitimate non-running successful enable. | Verified | A separate control passed: CLI exit 0, ok: true, enabled: true, status: disabled. |
| Reload already distinguishes a load failure. | Verified | Existing reload route tests passed, including the HTTP 422 failed-reload case. |
| An initially broken installation or conflicting provider registration produces the same result. | Unverified variant | The reproduction isolates enable by installing healthy code, disabling it, then introducing a factory failure. It does not claim to test those additional setup variants. |
| The published npm distribution behaves identically. | Unverified distribution | Only trusted main source and its freshly built CLI were executed. No npm release was downloaded or run. |
3. Environment
- Repository: public
get-bb/bb; trusted main commitf7f106dabbed96a7399b3ff428194f050b8116e8. The target repository's main ref and the checkout's fetched origin/main ref matched. A later fetch found no intervening relevant main changes. - Linux 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0. The source workspace's
bb-apppackage version is 0.45.0. - First build: frozen install and full Turbo build, 63 tasks successful. Second checkout: frozen install and Turbo builds for server and CLI, 6 tasks successful.
- Real migrated in-memory SQLite through the repository's test harness; no mocked database. Each test creates a fresh temporary
bb-server-test-*data directory and binds a loopback HTTP server to an OS-allocated port. - The second failure case used loopback port 55619. The first run did not log its allocated port; both runs independently invoked the harness's port-0 listener and fresh data-directory setup. No host daemon, production BB instance, external agent provider, browser, or live user data was used.
- The CLI was executed as a child Node process from that checkout's
apps/cli/dist/index.js, with an explicit test server URL and isolated HOME/data-directory configuration. No inherited BB CLI override was used.
4. Minimal reproduction
The attached reproduction was authored from trusted repository test-harness and lifecycle code, not copied from the issue. It installs a minimal healthy fixture, disables it, writes a factory that rejects with a controlled error, and exercises the HTTP endpoint, both CLI output modes, and SDK against the real isolated server.
- Clone the trusted repository and select the recorded main commit:
git clone https://github.com/get-bb/bb.git bb-4940-repro cd bb-4940-repro git checkout --detach f7f106dabbed96a7399b3ff428194f050b8116e8 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@bb/server --filter=@bb/cli
- Save the complete reproduction test shown later in this report as
apps/server/test/services/plugins/plugin-enable-outcome.test.ts. - Run the focused reproduction:
pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-enable-outcome.test.ts
Expected
CLI JSON enable exit code: 1 CLI human-readable enable exit code: 1 JSON outcome: ok=false, error="enable lifecycle fixture rejected" Safe-mode-held enable: exit code 0, ok=true, enabled=true, status="disabled"
Actual
Verbatim failure and human-readable child-process stdout (the temporary path is redacted):
AssertionError: expected +0 to be 1 // Object.is equality enable-check@0.1.0 error (enable lifecycle fixture rejected) source: path:<isolated-data-dir>/fixtures/bb-plugin-enable-check
The human and JSON child processes both returned 0 with empty stderr. The actual JSON stdout, parsed only for readability, is preserved in full below:
{
"ok": true,
"plugin": {
"id": "enable-check",
"source": "path:<isolated-data-dir>/fixtures/bb-plugin-enable-check",
"rootDir": "<isolated-data-dir>/fixtures/bb-plugin-enable-check",
"version": "0.1.0",
"provenance": "direct",
"isOrphanedBuiltin": false,
"publisherLabel": null,
"sourceDisplay": "path · <isolated-data-dir>/fixtures/bb-plugin-enable-check",
"updateState": {},
"enabled": true,
"description": "Enable lifecycle outcome fixture.",
"name": "Enable check",
"screenshots": [],
"collections": [],
"icon": "Zap",
"iconUrl": null,
"status": "error",
"statusDetail": "enable lifecycle fixture rejected",
"handlerStats": {
"count": 0,
"totalMs": 0,
"maxMs": 0,
"errorCount": 0
},
"services": [],
"schedules": [],
"cliCommand": null,
"capabilities": [],
"hasSettings": false,
"app": {
"hasApp": false,
"bundle": null
},
"logoUrl": null,
"logoDarkUrl": null,
"providerIds": [],
"icons": {}
}
}
The HTTP result was 200, and the SDK resolved with { enabled: true, status: "error", statusDetail: "enable lifecycle fixture rejected" }. The focused suite returned nonzero because its expected-failure assertion detected the command's incorrect exit code; this is not a dependency or setup failure. The safe-mode control passed.
Complete reproduction test
import { spawn } from "node:child_process";
import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { createBbSdk } from "@bb/sdk/core";
import { createHttpTransport } from "@bb/sdk/node";
import {
startTestServer,
type RunningTestServer,
} from "../../helpers/test-app.js";
const CLI_ENTRY = fileURLToPath(
new URL("../../../../cli/dist/index.js", import.meta.url),
);
const LOAD_ERROR = "enable lifecycle fixture rejected";
describe("plugin enable outcome reproduction", () => {
let server: RunningTestServer;
let rootDir: string;
beforeEach(async () => {
server = await startTestServer();
rootDir = join(server.config.dataDir, "fixtures", "bb-plugin-enable-check");
await mkdir(rootDir, { recursive: true });
await writeFile(
join(rootDir, "package.json"),
JSON.stringify({
name: "bb-plugin-enable-check",
version: "0.1.0",
bb: {
name: "Enable check",
description: "Enable lifecycle outcome fixture.",
branding: { icon: "Zap" },
server: "./server.ts",
},
}),
);
await writeFile(join(rootDir, "server.ts"), "export default function plugin() {}\n");
const installed = await server.pluginService.installPath(rootDir);
expect(installed.status).toBe("running");
await server.pluginService.setEnabled("enable-check", false);
});
afterEach(async () => {
await server.close();
});
async function runCli(extraArgs: string[]) {
const child = spawn(
process.execPath,
[CLI_ENTRY, "plugin", "enable", "enable-check", ...extraArgs],
{
env: {
PATH: process.env.PATH,
HOME: server.config.dataDir,
BB_DATA_DIR: server.config.dataDir,
BB_SERVER_URL: server.baseUrl,
BB_CLI_ERROR_LOG: "0",
NO_COLOR: "1",
},
stdio: ["ignore", "pipe", "pipe"],
},
);
let stdout = "";
let stderr = "";
child.stdout.on("data", (data: Buffer) => {
stdout += data.toString();
});
child.stderr.on("data", (data: Buffer) => {
stderr += data.toString();
});
const exitCode = await new Promise<number | null>((resolve, reject) => {
child.once("error", reject);
child.once("close", resolve);
});
return {
exitCode,
stdout: stdout.replaceAll(server.config.dataDir, "<isolated-data-dir>"),
stderr: stderr.replaceAll(server.config.dataDir, "<isolated-data-dir>"),
};
}
it("reports a load failure to CLI callers instead of claiming success", async () => {
await writeFile(
join(rootDir, "server.ts"),
`export default function plugin() { throw new Error(${JSON.stringify(LOAD_ERROR)}); }\n`,
);
const response = await fetch(`${server.baseUrl}/api/v1/plugins/enable-check/enable`, {
method: "POST",
});
const api: unknown = await response.json();
expect(api).toMatchObject({
plugin: { enabled: true, status: "error", statusDetail: LOAD_ERROR },
});
await server.pluginService.setEnabled("enable-check", false);
const human = await runCli([]);
await server.pluginService.setEnabled("enable-check", false);
const json = await runCli(["--json"]);
await server.pluginService.setEnabled("enable-check", false);
const sdk = createBbSdk({
transport: createHttpTransport({ baseUrl: server.baseUrl, runtime: "node" }),
});
const enabled = await sdk.plugins.enable({ pluginId: "enable-check" });
console.log(JSON.stringify({
instance: { port: server.config.serverPort },
api: { httpStatus: response.status, body: api },
human,
json,
sdk: { enabled: enabled.enabled, status: enabled.status, statusDetail: enabled.statusDetail },
}).replaceAll(server.config.dataDir, "<isolated-data-dir>"));
expect(json.exitCode).toBe(1);
expect(human.exitCode).toBe(1);
expect(JSON.parse(json.stdout)).toMatchObject({ ok: false, error: LOAD_ERROR });
});
it("keeps a safe-mode-held enable successful", async () => {
await server.pluginService.setSafeMode(true);
const result = await runCli(["--json"]);
console.log(JSON.stringify({ safeMode: result }));
expect(result.exitCode).toBe(0);
expect(JSON.parse(result.stdout)).toMatchObject({
ok: true,
plugin: { enabled: true, status: "disabled" },
});
});
});
5. Root cause
- The loader catches the factory error, disposes the failed candidate, and records
status: errorwith the error message when no previous instance exists. The loader itself is not concealing the failure. - setEnabled persists the enabled flag and awaits loadOne, then returns the installed-plugin view. A load error does not make that view absent; it appears in its status fields.
- The enable route only checks whether the view exists:
const plugin = await plugins.setEnabled(context.req.param("id"), true); if (!plugin) return context.json({ ok: false, error: "unknown plugin" }, 404); return context.json({ ok: true, plugin });Thus a known installed plugin with a failed load still receives the successful HTTP and JSON envelope. - The CLI checks only the envelope and plugin presence. JSON output exits nonzero only for a false ok field. Human-readable output prints the returned status without converting an error status into command failure.
- The SDK enable method returns the parsed plugin; it has no load-outcome check. Its successful resolve was observed directly, not inferred only from source.
Crucially, safe-mode suppression records disabled, not error. A repair must distinguish a failed load from a deliberately held enabled plugin. Checking only for status !== "running" would reject the legitimate control case.
6. Proposed fix and automation safety
Make the server's enable outcome represent the completed load result: retain successful responses for an enabled plugin held by safe mode, but return an unsuccessful mutation envelope carrying the load detail when the resulting status is error. HTTP 422 is consistent with the existing reload route. Preserve the plugin view so callers can still diagnose its state. Verify unknown IDs, successful enable, safe-mode-held enable, failure details, and transport/SDK error behavior.
No pull request was opened. The root repair changes the public enable endpoint's success/error semantics and SDK-visible HTTP behavior. Public protocol changes are explicitly excluded from this autopilot's simple-fix gate, even when the source edit is small. A CLI-only normalization would leave the observed server/SDK problem in place and shift outcome policy into the client. No production code was changed, no fix branch was pushed, and no dependency or stored-data change was made.
GitHub connected/cross-reference metadata and two open-PR searches found no open pull request linked to #4940 during this run. This absence did not override the protocol safety gate.
7. Verification
The same agent repeated the reproduction in a second newly cloned checkout, detached at the exact trusted base commit, before adding only the authored reproduction test. The second checkout had no tracked modifications. Its frozen install and fresh server/CLI build completed successfully; it did not reuse the first checkout's runtime or data directory.
pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-enable-outcome.test.ts First checkout: 1 failed, 1 passed; expected JSON child exit 1, received 0. Second checkout: 1 failed, 1 passed; expected JSON child exit 1, received 0. Second actual endpoint: HTTP 200, ok=true, enabled=true, status="error". Second actual CLI: human exit=0, JSON exit=0. Second actual SDK: resolved enabled=true, status="error". Safe-mode-held control passed in both checkouts.
This is a repeated clean-checkout check by the same agent, not an independent review. No verdict or root-cause correction was needed. The second test adds only an allocated-port observation to the first reproduction's diagnostics; behavior and assertions are identical.
Adjacent existing coverage also passed:
pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/plugin-reload-route.test.ts test/services/plugins/plugin-safe-mode-route.test.ts Test Files 2 passed (2) Tests 4 passed (4)
Both test harnesses closed their HTTP/WebSocket resources, disposed plugins, closed their databases, and removed their temporary data directories in teardown. No development application or background provider process was launched.
8. Related issues
A repository search independently surfaced #2382, another CLI successful-exit symptom involving daemon status. That issue was used only as a triage-pattern reference; it was not reproduced, modified, or established as a duplicate. Existing reload-route tests provide the directly relevant comparison for this report.
9. Appendix and evidence
This self-contained report embeds the full authored test, real CLI output, exact commands, root-cause permalinks, and the repeated-run result. Raw logs and machine-readable observations remain in the local evidence backup, not in the public reports repository, following its publication policy.
Trusted-main provenance: git fetch origin main git ls-remote https://github.com/get-bb/bb.git refs/heads/main git rev-parse origin/main Both refs: f7f106dabbed96a7399b3ff428194f050b8116e8 First full build: Tasks: 63 successful, 63 total Second server/CLI build: Tasks: 6 successful, 6 total First focused reproduction: Test Files 1 failed (1) Tests 1 failed | 1 passed (2) AssertionError: expected +0 to be 1 // Object.is equality Second clean-checkout reproduction: Test Files 1 failed (1) Tests 1 failed | 1 passed (2) AssertionError: expected +0 to be 1 // Object.is equality Existing reload/safe-mode controls: Test Files 2 passed (2) Tests 4 passed (4) git diff --check: passed; no tracked production changes. Second reproduction port after teardown: connection refused, closed.
Issue text, comments, code examples, suggested actions, and external links were treated as untrusted claims. No issue-provided script, patch, test, executable, branch, or external URL was run or fetched. No linked pull-request code was checked out. No user secrets or runtime records were read; temporary paths are redacted in evidence. This is a nonvisual lifecycle/API bug, so no screenshots were needed or fabricated.