Skip to content

bb plugin enable exits 0 and reports ok: true when the plugin fails to load #4940

Closed

Description

@regenrek

Summary

bb plugin enable <id> returns exit code 0 whenever the server knows the plugin, even if the load triggered by the enable fails and the plugin ends in status error. The failure is visible only as text in the human-readable output; --json reports ok: true as well. Scripts that chain on the exit code treat the plugin as enabled when it is not running.

Observed on bb 0.45.0 (npm bb-app); the code paths below are unchanged on main at 7fd6ee9.

Reproduction

  1. Create a path plugin whose server factory throws:

    export default definePlugin(() => {
      throw new Error("boom");
    });
  2. bb plugin install path:./boom-plugin (loads once, ends in error), then bb plugin disable boom-plugin.

  3. bb plugin enable boom-plugin; echo $?

Output (shape; statusDetail text depends on the thrown error):

[email protected]  error  (boom)
  source: path:...
0

bb plugin enable boom-plugin --json prints {"ok":true,"plugin":{...,"enabled":true,"status":"error",...}} and exits 0 too.

A provider plugin whose provider id is already registered by another running plugin behaves the same way; the throwing factory is just the smallest reproduction.

Why

  • apps/server/src/routes/plugins.ts:756-761 — POST /plugins/:id/enable answers { ok: true, plugin } as long as setEnabled returns a row; the response does not look at plugin.status.
  • apps/server/src/services/plugins/plugin-service.ts:1686-1718 — setEnabled runs loadOne(row) and returns list().find(...), so a failed load is reported only through status/statusDetail on the returned entry.
  • apps/cli/src/commands/plugin.ts:1600-1621 — the CLI calls exitWithError only when !result.ok || !result.plugin, then printPlugin shows the status and the command exits 0.

The neighbouring commands already fail loudly:

  • bb plugin reload returns { ok: false, error, plugins } with HTTP 422 when a plugin fails to load (plugin-service.ts:1767-1768, routes/plugins.ts:733-737), so the CLI exits 1.
  • bb plugin safe-mode off "exits 1 if any fail to start" (apps/cli/src/commands/plugin.ts:1627).

Expected

When the enable results in a load error (enabled: true and status: "error"), bb plugin enable exits non-zero and --json reports ok: false with the statusDetail as error.

Note this is narrower than "anything other than running": a plugin held back by safe mode is reported as disabled with a safe-mode detail (apps/server/src/services/plugins/plugin-runtime.ts:1541-1547), and that is a legitimate successful enable (the row is enabled; it will start when safe mode is turned off). Only status === "error" should fail the command.

Suggested direction

Either have POST /plugins/:id/enable return { ok: false, error: statusDetail, plugin } (422, like reload) when the resulting status is error, or keep the route as is and let the CLI treat plugin.enabled && plugin.status === "error" as a failure. The first option also helps bb.sdk.plugins.enable() callers, who currently have to inspect status themselves.

Related, not duplicates: #2029 (closed; reload reported exit 0 while services were orphaned), #2286 (open; plugin health counters hide failures), #2382 (open; bb status exits 0 against a dead daemon).

Activity

  1. added theissue type on Oct 5, 2026
  2. added
    plugins
    cli
    confirmed-repro
    on Oct 5, 2026
  3. bb-slop-cop commented on Oct 5, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Classification: Bug · Priority Medium · Effort Low · plugins, cli, confirmed-repro.

    Verdict: REPRODUCED, with high root-cause confidence, in two trusted-main checkouts at f7f106dab.

    Report: https://get-bb.github.io/reports/issues/4940.html

    Root cause: The enable endpoint returns a successful envelope whenever the installed plugin exists, even after its loader records an error. The CLI trusts that envelope and exits 0; the SDK also resolves with the failed plugin.

    Evidence: The authored end-to-end regression fails in both checkouts: expected CLI exit 1, received 0 in human and JSON modes. Safe-mode-held enable succeeds as intended; four existing reload/safe-mode tests pass. The report embeds the complete reproduction test.

    No PR: The root repair changes public enable API success/error semantics, which this rule excludes from its simple-fix scope.

  4. ahmedhesham6 commented on Oct 14, 2026

    @ahmedhesham6
    Contributor

    I'd like to work on this. I have a fix ready that takes the CLI-only route from the issue: when enable returns an enabled plugin with status: "error", bb plugin enable reports ok: false with statusDetail as error and exits 1. A plugin that safe mode holds back still counts as a successful enable. It's about 15 lines in apps/cli/src/commands/plugin.ts, plus a regression test that fails before the fix.

    If you'd rather fix it in the server (return 422 from the enable route, like reload does), I can do that instead. I'm asking for contributor approval in Discord before I open the PR.

  5. ahmedhesham6 commented on Oct 15, 2026

    @ahmedhesham6
    Contributor

    I opened the fix as #5534. The contributor gate may close it until I have approval. If you approve me, I'll reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliconfirmed-reproplugins

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions