Repository navigation
Description
Summary
I pool two Claude accounts: a Team account whose plan does not include Fable, and a Max 20x account whose plan does. The pool routes Fable turns to the Team account because it is the current cursor, and Anthropic serves them anyway by spending that account's paid usage credit (representative-claim: overage) rather than rejecting them. So every Fable turn costs real money on the Team account while the Max account's included Fable allowance sits unused. The pool already sees both signals, the overage claim on the Team account's responses and the weekly_scoped Fable limit in the Max account's usage payload, but neither influences selection. Expected: a model family that one account includes and another only serves by spending usage credit should always go to the account that includes it, unless that account is exhausted for the family.
Versions and environment
- bb 0.43.1, source checkout at
9e16411141788c67954bceb753bb64ac1dc7057f(main), Debian 13, Node v24.19.0 - Account Pooler plugin 0.1.0 (builtin), routing on for Claude
- claude-code provider, Claude Code 2.1.270
- Two Claude OAuth accounts in the pool: Team (
claude_team, priority 1, current active account) and Max 20x (max, priority 2)
Steps to reproduce
A live repro needs two real logins with differing plans, so the faithful repro is a unit test at the exact hub code path using the existing fixtures in plugins/account-pool/src/server.test.ts (startUpstream, createFixture with source: "import", importedCredentials, authHeaders). It mirrors the real accounts: the Team account's usage payload has no scoped Fable limit and its message responses carry anthropic-ratelimit-unified-representative-claim: overage; the Max account's usage payload has a weekly_scoped Fable limit at 33 percent.
- Append the
describe("model entitlement repro", …)block below toplugins/account-pool/src/server.test.ts. - Run:
cd plugins/account-pool
pnpm exec vitest run src/server.test.ts -t "model entitlement repro"Repro test
describe("model entitlement repro", () => {
it("routes Fable to the account whose plan includes Fable instead of the overage account", async () => {
const served: Array<{ authorization: string | undefined; model: string }> = [];
const upstream = await startUpstream(async (request, response) => {
const authorization = request.headers.authorization;
if (request.url === "/usage") {
response.writeHead(200, { "content-type": "application/json" });
response.end(
JSON.stringify(
authorization === "Bearer oauth-team"
? {
five_hour: { utilization: 2, resets_at: "4102444800" },
seven_day: { utilization: 0, resets_at: "4102448400" },
limits: [],
}
: {
five_hour: { utilization: 0, resets_at: "4102444800" },
seven_day: { utilization: 18, resets_at: "4102448400" },
limits: [
{
kind: "weekly_scoped",
group: "weekly",
percent: 33,
resets_at: "4102452000",
scope: { model: { display_name: "Fable" } },
},
],
},
),
);
return;
}
const body = JSON.parse(await readRequestBody(request)) as { model: string };
served.push({ authorization, model: body.model });
response.writeHead(200, {
"content-type": "application/json",
"anthropic-ratelimit-unified-5h-status": "allowed",
"anthropic-ratelimit-unified-7d-status": "allowed",
...(authorization === "Bearer oauth-team"
? { "anthropic-ratelimit-unified-representative-claim": "overage" }
: {}),
});
response.end('{"ok":true}');
});
cleanups.push(upstream.close);
const imports = [
importedCredentials({
accessToken: "oauth-team",
subscriptionType: "claude_team",
accountUuid: "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa",
}),
importedCredentials({
accessToken: "oauth-max",
subscriptionType: "max",
accountUuid: "bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb",
}),
];
let importIndex = 0;
const fixture = await createFixture({
upstreamUrl: upstream.url,
source: "import",
priority: 1,
options: {
usageUrl: `${upstream.url}/usage`,
importCredentials: async () => {
const imported = imports[importIndex];
importIndex += 1;
if (imported === undefined) throw new Error("No import fixture.");
return imported;
},
},
});
await fixture.host.harness.behavior.callRpc("account.add", {
provider: "claude",
source: { kind: "import" },
label: "max",
priority: 2,
});
for (const model of ["claude-fable-5-1", "claude-fable-5-1", "claude-opus-5"]) {
const response = await fixture.host.harness.behavior.fetchHttp("POST", "/v1/messages", {
headers: authHeaders(fixture.key),
body: JSON.stringify({ model }),
});
expect(response.status).toBe(200);
await response.text();
}
const accounts = z
.array(accountSummarySchema)
.parse(await fixture.host.harness.behavior.callRpc("account.list", null));
expect({
served,
familyWeeklyFable: accounts.map((account) => [
account.priority,
account.familyWeekly.fable === null ? null : account.familyWeekly.fable.utilization,
account.representativeClaim,
]),
}).toEqual({
served: [
{ authorization: "Bearer oauth-max", model: "claude-fable-5-1" },
{ authorization: "Bearer oauth-max", model: "claude-fable-5-1" },
{ authorization: "Bearer oauth-team", model: "claude-opus-5" },
],
familyWeeklyFable: [
[1, null, null],
[2, 0.33, null],
],
});
});
});Did not reproduce with: a Fable request when the Team account's response carries anthropic-ratelimit-unified-7d_oi-status: rejected. A family quota rejection already detours to the next account (existing test "rotates a family-only 429 without exhausting other families"). The gap is a family that is served but billed as overage.
Expected vs actual
FAIL bb-plugin-account-pool src/server.test.ts > model entitlement repro > routes Fable to the account whose plan includes Fable instead of the overage account
AssertionError: expected { served: [ { …(2) }, …(2) ], …(1) } to deeply equal { served: [ { …(2) }, …(2) ], …(1) }
- Expected
+ Received
{
"familyWeeklyFable": [
[
1,
null,
- null,
+ "overage",
],
[
2,
0.33,
null,
],
],
"served": [
{
- "authorization": "Bearer oauth-max",
+ "authorization": "Bearer oauth-team",
"model": "claude-fable-5-1",
},
{
- "authorization": "Bearer oauth-max",
+ "authorization": "Bearer oauth-team",
"model": "claude-fable-5-1",
},
{
"authorization": "Bearer oauth-team",
"model": "claude-opus-5",
Actual: both Fable requests go to the Team account. The second one goes there even though the pool has already stored representativeClaim: "overage" for that account from the first response, and has known since import that only the Max account reports a Fable limit. Opus correctly goes to the Team account.
Expected: Fable requests go to the Max account while its Fable window is under the switch threshold. Other families keep following priority order.
Evidence
Observed state on the reporting machine (plugin store ~/.bb/plugins/account-pool/data.db and plugin_kv in ~/.bb/bb.db, secrets not read), after a Fable 5.1 turn in thread thr_bwe8imghu5 at 20:42 UTC on 2026-09-13:
- Team account:
representative_claim: "overage",five_hour_utilization: 0.02,familyWeekly.fable: null,observed_atmatching the Fable turn's response, priority 1,pool_active_accountfor claude, and all three current session pins point at it. - Max account:
familyWeekly.fable = { utilization: 0.33, status: "allowed", source: "usage" }, priority 2, norepresentative_claim.
Code (permalinks at 9e16411141788c67954bceb753bb64ac1dc7057f):
- Eligibility is quota-only. An account with no Fable bucket is fully eligible for Fable, and the
overageclaim is stored but never consulted:andbb/plugins/account-pool/src/hub.ts
Lines 686 to 689 in 9e16411
.filter(({ quota }) => !isSharedQuotaExhausted(quota, threshold, now)); const eligible = available.filter( ({ quota }) => !isQuotaExhausted(quota, family, threshold, now), ); bb/plugins/account-pool/src/quota.ts
Lines 240 to 250 in 9e16411
export function isQuotaExhausted( quota: AccountQuota, family: ModelFamily, threshold: number, now: number, ): boolean { return ( isSharedQuotaExhausted(quota, threshold, now) || activeFamilyWindow(quota.familyWeekly[family], threshold, now) ); } representative-claimis parsed from every response and persisted, then unused outside the status report:andbb/plugins/account-pool/src/quota.ts
Line 90 in 9e16411
const representativeClaim = headers.get(`${PREFIX}representative-claim`); bb/plugins/account-pool/src/quota.ts
Line 123 in 9e16411
representativeClaim: representativeClaim ?? previous.representativeClaim, - The usage refresh sees per-model
weekly_scopedlimits but records only the buckets that are present; the absence of a Fable bucket on one account is not retained as a routing signal:bb/plugins/account-pool/src/usage.ts
Lines 112 to 160 in 9e16411
} export function quotaFromUsage( accountId: string, payload: object, previous: AccountQuota, now: number, ): AccountQuota | null { const parsed = usagePayloadSchema.safeParse(payload); if (!parsed.success) return null; const data = parsed.data; if ( data.five_hour == null && data.seven_day == null && data.seven_day_fable == null && data.seven_day_sonnet == null && data.seven_day_opus == null && data.seven_day_haiku == null && data.limits === undefined ) return null; const familyWeekly: FamilyWeekly = data.limits === undefined ? { ...previous.familyWeekly } : { ...EMPTY_FAMILY_WEEKLY }; for (const limit of data.limits ?? []) { if ( limit.kind !== "weekly_scoped" && !(limit.group === "weekly" && limit.scope?.model?.display_name != null) ) continue; const displayName = limit.scope?.model?.display_name; if (displayName == null) continue; const family = modelFamily(displayName); familyWeekly[family] = stronger( familyWeekly[family], limitBucket(limit.percent, limit.resets_at, limit.status, now), ); } const slots: Array<[ModelFamily, UsageBucket | null | undefined]> = [ ["fable", data.seven_day_fable], ["sonnet", data.seven_day_sonnet], ["opus", data.seven_day_opus], ["haiku", data.seven_day_haiku], ]; for (const [family, bucket] of slots) { if (bucket == null) continue; const normalized = normalizeBucket(bucket, now); if (normalized !== null) familyWeekly[family] = normalized; - New sessions follow the provider cursor and existing sessions stay pinned, so once the cursor sits on the Team account every new Fable session lands there:
bb/plugins/account-pool/src/hub.ts
Lines 736 to 752 in 9e16411
const selected = bound !== undefined && unattempted.includes(bound) ? bound : (inherited ?? (boundAccountId === null && previousAccountId === null && activeAccount !== undefined && unattempted.includes(activeAccount) ? activeAccount : next) ?? null); if (selected === null) return null; if (routing.active === null) routing.pinnedAccountId = boundAccountId ?? inherited?.account.id ?? null; if (affinityKey !== null && binding === undefined) { binding = { accountId: selected.account.id, lastUsedAt: now }; this.affinityBindings.set(affinityKey, binding);
Related but secondary: if an account rejects the model outright instead of billing overage, the hub returns a 404 verbatim without failover (hub.ts#L544-L545), and treats a 403 as an auth failure that marks the whole account in error for every family (hub.ts#L534-L541). A per-family availability record would cover both.
Investigation thread: thr_gtdujy2ja4.
Unverified: whether Anthropic ever reports an "included" marker for a family beyond the presence of a weekly_scoped limit in the usage payload. The repro treats presence of that limit as "included" and representative-claim: overage as "billed as extra usage", which matches the two real accounts.
What you ruled out
- Not Account Pooler: persistent immediate 502s from a destroyed transport session (Claude and ChatGPT/Codex); underlying cause is discarded #3201 (transport 502s), Show pooled Claude and Codex account usage in Settings → Usage #3243 (usage display), or Account Pooler has no route for Codex standalone search, so Codex web search 404s through the pool #3528 (Codex search route); none concern which account pays for a family.
- Not the Headroom base URL override from the earlier 401 investigation; that was removed and pooled turns succeed.
- Family quota detours work when the response carries a
7d_<scope>rejection; the gap is a served-but-overage family. - Still present on
mainat9e16411141788c67954bceb753bb64ac1dc7057f.
Suggested priority and effort
High for cost. Every pooled Fable turn on the wrong account is billed as extra usage while an included allowance goes unused, and nothing in the UI or CLI shows that it happened. Hits anyone mixing a Team or Pro account with a Max account. Workaround: put the Max account at priority 1 and disable then re-enable the Team account so the cursor moves. Effort probably Medium: a per-account, per-family "included / overage / unavailable" record learned from the usage payload and from representative-claim, consulted in select() before the priority order, plus a manual per-account override and a visible marker in bb pool status.
AGENT GENERATED
Activity
bb-slop-cop commentedon Sep 13, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotClassified Bug · High priority · Medium effort; added
providers.Reproduction and root-cause report: REPRODUCED, high confidence in the routing cause. An authored regression failed identically in two clean checkouts of trusted main: both requests used the first account, despite stored overage and available scoped quota on the second. Real billing and plan entitlement remain unverified.
Root cause: quota-only eligibility and account affinity ignore the overage signal. Reproduction label:
confirmed-repro.No PR: safe entitlement inference and family-specific fallback require a product decision, outside the simple-fix constraints.
Support Claude and Codex extra-usage fallback and availability (#4531)
Keep Account Pooler accounts past the switch threshold usable until t…