Skip to content

Retry turns that fail on provider server and connection errors - #5931

Merged
ymichael merged 1 commit into
mainfrom
bb/reproduce-and-analyze-github-issue-4839-thr_zrdzsq2xsj
Oct 20, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/reproduce-and-analyze-github-issue-4839-thr_zrdzsq2xsj

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

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 provider-retry never retries Account Pooler 429/502 failures #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 Fix provider retries for exhausted account pools #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

Provider retry only scheduled retries for overloads and rate limits, so a
turn that failed because the provider or Account Pooler was unreachable
(HTTP 500/502/503/504, internal, connection-failed, stream-disconnected)
stayed in error until someone sent a new message. These failures now
retry with exponential backoff starting at one minute, sharing the
existing five-attempt cap. Unauthorized and other non-transient failures
are still declined.

Refs #4839

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

provider-retry never retries Account Pooler 429/502 failures

1 participant