Skip to content

Show stale and rate-limited usage honestly in the usage panel - #8455

Merged
ymichael merged 2 commits into
mainfrom
bb/fix-stuck-usage-percentage-thr_2nt7ewyr4q
Dec 1, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/fix-stuck-usage-percentage-thr_2nt7ewyr4q

Conversation

@ymichael

@ymichael ymichael commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Anthropic's /api/oauth/usage can answer 429 with a Retry-After for a single account. In one live case the endpoint had been returning 429 for four days. Account Pooler's Claude and Codex adapters dropped every non-OK usage response, and refreshAccountUsage ended in .catch(() => undefined), so the pool kept the last good reading and reported the account as healthy. The Provider usage panel then drew that reading as current indefinitely, including windows whose reset time had already passed. The account showed "7d 83%, resets now" for days after the limit had reset.

What changed

Account Pooler (plugins/account-pool)

  • ProviderAdapter.refreshUsage now returns { kind: "done" } | { kind: "failed"; retryAt }. A 429 records retryAt from Retry-After. Other non-OK responses, unparseable bodies and thrown errors count as failed checks.
  • The hub skips usage checks for an account until retryAt has passed. This applies to forced refreshes too, since the endpoint would refuse them anyway.
  • Until a check succeeds, the usage source reports the failure: "Anthropic is rate-limiting usage checks for this account." (or "OpenAI …"), or "Couldn’t check usage for this account." for other failures. Provider usage already shows a source error next to the cached measurement as a refresh error.

Provider usage (plugins/provider-usage, footer card and settings)

  • Windows whose resetsAt has passed are no longer drawn with their old percentage, for every usage source.
  • An account whose windows have all reset says "Limits have reset since the last update."
  • A refresh error only appends "Showing last update." when some windows are still shown.
  • New Ladle scenario "stale usage" with one account per state.

There are no wire, CLI or guide changes.

Related: #7739 covers the silent-refresh-failure part. Disabled-source handling, warn logging and per-reading age are not addressed here. #6669 is the same 429 pattern in provider-claude-code, which this PR does not touch.

How you verified

  • Reproduced live: bb pool account list --json showed the account's last observation 4 days old, with resetAt 2 days in the past. Calling /api/oauth/usage with that account's token returned 429, with Retry-After: 2977 counting down. The pool showed no error.
  • server.test.ts, "backs off usage checks the provider rate-limits and reports the failure until a check succeeds": a 429 is reported as an error, no upstream call is made before Retry-After, and the next check after it recovers. The test fails when the hub's backoff check is removed (an extra /usage call).
  • app.test.tsx gains a reset-since-update case: a window past its reset shows no percentage, and the refresh error is shown without "Showing last update."
  • Ladle ("stale usage" row in plugins--provider-usage--disclosure and --settings), rendered on main and on this branch for six states: healthy, checks failing, partly reset, fully reset, failing and reset, and no reading. On main every stale account shows its old percentages, with "now" or "Resetting now" for windows that already reset. On this branch reset windows are gone and failing checks show their reason.
  • pnpm exec turbo run typecheck lint test --filter=bb-plugin-account-pool --filter=bb-plugin-bb--provider-usage passes (406 and 26 tests).

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 2 commits November 30, 2026 18:24
Anthropic's /api/oauth/usage can answer 429 with a Retry-After for one
account. The Claude and Codex adapters discarded every non-OK usage
response without a trace, so the pool kept the last good reading and the
usage panel showed it as current indefinitely, even after the window's
reset time had passed ("83%, resets now" for days).

Account Pooler: adapters report whether a usage check failed and, for a
429, when to retry. The hub skips checks for that account until then, and
the usage source reports the failure ("Anthropic is rate-limiting usage
checks for this account.") until a check succeeds, so the panel shows the
reason next to the last update instead of presenting it as fresh.

Provider usage panel and settings: windows whose reset time has passed are
no longer drawn with their old percentage, for every usage source. An
account whose windows have all reset says "Limits have reset since the
last update." and a refresh error only claims "Showing last update." when
there is still something shown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit a625bfb into main Dec 1, 2026
35 checks passed
@ymichael
ymichael deleted the bb/fix-stuck-usage-percentage-thr_2nt7ewyr4q branch December 1, 2026 04:33
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
…#8455)

## Human comments

## What was wrong

Anthropic's `/api/oauth/usage` can answer `429` with a `Retry-After` for
a single account. In one live case the endpoint had been returning 429
for four days. Account Pooler's Claude and Codex adapters dropped every
non-OK usage response, and `refreshAccountUsage` ended in `.catch(() =>
undefined)`, so the pool kept the last good reading and reported the
account as healthy. The Provider usage panel then drew that reading as
current indefinitely, including windows whose reset time had already
passed. The account showed "7d 83%, resets now" for days after the limit
had reset.

## What changed

**Account Pooler** (`plugins/account-pool`)
- `ProviderAdapter.refreshUsage` now returns `{ kind: "done" } | { kind:
"failed"; retryAt }`. A 429 records `retryAt` from `Retry-After`. Other
non-OK responses, unparseable bodies and thrown errors count as failed
checks.
- The hub skips usage checks for an account until `retryAt` has passed.
This applies to forced refreshes too, since the endpoint would refuse
them anyway.
- Until a check succeeds, the usage source reports the failure:
"Anthropic is rate-limiting usage checks for this account." (or "OpenAI
…"), or "Couldn’t check usage for this account." for other failures.
Provider usage already shows a source error next to the cached
measurement as a refresh error.

**Provider usage** (`plugins/provider-usage`, footer card and settings)
- Windows whose `resetsAt` has passed are no longer drawn with their old
percentage, for every usage source.
- An account whose windows have all reset says "Limits have reset since
the last update."
- A refresh error only appends "Showing last update." when some windows
are still shown.
- New Ladle scenario "stale usage" with one account per state.

There are no wire, CLI or guide changes.

Related: get-bb#7739 covers the silent-refresh-failure part. Disabled-source
handling, warn logging and per-reading age are not addressed here. get-bb#6669
is the same 429 pattern in `provider-claude-code`, which this PR does
not touch.

## How you verified

- Reproduced live: `bb pool account list --json` showed the account's
last observation 4 days old, with `resetAt` 2 days in the past. Calling
`/api/oauth/usage` with that account's token returned `429`, with
`Retry-After: 2977` counting down. The pool showed no error.
- `server.test.ts`, "backs off usage checks the provider rate-limits and
reports the failure until a check succeeds": a 429 is reported as an
error, no upstream call is made before `Retry-After`, and the next check
after it recovers. The test fails when the hub's backoff check is
removed (an extra `/usage` call).
- `app.test.tsx` gains a `reset-since-update` case: a window past its
reset shows no percentage, and the refresh error is shown without
"Showing last update."
- Ladle ("stale usage" row in `plugins--provider-usage--disclosure` and
`--settings`), rendered on main and on this branch for six states:
healthy, checks failing, partly reset, fully reset, failing and reset,
and no reading. On main every stale account shows its old percentages,
with "now" or "Resetting now" for windows that already reset. On this
branch reset windows are gone and failing checks show their reason.
- `pnpm exec turbo run typecheck lint test
--filter=bb-plugin-account-pool --filter=bb-plugin-bb--provider-usage`
passes (406 and 26 tests).

> 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