Skip to content

Retry structured provider overload failures - #2801

Merged
ymichael merged 1 commit into
mainfrom
bb/assess-provider-overload-retryability-thr_6iptthdyda
Sep 1, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/assess-provider-overload-retryability-thr_6iptthdyda

Conversation

@ymichael

@ymichael ymichael commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The provider-retry policy treated every structured failure other than a resettable subscription rate limit as ineligible. Structured overloaded failures are transient and retryable, but the plugin had no independent delay policy for failures that do not report a rate-limit reset window.

What changed

The retry policy now schedules overloaded failures with exponential backoff and bounded jitter: 5–10 seconds, 10–20 seconds, 20–40 seconds, then 40–80 seconds. Overload recovery shares the existing five-total-attempt cap, identifies queued work as Provider overloaded, and continues to delegate accepted-versus-unaccepted input handling to core through threads.retry. Subscription-window behavior is unchanged. Plugin metadata, CLI wording, configuration documentation, and the generated BB guide sources now describe both recovery modes. There are no host-daemon protocol or wire changes.

How you verified

The new overload policy and plugin-handler tests fail against the previous implementation because it declines the overloaded category. Verification commands:

  • pnpm exec turbo run test typecheck --filter=bb-plugin-provider-retry --force — 15 tests passed and typecheck passed
  • pnpm exec turbo run test --filter=@bb/server --force -- --run test/threads/turn-failed-retry.test.ts — 12 tests passed
  • pnpm exec turbo run test --filter=@bb/server --force -- --run test/services/plugins/plugin-authoring-docs.test.ts test/services/plugins/builtin-plugins.test.ts — 47 tests passed
  • bb plugin build plugins/provider-retry
  • git diff --check

Fixes # (no tracking issue was filed)

AGENT GENERATED

@ymichael

ymichael commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

@slopcop

@bb-slop-cop

bb-slop-cop Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am the Slop Cop. I am reviewing this pull request now.

I will check security, code quality, performance, architecture, duplication, and the full user flow.

I will post one final review after the parallel checks finish.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Plain-English summary: This change lets BB retry a failed turn when Codex or Claude reports a structured provider overload.

BB waits 5–10 seconds before the first retry. It doubles later delays and stops after five total attempts.

I found no blocking issues.

  • Security: The change uses parsed error categories, keeps a fixed public reason, and preserves the existing retry and queue limits.
  • Code quality: The policy, server action, tests, CLI text, and documentation agree.
  • Architecture: The Workflows plugin has a separate retry path for child calls. A shared refactor would not improve this change.
  • Performance: The extra retry layer and per-thread jitter are bounded parts of the stated policy. They do not show a concrete regression.
  • Product test: This server plugin has no browser route. The plugin harness is the correct full-path test, so doobie does not apply.

I verified the exact head SHA. The plugin test passed all 15 tests, and git diff --check passed.

All required GitHub package, server, app, integration, and smoke checks also passed.

@ymichael
ymichael merged commit d33caab into main Sep 1, 2026
15 checks passed
@ymichael
ymichael deleted the bb/assess-provider-overload-retryability-thr_6iptthdyda branch September 1, 2026 17:26
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]>
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.

1 participant