Skip to content

fix(cli): retry the plugin CLI probe instead of declaring bb down - #1313

Merged
ymichael merged 2 commits into
get-bb:mainfrom
MGrin:fix/plugin-cli-probe-retry
Aug 13, 2026
Merged

ymichael merged 2 commits into
get-bb:mainfrom
MGrin:fix/plugin-cli-probe-retry

Conversation

@MGrin

@MGrin MGrin commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

The bug

Every plugin-contributed command (bb memory add, bb tasks ..., bb automation ...) is gated by a single GET /api/v1/plugins/contributions probe in tryPluginCommandProxy, with a 2000ms AbortSignal.timeout and no retry. Any thrown error collapses into outcome: "unreachable" and the CLI exits 1 — the user's command never runs.

That window is too tight to be used as a liveness signal. Measured against a running 0.36.0 server on an ordinarily busy machine (load average ~23, a monorepo test suite plus dev servers):

latency
p50 1.9 ms
p90 130 ms
p99 1.24 s
max (200 samples) >2000 ms — 1 request timed out

The distribution is sharply bimodal: nearly every request is single-digit milliseconds, and a few block for hundreds of ms to seconds behind the server's event loop. So ~0.5% of plugin command invocations failed while bb was up and healthy, and the rate climbs with machine load. It reproduced repeatedly on one machine on a single day.

Why it matters more than the wording suggests

The reader of this message is usually an agent. bb isn't running — open the bb app, then re-run this command. describes a state that only a human can clear, so agents did not retry — they recorded the write as impossible and moved on. In one observed transcript the agent replied "bb isn't running, so I'll circle back on that once it's up" and never did. Memory writes and task updates were silently dropped while the daemon was running the whole time.

describeUnreachableServer already distinguished refused / blocked / timed out, which fixed the wording for a timeout. But the invocation still failed, so the work was still lost.

The fix

Retry the probe on causes that mean the server exists but did not answer in time — TimeoutError/AbortError and the reset family (ECONNRESET, EPIPE, ETIMEDOUT, UND_ERR_*). Windows escalate 2000 / 4000 / 4000 ms with 150 ms and 500 ms backoff, so a server stalled mid-GC gets room to finish rather than re-hitting the same block. Worst case is bounded at ~10.6s, and only on the path that previously lost the command outright.

Two causes still fail on the first attempt, because waiting cannot change either:

  • ECONNREFUSED — nothing is listening, bb really is down; retrying would only delay a correct, actionable answer.
  • EPERM / EACCES — a sandbox or firewall is blocking this shell.

The cause-chain walk moved out of describeUnreachableServer into diagnoseUnreachableServer, so the retry decision and the message are derived from one classification and cannot drift apart.

A timeout now reads:

bb did not respond at http://127.0.0.1:38886 after 3 attempts (last window 4000ms) — bb is running but too busy to answer. Nothing was rejected and your command did not run; re-run it.

It names the state (up, busy), rules out rejection, and says the command did not run — so an agent retries instead of giving up.

Notes for review

  • The pre-flight probe was strictly more fragile than the work it guarded: runPluginCliCommand (the actual POST .../cli) has no timeout at all. A 2s gate was rejecting commands that are themselves allowed to run unbounded. I left that asymmetry alone rather than widen the scope — worth a separate look.
  • An alternative fix is to make the contributions route cheap enough that 2s is never in question. That is the better long-term answer, but it does not help a CLI talking to an older or loaded server, and the retry is useful regardless.

Verification

  • pnpm --filter @bb/cli test — 399 tests across 46 files pass.
  • tsc --noEmit clean; prettier applied.
  • The three new retry tests were confirmed to fail with the retry schedule reduced to a single attempt, so they pin the regression rather than passing vacuously.

🤖 Generated with Claude Code

Every plugin-contributed command (`bb memory add`, `bb tasks ...`) is gated
by one GET /api/v1/plugins/contributions probe with a 2000ms
AbortSignal.timeout and no retry. Any thrown error collapsed into
`outcome: "unreachable"`, so a single slow response failed the whole
invocation and the command never ran.

That window is too tight to be a liveness signal. Measured against a
running 0.36.0 server on an ordinarily busy machine (load ~23), the
endpoint's latency is sharply bimodal: p50 1.9ms but p99 1.24s, with
1 request in 200 exceeding 2000ms. So roughly 0.5% of plugin command
invocations failed while bb was up and healthy, and the rate climbs with
machine load.

The cost is worse than the wording suggests. The reader is usually an
agent, and "bb isn't running — open the bb app" describes a state only a
human can clear, so agents abandoned the write rather than retrying it —
memory writes and task updates were silently dropped.

Retry the probe on causes that mean "the server exists but did not answer
in time" (timeout, ECONNRESET and friends), escalating the window
2000/4000/4000ms with 150ms and 500ms backoff. ECONNREFUSED and
EPERM/EACCES still fail on the first attempt: nothing is listening, or a
sandbox is blocking the shell, and waiting cannot change either.

The cause-chain walk moves into `diagnoseUnreachableServer` so the retry
decision and the message are derived from one classification and cannot
drift apart. A timeout now reports that bb is up but busy and that the
command did not run, so re-running it is the fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
@ymichael ymichael self-assigned this Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants