Skip to content

Route Account Pooler requests by ranked routing tiers - #6734

Closed
ymichael wants to merge 3 commits into
mainfrom
bb/account-pooler-tiered-selection-6169-3615-4468-6-thr_ywz3urifmc
Closed

ymichael wants to merge 3 commits into
mainfrom
bb/account-pooler-tiered-selection-6169-3615-4468-6-thr_ywz3urifmc

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Account Pooler routing used yes/no filters in select() (plugins/account-pool/src/hub.ts). Any window at or above switchThreshold (default 0.98) counted as exhausted, and the account was dropped, so the pool answered with its own 429 while Anthropic still allowed several accounts. In #6169 that parked threads for nearly three hours, and the 429 quoted the reset of an account Anthropic had actually rejected. accountAvailability() and noEligibleResponse() repeated similar filters to build the 429, Retry-After and provider-retry.v1.availability, so the answers could disagree, the same drift as #3324. The representative-claim: overage header was stored but never used, so Fable was billed as overage on a Team account while a Max account included it (#3615). API-key accounts had no rule enforcing "Metered fallback, never routes first" (#4468).

What changed

How you verified

  • New tests in src/server.test.ts ("tiered routing"): all four fail with main's routing code and pass with this change.
  • Unknown-column quota test in src/store.test.ts: fails with .strict(), passes without it.
  • Existing tests: every Account Pooler test passes unchanged except fixture type updates and replacing the removed isQuotaExhausted in codex-adapter.test.ts.
  • Commands:
    • pnpm exec turbo run typecheck lint test --force --filter=bb-plugin-account-pool --filter=bb-plugin-provider-retry: 370 and 33 tests pass. Lint shows the two existing React warnings.
    • pnpm exec turbo run typecheck lint --filter='...[origin/main]': passes.
    • pnpm exec turbo run test --filter=@bb/server -- test/threads/turn-failed-retry.test.ts test/services/plugin-catalog: 181 tests pass.
    • generate:bb-official-marketplace accepts the overview.

Fixes #6169
Fixes #3615
Part of #4468

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 3 commits October 30, 2026 15:56
The pool treated any window at or above switchThreshold as exhausted and
dropped the account, so it answered with its own 429 while the provider still
allowed several accounts (#6169). accountAvailability() and the 429 repeated
those filters, the overage claim never affected selection (#3615), and
API-key accounts had no "never routes first" rule (#4468).

One ranking function, routeRank(), now drives select(), the 429 text and
Retry-After, provider-retry.v1.availability, and account status: below
threshold, above it while the provider still allows the account (its
reported status decides, so 1.0 "allowed" stays usable), then paid (extra
usage or credits on a rejected account, per-family overage claims, API keys).
The pool refuses only when every tier is empty. The current account follows
the best tier; session pins stay on the first two tiers and move up only off
paid accounts. Holds, errors, family detours, commit-on-success and the
30-second recheck are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… know

The quota store reads `SELECT *` into a strict row schema, so a column added
by a later migration made every quota read throw on an older build. Reverting
this branch, or running an older build against the same plugin database,
would therefore break the pool instead of just losing the newest fields.
The row schema now ignores unknown columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The settings page listed accounts and statuses but never said how the pool
chooses between them, and the threshold field did not say what happens past
it. An info banner above the account list, styled like the thread storage
explainer in Storage retention, summarizes the routing: one account at a time
in list order, switching past the threshold, accounts past it still serving
when none have room, paid usage last, and ongoing conversations staying on
their account. It shows the configured threshold and appears once an account
exists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 2, 2026
## Human comments

## What was wrong

After a server restart, the GitHub PR Status plugin restores each
environment's PR from its database and serves it right away. It also
starts a background re-check right away, often before the host daemon
has reconnected. That re-check returned `unavailable` ("machine isn't
available"), and `store.load` replaced the environment's known PR link
with that result. The sidebar row badge disappeared and stayed gone
until something re-read that row, such as opening the thread or
refocusing the page. Observed on prod: the server restarted at 13:04:14
and the daemon reconnected at 13:04:20. Afterwards the sidebar showed
only #6849 (the thread that was opened). Six other inbox threads with
open PRs (#6760, #6755, #6736, #6728, #6727, #6734) showed no badge,
although their links and snapshots were still in the plugin database.

## What changed

- `plugins/github-pr-status/store.ts`: when a re-check of a known PR URL
comes back `unavailable`, the environment's link is no longer replaced,
so the last snapshot keeps being served. The snapshot's `fetchedAt` is
still bumped, so the regular poll retries it. Discovery reads (no known
URL) behave as before.
- Behaviour change: `bb pull-request show` for an environment whose
machine is offline now prints the last PR bb saw, or `unavailable` when
it has none. Actions (`ready`/`draft`/`merge`) still refuse with the
machine message. The skill doc and README are updated.

## How you verified

- New store test, "keeps serving a restored PR when its machine is
unreachable after a restart": it restores a persisted PR, makes the
first re-check return `unavailable`, and checks that the PR is still
served, nothing is published, and the next successful check publishes
the update. It fails without the fix (`expected { outcome: 'unavailable'
} to deeply equal { outcome: 'available' }`) and passes with it.
- `pnpm exec turbo run test typecheck lint
--filter=bb-plugin-bb--github-pr-status`: 183/183 tests pass, typecheck
and lint clean.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
@ymichael ymichael closed this Nov 2, 2026
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