Skip to content

Report failed Account Pooler usage refreshes instead of keeping old readings silently - #7852

Open
lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:fix-7739-pool-usage-refresh-failures
Open

lanjak wants to merge 1 commit into
get-bb:mainfrom
lanjak:fix-7739-pool-usage-refresh-failures

Conversation

@lanjak

@lanjak lanjak commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Human comments

What was wrong

An Account Pooler usage refresh that failed looked like a success. The Claude adapter cancelled the body of a non-OK response and returned, turned a JSON parse failure into null, and ignored a payload that produced no quota (claude-adapter.ts#L108-L156). The Codex adapter returned early in the same cases. The hub then swallowed anything that was thrown, such as a network error, with .catch(() => undefined) (hub.ts#L369-L389). So the usage source still had a stored observation and no account error, and returned status: "ok" with the old windows. Provider usage showed them as current, and plugin.log had nothing (#7739).

What changed

  • claude-adapter.ts, codex-adapter.ts: refreshUsage rejects when the usage request fails, with the usage endpoint returned HTTP <status> or the usage response could not be read. A network error propagates as before. A valid response with no usage data ({}) is not a failure, because there is nothing to update. The Claude account-UUID lookup still runs after a failed usage request.
  • hub.ts: refreshAccountUsage records the latest failure per account and clears it on the next successful refresh. It reports a failure through a new onUsageRefreshFailed callback only when the reason changes, so a persistent 401 logs once instead of every 5 minutes. server.ts logs it as Account Pooler <provider> account <id> usage refresh failed: <reason>.
  • usage-source.ts: an account with a recorded failure reports status: "error" with Usage could not be refreshed: <reason>. and keeps its observedAt. Provider usage already handles this state: it keeps the last reading on that account's row and shows the message followed by "Showing last update.". No Provider usage change.
  • The failure is not stored as quota.error. That field makes accountStatus return error and takes the account out of routing, and a failing usage endpoint does not make the account unusable.
  • cli.ts, operations.ts: bb pool account refresh <id> fails with usage_refresh_failed when the forced refresh fails, instead of printing "Refreshed usage". The plugin skill reference documents this.

Deviations from the issue:

  • Reading age: showing "checked 14:02" needs observedAt carried through Provider usage's snapshot schema and UI. That is a separate change, not made here.
  • Disabled source: the bot report could not reproduce readings that persist after the plugin is disabled on main. Nothing changed for that.
  • Busy accounts: usage refresh is still skipped while an account has a request in flight. Open PR Allow usage refreshes while pooled accounts are streaming #7419 changes that.

How you verified

  • New server.test.ts cases through the real plugin entry and its usage RPC:
    • Claude: 401, 429, a malformed payload and a network error. Codex: 503 and a malformed payload.
    • Each checks the error state with the reason and an unchanged observedAt, one warning (not repeated on the next failed refresh), error: null on the account in status.get, the CLI exit code and message, and recovery to ok once the endpoint works again.
    • On main all 6 fail: status ok and no warning.
  • One existing test ("publishes pooled subscription usage ... does not invent unobserved utilization") now expects the refresh-failure message instead of "has not been observed". Its stub answers the usage request with an empty body, which is now an unreadable response. observedAt is still null.
  • pnpm exec turbo run test typecheck lint --filter=bb-plugin-account-pool passes (405 tests). The 3 lint warnings are React Compiler notes that main has too.

Fixes #7739

AGENT GENERATED

…eadings silently

A usage refresh that got an HTTP error, a response that could not be
read, or a network error returned as if it had succeeded. The hub also
swallowed any error with .catch(() => undefined). Provider usage then
kept showing the last reading as current, and plugin.log had nothing
(get-bb#7739).

The Claude and Codex adapters now reject when the usage request fails.
The hub records the latest failure per account, clears it on the next
successful refresh, and logs one warning per account and reason. The
usage source reports the failure as that account's error state, so
Provider usage keeps the last reading and shows that it could not be
refreshed. bb pool account refresh exits with usage_refresh_failed.
The failure is not stored as quota.error, so routing is unaffected.
@lanjak
lanjak force-pushed the fix-7739-pool-usage-refresh-failures branch from 1b3a28a to 5eade87 Compare November 24, 2026 00:58

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

Development

Successfully merging this pull request may close these issues.

Account Pooler: Provider usage keeps showing old readings after the plugin is disabled, and failed usage refreshes are silent

1 participant