Skip to content

Clear stale Claude rate-limit windows and allow usage refresh while busy - #8541

Open
lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:lanjak/fix-7418-clear-stale-5h-window-in-account-pooler-thr_nx7pdxca2x
Open

lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:lanjak/fix-7418-clear-stale-5h-window-in-account-pooler-thr_nx7pdxca2x

Conversation

@lanjak

@lanjak lanjak commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

Account Pooler kept a stale 5-hour window for a Claude account after Anthropic stopped reporting one for as long as the account stayed busy:

  1. windowFromHeaders (quota.ts#L81) returned prior whenever a window's utilization, resetAt, and status headers were all absent, even when Anthropic returned other anthropic-ratelimit-unified-* headers without 5h-*.
  2. refreshAccountUsage (hub.ts#L375) exited early whenever inFlightByAccount was non-zero, so periodic and manual usage refreshes skipped accounts with active streams.

Investigation report: https://get-bb.github.io/reports/issues/7418.html

What changed

  • plugins/account-pool/src/quota.ts: added hasUnifiedRateLimitHeaders(headers) (true when any header name starts with anthropic-ratelimit-unified-). When true, omitted window slots return null (clearing stale windows) and observedAt updates to now; when false (errors or non-rate-limit responses), prior windows and observedAt are preserved unchanged.
  • plugins/account-pool/src/hub.ts: removed the inFlightByAccount early return in refreshAccountUsage (token refresh deduplication and QuotaStore.put already handle concurrent requests).
  • Docs: none updated; no guide or doc describes internal Account Pooler header-merge or refresh gating.

No wire change and no schema change.

How you verified

Base commit: origin/main 4d7a9af609.

Case Before (origin/main) After (89d81dccea)
Response with anthropic-ratelimit-unified-* headers omitting 5h-* Carries stale 5h window forward Drops stale 5h window
Response with no unified rate-limit headers Preserves existing windows Preserves existing windows (unchanged)
Usage refresh while streaming /v1/messages is in flight Skipped (inFlightByAccount > 0) Runs refresh and drops stale 5h window

Tests added in plugins/account-pool/src/quota.test.ts and src/server.test.ts (3 new cases failed before the fix; all 4 targeted cases pass after).

CI parity command:
pnpm exec turbo run typecheck test lint lint:type-aware --filter=bb-plugin-account-pool --continue

  • typecheck, lint, lint:type-aware: 0 errors.
  • test: 14/15 files passed (all 375 tests in src/*.test.ts; app.test.tsx hits local Node 26 window.localStorage shadowing).

Fixes #7418

AGENT GENERATED

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant