Repository navigation
fix(cli): retry the plugin CLI probe instead of declaring bb down - #1313
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Every plugin-contributed command (
bb memory add,bb tasks ...,bb automation ...) is gated by a singleGET /api/v1/plugins/contributionsprobe intryPluginCommandProxy, with a 2000msAbortSignal.timeoutand no retry. Any thrown error collapses intooutcome: "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):
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.describeUnreachableServeralready 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/AbortErrorand 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
describeUnreachableServerintodiagnoseUnreachableServer, so the retry decision and the message are derived from one classification and cannot drift apart.A timeout now reads:
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
runPluginCliCommand(the actualPOST .../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.Verification
pnpm --filter @bb/cli test— 399 tests across 46 files pass.tsc --noEmitclean; prettier applied.🤖 Generated with Claude Code