Reports

#6239 · Plugin proxy shutdown verification

BugHighEffort: LowclipluginsIssue2026-10-24

Trusted base: 9eb0c09254a21482c0cfd935e0a9908049333e93.

Verdict: NOT REPRODUCED on the available Linux host. Root-cause confidence: low for the Windows native assertion; high for the verified CLI request and shutdown path.

1. TL;DR

The report describes a Windows-only abort after otherwise complete plugin CLI output. Trusted main still fetches plugin contributions, executes the matching command, and forcibly exits with its returned status. A new repository-derived fixture exercised this exact entrypoint with compressed discovery and an uncompressed command result, plus uncompressed-discovery and explicit-command controls. All 60 child processes in each of two clean checkouts returned the intended status and complete output on Linux. This does not refute the Windows report: Windows and the reported affected Node runtime are unavailable, so neither the native assertion nor the runtime-version workaround is independently verified. No production change or pull request was made.

2. Claims vs findings

ClaimFindingEvidence
Top-level plugin dispatch performs discovery followed by command execution.VerifiedReal CLI subprocesses made GET contributions followed by POST command in both checkouts.
Discovery can be compressed while the command response is plain.Verified as an eligible server behavior and fixture conditionServer JSON compression uses a 1,024-byte threshold. The fixture sends a 2,570-byte discovery body with gzip and a smaller plain result. No full application server was launched.
Top-level dispatch ends with a forced process exit.Verified in trusted sourceEntrypoint awaits the plugin result and invokes process.exit(exitCode).
Windows aborts after output; upstream native scheduling is responsible.UnverifiedLinux x64, Node v22.19.0: zero aborts across 120 subprocesses. No Windows runtime or compatibility layer is available.
A newer Node release or natural exit avoids the Windows assertion.UnverifiedNo affected/fixed Windows runtime pair was available. No upstream links or issue scripts were fetched or run.
The explicit command path makes just one command request.VerifiedExplicit plugin-run controls made only POST command, with no discovery request.

3. Environment

4. Minimal reproduction

Save the full probe below as proxy-exit-probe.mjs outside the checkout. It is newly authored from trusted CLI code and existing fixture tests, not copied from the issue. It starts only a local HTTP fixture and launches the built trusted CLI. It requires the selected port to be free; binding fails instead of using another instance.

WORK=$(mktemp -d)
git clone --branch main https://github.com/get-bb/bb.git "$WORK/base"
git -C "$WORK/base" checkout --detach 9eb0c09254a21482c0cfd935e0a9908049333e93
cd "$WORK/base"
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@bb/cli
node /path/to/proxy-exit-probe.mjs "$WORK/base" 49139

Expected: every success returns 0, every fixture failure returns 7, complete stdout/stderr, no signal or assertion. The fixture uses a synthetic nonzero result to test status propagation without relying on a plugin's error-message contract. Actual first run:

platform=linux arch=x64 node=v22.19.0
fixture contribution bytes=2570
proxy gzip expected=0: exit mismatches=0/10 assertions=0/10
  actual=0 signal=null stdout="fixture completed\n" stderr=""
  requests: GET /api/v1/plugins/contributions response=gzip -> POST /api/v1/plugins/fixture/cli response=identity
proxy gzip expected=7: exit mismatches=0/10 assertions=0/10
  actual=7 signal=null stdout="fixture completed\n" stderr="fixture returned failure\n"
  requests: GET /api/v1/plugins/contributions response=gzip -> POST /api/v1/plugins/fixture/cli response=identity
proxy identity expected=0: exit mismatches=0/10 assertions=0/10
  actual=0 signal=null stdout="fixture completed\n" stderr=""
  requests: GET /api/v1/plugins/contributions response=identity -> POST /api/v1/plugins/fixture/cli response=identity
proxy identity expected=7: exit mismatches=0/10 assertions=0/10
  actual=7 signal=null stdout="fixture completed\n" stderr="fixture returned failure\n"
  requests: GET /api/v1/plugins/contributions response=identity -> POST /api/v1/plugins/fixture/cli response=identity
direct identity expected=0: exit mismatches=0/10 assertions=0/10
  actual=0 signal=null stdout="fixture completed\n" stderr=""
  requests: POST /api/v1/plugins/fixture/cli response=identity
direct identity expected=7: exit mismatches=0/10 assertions=0/10
  actual=7 signal=null stdout="fixture completed\n" stderr="fixture returned failure\n"
  requests: POST /api/v1/plugins/fixture/cli response=identity
Complete repeatable probe source
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
import { mkdtemp, rm } from "node:fs/promises";
import { createServer } from "node:http";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { gzipSync } from "node:zlib";

const checkout = resolve(process.argv[2]);
const port = Number(process.argv[3]);
assert(Number.isInteger(port) && port >= 40000 && port <= 60000);
const dataDir = await mkdtemp(join(tmpdir(), "bb-proxy-probe-"));
const baseUrl = `http://127.0.0.1:${port}`;
const fixture = {
  cliCommands: [{
    pluginId: "fixture",
    name: "fixture",
    summary: "Plugin fixture ".repeat(160),
    commands: [{ name: "execute", summary: "Execute", usage: "bb fixture execute" }],
    rendersHelp: true,
  }],
};
let encoding = "gzip";
let expectedExitCode = 0;
let requests = [];
const server = createServer((request, response) => {
  request.resume();
  response.setHeader("content-type", "application/json");
  if (request.url === "/api/v1/plugins/contributions") {
    requests.push(`${request.method} ${request.url} response=${encoding}`);
    const bytes = Buffer.from(JSON.stringify(fixture));
    if (encoding === "gzip") {
      response.setHeader("content-encoding", "gzip");
      response.end(gzipSync(bytes));
    } else {
      response.end(bytes);
    }
    return;
  }
  if (request.url === "/api/v1/plugins/fixture/cli") {
    requests.push(`${request.method} ${request.url} response=identity`);
    response.end(JSON.stringify({
      exitCode: expectedExitCode,
      stdout: "fixture completed\n",
      stderr: expectedExitCode === 0 ? "" : "fixture returned failure\n",
    }));
    return;
  }
  requests.push(`unexpected ${request.method} ${request.url}`);
  response.writeHead(404).end("{}");
});

function invoke(direct) {
  return new Promise((resolveResult, rejectResult) => {
    const args = direct ? ["plugin", "run", "fixture", "execute"] : ["fixture", "execute"];
    const child = spawn(process.execPath, [join(checkout, "apps/cli/dist/index.js"), ...args], {
      cwd: checkout,
      env: {
        PATH: process.env.PATH,
        HOME: dataDir,
        USERPROFILE: dataDir,
        BB_DATA_DIR: dataDir,
        BB_SERVER_URL: baseUrl,
        BB_CLI_REEXEC: "1",
        NO_COLOR: "1",
      },
      stdio: ["ignore", "pipe", "pipe"],
    });
    let stdout = "";
    let stderr = "";
    let timedOut = false;
    const timer = setTimeout(() => {
      timedOut = true;
      child.kill();
    }, 15000);
    child.stdout.setEncoding("utf8").on("data", (chunk) => { stdout += chunk; });
    child.stderr.setEncoding("utf8").on("data", (chunk) => { stderr += chunk; });
    child.on("error", (error) => {
      clearTimeout(timer);
      rejectResult(error);
    });
    child.on("close", (code, signal) => {
      clearTimeout(timer);
      resolveResult({ code, signal, stdout, stderr, timedOut });
    });
  });
}

try {
  await new Promise((resolveReady, rejectReady) => {
    server.once("error", rejectReady);
    server.listen(port, "127.0.0.1", resolveReady);
  });
  console.log(`platform=${process.platform} arch=${process.arch} node=${process.version}`);
  console.log(`fixture contribution bytes=${Buffer.byteLength(JSON.stringify(fixture))}`);
  for (const direct of [false, true]) {
    for (encoding of direct ? ["identity"] : ["gzip", "identity"]) {
      for (expectedExitCode of [0, 7]) {
        let mismatches = 0;
        let assertions = 0;
        let lastResult;
        for (let attempt = 0; attempt < 10; attempt += 1) {
          requests = [];
          lastResult = await invoke(direct);
          if (lastResult.stderr.includes("UV_HANDLE_CLOSING")) assertions += 1;
          if (lastResult.code !== expectedExitCode || lastResult.signal !== null || lastResult.timedOut) {
            mismatches += 1;
          }
          assert.equal(lastResult.stdout, "fixture completed\n");
          assert.equal(lastResult.stderr, expectedExitCode === 0 ? "" : "fixture returned failure\n");
          assert.deepEqual(requests, [
            ...direct ? [] : [`GET /api/v1/plugins/contributions response=${encoding}`],
            "POST /api/v1/plugins/fixture/cli response=identity",
          ]);
        }
        console.log(`${direct ? "direct" : "proxy"} ${encoding} expected=${expectedExitCode}: exit mismatches=${mismatches}/10 assertions=${assertions}/10`);
        console.log(`  actual=${lastResult.code} signal=${lastResult.signal} stdout=${JSON.stringify(lastResult.stdout)} stderr=${JSON.stringify(lastResult.stderr)}`);
        console.log(`  requests: ${requests.join(" -> ")}`);
      }
    }
  }
} finally {
  server.closeAllConnections();
  await new Promise((resolveClosed) => server.close(resolveClosed));
  await rm(dataDir, { recursive: true, force: true });
}

The probe asserts exact stdout, stderr, and request order. It records status mismatches and native-assertion counts rather than pretending their absence proves the Windows case. The script is retained locally; the public report is self-contained and publishes no separate scripts or logs.

5. Root cause: confirmed boundary, unverified native mechanism

Contribution discovery fetches and decodes the contributions response. Command execution posts the invocation and decodes the command response. Top-level dispatch awaits that work, logs a nonzero result when needed, then calls:

process.exit(exitCode);

Server compression supports gzip above the minimum JSON size, and selects compression using the request's accepted encoding. This makes compressed discovery followed by a smaller plain command result a faithful condition, not a guarantee for every server response. Explicit plugin run also forces exit but skips discovery. Thus a fix that blames process.exit alone without accounting for request/decompression state would overstate the evidence.

Confirmed: BB forces shutdown after decoding network responses. Candidate native trigger: forced shutdown while runtime work associated with decompression remains pending. The assertion and the alleged upstream scheduling race were not observed here; their exact mechanism and Node-version thresholds remain unverified. A forced exit is not by itself evidence of a native runtime defect on this host.

6. Proposed fix or next experiment

Run this probe against the same trusted base on Windows with an affected runtime, then repeat on the claimed fixed runtime. If the assertion reproduces, write a focused failing test at the CLI process boundary before changing production code. A natural-exit approach would need to set the exit status, return a handled result to the main dispatcher, avoid falling through into Commander, and preserve no-match fallback, help, failed-command logging, and output errors. Verify that open dispatchers do not keep the CLI alive.

No fix was attempted: the required pre-fix regression failure was not demonstrated on trusted main. A plausible small edit is not enough to satisfy the autopilot's safety gate. No linked open pull request was found in issue cross-reference metadata; a search false positive was checked and did not close this issue.

7. Verification

The same agent repeated the entire fixture in a second clean detached worktree at 9eb0c09254a21482c0cfd935e0a9908049333e93, with a fresh install, a Turbo CLI build, new port 49140, and a new temporary data directory. Both worktrees had clean tracked status after the runs. Command: node /path/to/proxy-exit-probe.mjs /path/to/second-clean-checkout 49140. This is repeat verification by the same agent, not independent verification.

platform=linux arch=x64 node=v22.19.0
fixture contribution bytes=2570
proxy gzip expected=0: exit mismatches=0/10 assertions=0/10
  actual=0 signal=null stdout="fixture completed\n" stderr=""
  requests: GET /api/v1/plugins/contributions response=gzip -> POST /api/v1/plugins/fixture/cli response=identity
proxy gzip expected=7: exit mismatches=0/10 assertions=0/10
  actual=7 signal=null stdout="fixture completed\n" stderr="fixture returned failure\n"
  requests: GET /api/v1/plugins/contributions response=gzip -> POST /api/v1/plugins/fixture/cli response=identity
proxy identity expected=0: exit mismatches=0/10 assertions=0/10
  actual=0 signal=null stdout="fixture completed\n" stderr=""
  requests: GET /api/v1/plugins/contributions response=identity -> POST /api/v1/plugins/fixture/cli response=identity
proxy identity expected=7: exit mismatches=0/10 assertions=0/10
  actual=7 signal=null stdout="fixture completed\n" stderr="fixture returned failure\n"
  requests: GET /api/v1/plugins/contributions response=identity -> POST /api/v1/plugins/fixture/cli response=identity
direct identity expected=0: exit mismatches=0/10 assertions=0/10
  actual=0 signal=null stdout="fixture completed\n" stderr=""
  requests: POST /api/v1/plugins/fixture/cli response=identity
direct identity expected=7: exit mismatches=0/10 assertions=0/10
  actual=7 signal=null stdout="fixture completed\n" stderr="fixture returned failure\n"
  requests: POST /api/v1/plugins/fixture/cli response=identity

Result: identical output and 60/60 correct statuses in the second checkout. No correction to the first run was necessary. Both fixture listeners closed, temporary data directories were removed, and fresh bind checks confirmed both ports were free.

8. Related issues

No related issue was independently evaluated. Issue-supplied links, scripts, and upstream-fix claims were treated as untrusted evidence, not execution instructions.

9. Appendix: build and test evidence

The initial whole-workspace pnpm exec turbo run build failed in the unrelated GitHub plugin while its SDK host entry was not yet built. No source was changed to repair that failure. Focused pnpm exec turbo run build --filter=@bb/cli then passed: 5 successful tasks in each checkout (second checkout fully cached).

pnpm exec turbo run test --filter=@bb/cli -- --run src/__tests__/plugin-cli-proxy.test.ts src/__tests__/plugin-cli-broken-pipe.e2e.test.ts src/__tests__/cli-entry-errors.e2e.test.ts
Test Files  3 passed (3)
Tests       54 passed (54)
Tasks       6 successful, 6 total

Investigation commands also read repository visibility, issue comments, built-in field options, labels, and open pull-request cross-reference metadata; fetched origin/main; created two clean worktrees; checked source line links at the pinned commit; checked tracked status; and verified the fixture ports were released. No issue-provided program, patch, branch, command line, binary, or external URL was executed or fetched.

Classification: Bug / High / Low; labels cli and plugins. High follows the triage rule that any crash has at least High priority; Low effort describes the likely contained CLI change, not proof that a fix is safe.

> AGENT GENERATED