Repository navigation
Fix provider retries for exhausted account pools - #5283
Merged
Merged
Conversation
stephendolan
added a commit
to stephendolan/bb
that referenced
this pull request
Oct 13, 2026
Incorporate upstream get-bb#5130, get-bb#5226, get-bb#5283 and settings/clipboard fixes. Keep retry availability scoped to durable conversation assignments, including parent pools and spend-control recovery. Build the managed package against BB 0.46.0 SDK 0.6.37.
ymichael
added a commit
that referenced
this pull request
Oct 20, 2026
## Human comments
## What was wrong
Provider retry only scheduled retries for two kinds of failure:
structured overloads (529) and rate limits. Every other failure was
declined as `not-retryable`. When the Account Pooler, or the provider
itself, briefly cannot be reached, Claude Code records the failure as
`{category: "internal", httpStatusCode: 502}` and Codex records
`{category: "stream-disconnected", httpStatusCode: 502}`. Neither
matched, so the thread stayed in `error` until someone sent a new
message. The 429 half of #4839 was already fixed by #5283; this PR
covers the 502/503 half. Nothing in the history shows 5xx failures being
excluded on purpose: #1027 scoped the plugin to subscription limits, and
#2801 added only `overloaded`.
## What changed
- `plugins/provider-retry/src/retry-policy.ts`: a failure counts as
"provider unavailable" when its HTTP status is 500, 502, 503 or 504, or
its category is `internal`, `connection-failed` or
`stream-disconnected`. Such failures are retried for every thread,
pooled or not, with exponential backoff that starts at 1 minute: 1–2,
2–4, 4–8 and 8–16 minutes with jitter. They share the existing 5-attempt
cap, and the queue card shows "Provider unavailable". Overload timing is
unchanged; the backoff helper now takes a base delay. Rate-limit
failures keep their existing handling. `unauthorized` (401) and other
permanent failures are still declined.
- The longer base delay is deliberate. Providers already retry 5xx
errors internally for a few minutes, so the 5-second overload backoff
would use up the attempt cap during an outage like the 30-minute one
reported in #4839.
- Docs: the provider-retry overview, skill and package description, plus
the `bb guide plugins` and `bb guide providers` templates.
- No server/daemon wire change, CLI change or protocol bump.
## How you verified
- **Production evidence (from a local bb.db):**
- Pooler 502s on 2026-09-23 were recorded with exactly the `errorInfo`
shapes above.
- Each affected thread sat idle about 20 minutes, until a manual send.
- The 429 wave on 2026-10-20 was retried automatically, confirming #5283
works.
- **Regression tests (`plugins/provider-retry/server.test.ts`):**
- Policy cases built from the recorded shapes: Claude Code pooler 502,
Codex stream-disconnected 502, Codex too-many-failed-attempts 503, and a
connection failure.
- One plugin-level case that queues a "Provider unavailable" retry.
- All 5 new tests fail against the previous policy and pass with this
change.
- The existing decline test used a 500 as its example of a permanent
failure; it now uses a 401.
- **Commands:**
- `pnpm exec turbo run test typecheck lint
--filter=bb-plugin-provider-retry --filter=@bb/templates`: 26 and 46
tests pass.
- `pnpm exec turbo run test --filter=@bb/server --
test/threads/turn-failed-retry.test.ts
test/services/plugins/plugin-authoring-docs.test.ts
test/services/plugins/builtin-plugins.test.ts`: 60 tests pass.
- `pnpm exec turbo run test typecheck --filter=@bb/plugin-registry
--filter=@bb/bundled-plugins`: pass.
- `oxfmt --check` is clean.
- **Live test (`pnpm start:worktree`):**
- Claude Code was routed through a local proxy that returns the pooler's
exact "502 Account Pooler could not reach Anthropic." response.
- The follow-up turn failed and a "Provider unavailable · attempt 2"
retry was queued about 90 s later.
- Attempt 2 failed while the outage was still on, and attempt 3 was
queued about 4 minutes later.
- After the outage ended, attempt 3 ran on its own and the agent
replied.
- A 401 from the same proxy was recorded as `Skipped: not-retryable`.
Fixes #4839
> AGENT GENERATED
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Oct 23, 2026
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.
Human comments
What was wrong
Account Pooler could reject an exhausted pool with HTTP 429 while Provider Retry received no structured subscription-window snapshot. The pool knew when an account would become usable, but the retry policy silently declined the failed turn. Live verification also found that Codex wraps exhausted native retries as
too-many-failed-attemptswhile retaining HTTP status 429, which the category-only check missed.What changed
provider-retry.v1.availabilityRPC for a failed thread/request. It verifies the recorded route and latest request, uses that request's model, and returns ready, blocked with a recovery timestamp, unavailable with a reason, or not-routed.decision.getandbb provider-retry explain [thread-id] [--json], with CLI guide and skill updates. Diagnostics describe historical decisions;statusremains the current queue view.No server/daemon wire changes or protocol version bump. No backfill of previously failed turns. The availability contract assumes one routing owner per thread; the first applicable source wins.
How you verified
pnpm exec turbo run test typecheck lint --filter=bb-plugin-account-pool --filter=bb-plugin-provider-retry: 356 Account Pooler tests and 20 Provider Retry tests passed. After the live Codex discovery, reran Provider Retry's tests/typecheck/lint: all 21 tests passed. Account Pooler lint has two existing React warnings and no errors.pnpm exec turbo run test --filter=@bb/server -- test/threads/turn-failed-retry.test.ts: all 13 tests passed, including a real database integration that queues a durable retry without a provider quota event. Confirmed the regression fails against the old retry handler because no row is queued.pnpm exec turbo run typecheck lint --filter=@bb/serverpassed.git diff --checkpassed.pnpm start:worktreeand ran real Claude Code and Codex clients through controlled HTTP 429 injection. Claude queued a retry without a provider quota event, and the queue survived a server restart; successful Claude completion remains unverified because the real account was exhausted.CODEX_DURABLE_RETRY_OK; the thread became idle and its retry queue emptied. Verified the queue card and completed response in the browser, including after reload.