GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(combos): a spent pool account must not cool the whole target (car… · lidge-jun/opencodex@99878c3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs-site/src/content/docs/guides
    • combos.md
  • scripts/test-layout
    • layout.json
  • src
    • combos
      • resolve.ts
    • oauth
      • anthropic-routing.ts
    • providers
      • label.ts
    • server/responses
      • adapter-continuation.ts
      • adapter-dispatch.ts
      • core-combo.ts
  • structure
    • providers-and-adapters.md
    • runtime.md
    • transports
      • inventory.md
  • tests
    • adapters/anthropic
      • anthropic-combo-account-cooldown.test.ts
    • fixtures
      • test-layout-expected.json
    • routing
      • always-on-429-failover.test.ts
    • server
      • server-combo-cooldown-recording.test.ts
    • usage
      • usage-provider-label.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs-site/src/content/docs/guides/combos.md‎

Copy file name to clipboardExpand all lines: docs-site/src/content/docs/guides/combos.md
+4Lines changed: 4 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ five seconds. A valid immediate
354354
`Retry-After: 0` remains an immediate upstream directive rather than being replaced by a configured
355355
cooldown.
356356

357+
For an Anthropic OAuth or Codex pool, a 429 tied to one account that the pool has cooled does
358+
not cool the whole combo target. Other accounts behind that target remain available. A 429 with
359+
no identified, cooled pool account still cools the target, as do provider-wide failures.
360+
357361
### Last-resort targets
358362

359363
A brief cooldown on a preferred target otherwise routes straight to whatever
Collapse file

‎scripts/test-layout/layout.json‎

Copy file name to clipboardExpand all lines: scripts/test-layout/layout.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"ambiguous-resend-composition.test.ts": "lib",
101101
"ambiguous-resend-gate.test.ts": "lib",
102102
"anthropic-account-pool.test.ts": "adapters/anthropic",
103+
"anthropic-combo-account-cooldown.test.ts": "adapters/anthropic",
103104
"anthropic-model-routes.test.ts": "adapters/anthropic",
104105
"anthropic-agentrouter-language-framing.test.ts": "adapters/anthropic",
105106
"anthropic-baseurl-override.test.ts": "adapters/anthropic",
Collapse file

‎src/combos/resolve.ts‎

Copy file name to clipboardExpand all lines: src/combos/resolve.ts
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,28 @@ export function advanceComboAfterFailure(
380380
status?: number;
381381
code?: string | null;
382382
message?: string;
383+
/** Account-qualified provider label of the account this failure came from, when a pool resolved one. */
384+
failedAccount?: string;
383385
} = {},
384386
): ComboPick | null {
385387
noteComboFailure(pick.comboId, pick.target, pick.writerGeneration);
386388
const combo = getCombo(config, pick.comboId);
389+
// A 429 from a pooled provider names the ACCOUNT that is spent, not the target. The pool
390+
// records that account's own cooldown and rotates past it, so cooling the target here blacks
391+
// out the accounts that still answer: on 2026-09-28 one Anthropic account replied
392+
// `Retry-After: 318747` (88.5h) and anthropic/claude-opus-5-5 left selection for four hours
393+
// while four of five accounts still returned 200.
394+
//
395+
// Only a pool-resolved account qualifies, and an unidentified account still cools the target --
396+
// including the pool's OWN "all accounts are cooled" 429, which refuses locally before it picks
397+
// one. That is what keeps this from trading a blackhole for a hammer: when nothing else is
398+
// holding the target back, the target cooldown still does.
399+
const accountScoped = options.cooldownScope === "target"
400+
&& options.status === 429
401+
&& options.failedAccount !== undefined;
387402
// "none" records no cooldown at all: the failure described the request, not the target, so
388403
// the target must stay immediately selectable for the next (differently shaped) request.
389-
if (options.cooldownScope !== "none") {
404+
if (options.cooldownScope !== "none" && !accountScoped) {
390405
const cooldownTargets = options.cooldownScope === "provider" && combo
391406
? combo.targets.filter(target => target.provider === pick.target.provider)
392407
: [pick.target];
Collapse file

‎src/oauth/anthropic-routing.ts‎

Copy file name to clipboardExpand all lines: src/oauth/anthropic-routing.ts
+31-19Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,41 @@ export function rotateAnthropicAccountOn429(
736736
rateLimitHeaders?: AnthropicRateLimitHeaders | null,
737737
decision: AnthropicRouteDecision | null = null,
738738
): string | null {
739+
if (!recordAnthropicAccount429(config, failedAccountId, retryAfterHeader, now, rateLimitHeaders)) return null;
740+
741+
// The pool's strategy is a PROACTIVE policy. When the pool is disabled, reactive
742+
// presence-only recovery must not silently reactivate round-robin/fill-first merely
743+
// because those dormant values remain in config. The quota picker is the neutral
744+
// recovery policy already used by the default strategy.
745+
const next = isAnthropicAccountPoolEnabled(config)
746+
? pickAlternateAnthropicAccount(config, failedAccountId, now, decision)
747+
: pickLowestUsage(config, failedAccountId, now);
748+
if (!next) {
749+
console.warn(`[anthropic-pool] ${decision ? `route:#${decision.position} ` : ""}no eligible replacement; returning 429`);
750+
return null;
751+
}
752+
753+
console.warn(
754+
`[anthropic-pool] ${decision ? `route:#${decision.position} ` : ""}429 on ${formatAnthropicAccountOrdinal(failedAccountId)}; failing over to ${formatAnthropicAccountOrdinal(next)}`,
755+
);
756+
return next;
757+
}
758+
759+
/** Record the account refusal even when this request has no remaining retry sends. */
760+
export function recordAnthropicAccount429(
761+
config: OcxConfig,
762+
failedAccountId: string,
763+
retryAfterHeader: string | null | undefined,
764+
now = Date.now(),
765+
rateLimitHeaders?: AnthropicRateLimitHeaders | null,
766+
): boolean {
739767
// Reactive 429 failover is NOT gated on the pool flag. That flag buys PROACTIVE routing --
740768
// session affinity, quota-ranked new-session selection, autoSwitchThreshold, strategy -- all
741769
// of which move a HEALTHY request and stay opt-in. Rotating away from an account upstream has
742770
// just rate-limited is a different thing: it only ever runs after a refusal, and stranding a
743771
// 429 while a second logged-in account sits idle is a defect, not a configuration choice.
744772
// Presence is the activation rule, the same one an apiKeyPool of two keys already uses.
745-
if (!isAnthropicAccountPoolEnabled(config) && !hasAnthropicFailoverQuorum(now)) return null;
773+
if (!isAnthropicAccountPoolEnabled(config) && !hasAnthropicFailoverQuorum(now)) return false;
746774

747775
// Retry-After first: it is the header written FOR this decision. The rejected window's
748776
// reset is the fallback, because a 429 that omits Retry-After still carries it -- and
@@ -760,26 +788,10 @@ export function rotateAnthropicAccountOn429(
760788
sweepExpiredOnWrite(now);
761789
clearAnthropicSessionAffinityForAccount(failedAccountId);
762790
notePoolRotationFailure(POOL_KEY_ANTHROPIC, failedAccountId);
763-
// A rotation means the roster in use just changed; do not answer the next activation question
764-
// from a count read taken before the failure.
791+
// The refused account changed the eligible roster even when no retry send remains.
765792
quorumCache = null;
766793

767-
// The pool's strategy is a PROACTIVE policy. When the pool is disabled, reactive
768-
// presence-only recovery must not silently reactivate round-robin/fill-first merely
769-
// because those dormant values remain in config. The quota picker is the neutral
770-
// recovery policy already used by the default strategy.
771-
const next = isAnthropicAccountPoolEnabled(config)
772-
? pickAlternateAnthropicAccount(config, failedAccountId, now, decision)
773-
: pickLowestUsage(config, failedAccountId, now);
774-
if (!next) {
775-
console.warn(`[anthropic-pool] ${decision ? `route:#${decision.position} ` : ""}no eligible replacement; returning 429`);
776-
return null;
777-
}
778-
779-
console.warn(
780-
`[anthropic-pool] ${decision ? `route:#${decision.position} ` : ""}429 on ${formatAnthropicAccountOrdinal(failedAccountId)}; failing over to ${formatAnthropicAccountOrdinal(next)}`,
781-
);
782-
return next;
794+
return true;
783795
}
784796

785797
export interface AnthropicSelectionRoutingOptions {
Collapse file

‎src/providers/label.ts‎

Copy file name to clipboardExpand all lines: src/providers/label.ts
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CODEX_ACCOUNT_LOG_LABEL_RE, KEY_ACCOUNT_LOG_LABEL_RE, apiKeyAccountLogLabel, oauthAccountLogLabel } from "../codex/account-label";
1+
import { ACCOUNT_LOG_LABEL_RE, CODEX_ACCOUNT_LOG_LABEL_RE, KEY_ACCOUNT_LOG_LABEL_RE, apiKeyAccountLogLabel, oauthAccountLogLabel } from "../codex/account-label";
22
import type { OcxProviderConfig } from "../types";
33

44
export function canonicalUsageProviderLabel(provider: string): string {
@@ -25,6 +25,25 @@ export function stampApiKeyAccountLabel(
2525
}
2626
}
2727

28+
/**
29+
* The account-qualified provider label a pool dispatch stamped for this request, or undefined.
30+
*
31+
* An account pool rewrites the logged provider to name the account that served the turn
32+
* (`anthropic-p2e22d0`, `openai-main`); the configured provider name never does, so a label that
33+
* differs from the configured one AND ends in an account label identifies exactly one account.
34+
*
35+
* Deliberately NOT `accountLogLabel`: that is stamped for a lone configured API key too, so it
36+
* cannot tell a pooled account apart from a provider that has no pool to rotate within.
37+
*/
38+
export function poolAccountProviderLabel(
39+
loggedProvider: string | undefined,
40+
configuredProvider: string,
41+
): string | undefined {
42+
if (!loggedProvider?.startsWith(`${configuredProvider}-`)) return undefined;
43+
return ACCOUNT_LOG_LABEL_RE.test(loggedProvider.slice(configuredProvider.length + 1))
44+
? loggedProvider : undefined;
45+
}
46+
2847
export function baseProviderLabel(provider: string): string {
2948
const canonical = canonicalUsageProviderLabel(provider);
3049
if (canonical !== provider) return canonical;
Collapse file

‎src/server/responses/adapter-continuation.ts‎

Copy file name to clipboardExpand all lines: src/server/responses/adapter-continuation.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { bindRouteReasoningReplayScope } from "./core-replay";
3535
import {
3636
ANTHROPIC_POOL_MAX_FAILOVERS_PER_REQUEST,
3737
rotateAnthropicAccountOn429,
38+
recordAnthropicAccount429,
3839
getAnthropicPoolAccessSnapshot,
3940
formatAnthropicProviderForLog,
4041
} from "../../oauth/anthropic-routing";
@@ -425,6 +426,11 @@ export function createAdapterContinuations(
425426
}
426427
}
427428
}
429+
if (response.status === 429 && transportState.anthropicPoolAccountId
430+
&& transportState.anthropicPoolFailovers >= ANTHROPIC_POOL_MAX_FAILOVERS_PER_REQUEST) {
431+
recordAnthropicAccount429(config, transportState.anthropicPoolAccountId,
432+
response.headers.get("retry-after"), Date.now(), response.headers);
433+
}
428434
// Generic OAuth rotation for the continuation loop. The streaming loop grew this arm with
429435
// #2568 and this one did not, so an xAI/Cursor/Kimi/Copilot/Antigravity/Nous continuation
430436
// 429 stayed terminal even with failover fully active -- the same class of divergence the
Collapse file

‎src/server/responses/adapter-dispatch.ts‎

Copy file name to clipboardExpand all lines: src/server/responses/adapter-dispatch.ts
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { bindRouteReasoningReplayScope } from "./core-replay";
5656
import {
5757
ANTHROPIC_POOL_MAX_FAILOVERS_PER_REQUEST,
5858
rotateAnthropicAccountOn429,
59+
recordAnthropicAccount429,
5960
getAnthropicPoolAccessSnapshot,
6061
formatAnthropicProviderForLog,
6162
} from "../../oauth/anthropic-routing";
@@ -1000,6 +1001,11 @@ export async function prepareAdapterExchange(
10001001
break;
10011002
}
10021003
}
1004+
if (upstreamResponse.status === 429 && transportState.anthropicPoolAccountId
1005+
&& transportState.anthropicPoolFailovers >= ANTHROPIC_POOL_MAX_FAILOVERS_PER_REQUEST) {
1006+
recordAnthropicAccount429(config, transportState.anthropicPoolAccountId,
1007+
upstreamResponse.headers.get("retry-after"), Date.now(), upstreamResponse.headers);
1008+
}
10031009
// Generic OAuth account failover (#2568) rotates reactively after a refusal when
10041010
// two accounts are stored. Kiro additionally classifies bounded 400/403 refusals;
10051011
// all other providers retain the original 429 loop below.
Collapse file

‎src/server/responses/core-combo.ts‎

Copy file name to clipboardExpand all lines: src/server/responses/core-combo.ts
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ import {
4646
import { hasUnreadableEncryptedAgentTask } from "./encrypted-payload";
4747
import { routeConcreteModel, comboRouteDecisionTrace } from "../../router";
4848
import { memoryModelRouteReason } from "./memory-models";
49+
import { poolAccountProviderLabel } from "../../providers/label";
50+
import { getAccountSet } from "../../oauth/store";
51+
import { formatAnthropicProviderForLog, getAnthropicAccountHealthSnapshot } from "../../oauth/anthropic-routing";
52+
import { codexAccountLogLabel } from "../../codex/account-label";
53+
import { codexQuotaScopeForModel, getCodexQuotaHealthSnapshot } from "../../codex/routing";
4954
import { isCanonicalOpenAiForwardProvider } from "../../providers/openai-tiers";
5055
import type { AgentTaskRecoveryFailureReason } from "./agent-task-recovery";
5156
import {
@@ -97,6 +102,22 @@ import { clientWireOf } from "../inference/client-wire";
97102
*/
98103
export const COMBO_TARGET_BASE_SENDS = CODEX_TEXT_GUARDED_BUDGET_POLICY.baseSendAllowance;
99104

105+
function cooledPoolAccountLabel(config: OcxConfig, providerName: string, modelId: string, label: string | undefined): string | undefined {
106+
if (!label) return undefined;
107+
if (providerName === "anthropic") {
108+
const matches = getAccountSet("anthropic")?.accounts.filter(account =>
109+
formatAnthropicProviderForLog("anthropic", account.id) === label) ?? [];
110+
return matches.length === 1 && getAnthropicAccountHealthSnapshot(matches[0]!.id) ? label : undefined;
111+
}
112+
const provider = config.providers[providerName];
113+
if (!provider || !isCanonicalOpenAiForwardProvider(provider)) return undefined;
114+
const matches = (config.codexAccounts ?? []).filter(account =>
115+
`${providerName}-${codexAccountLogLabel(account)}` === label);
116+
return matches.length === 1
117+
&& getCodexQuotaHealthSnapshot(matches[0]!.id, codexQuotaScopeForModel(modelId))
118+
? label : undefined;
119+
}
120+
100121

101122
/**
102123
* A combo's execution policy is DECLARED by the combo, not inherited from the single-target
@@ -977,6 +998,13 @@ export async function executeComboResponses(
977998
status: failure.response.status,
978999
code: failure.upstreamCode,
9791000
message: failure.classificationText,
1001+
// The dispatch rewrote this to name the pool account that actually served the turn.
1002+
failedAccount: cooledPoolAccountLabel(
1003+
config,
1004+
pick.target.provider,
1005+
pick.target.model,
1006+
poolAccountProviderLabel(childLog.provider, pick.target.provider),
1007+
),
9801008
onCooldownRecorded: target => {
9811009
failedTargetCooldownRecorded ||= targetKey(target) === failedTargetKey;
9821010
},
Collapse file

‎structure/providers-and-adapters.md‎

Copy file name to clipboardExpand all lines: structure/providers-and-adapters.md
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
For Anthropic OAuth, `src/oauth/anthropic-routing.ts` applies the first matching `anthropicAccountPool.routes` rule to every eligible pick. The declared account order is stable while its candidates remain eligible; active, manual, affinity, quota and strategy preferences only choose inside that set. A healthy session affinity outside a model route is ignored for that request and retained for later unrouted or differently routed models; the routed commit does not overwrite it. An explicit fallback widens an empty route to the ordinary pool, and fill-first then advances in ordinary pool order from the active account. A missing eligible route fails locally without that fallback. The rules are operator allowlists, not provider entitlement evidence. Request logs use `route:#<n>` for the 1-based rule position, not the operator name.
44

5+
An Anthropic 429 records the served account's cooldown even when the request has used its allowed retry sends. That final account remains excluded on the next request; combo target cooling is skipped only after the matching account cooldown is present.
6+
57
GitHub Copilot `modelContextTiers` is selected per upstream model. The Chat and Responses
68
adapters set `contextTier` only when the canonical routed provider is `github-copilot`
79
and a tier is configured. Otherwise passthrough retains caller-supplied values. The server carries provider identity
Collapse file

‎structure/runtime.md‎

Copy file name to clipboardExpand all lines: structure/runtime.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ This is also why the classifier cannot duplicate visible output. Native byte str
504504

505505
Regression coverage: `tests/responses/responses-forward-prompt-envelope.test.ts`, `tests/routing/router-combo-failover-classification.test.ts`, `tests/routing/routing-policy-fallback.test.ts`, `tests/helpers/combo-context-overflow-cases.ts`, and `tests/server/server-combo-failover-e2e.test.ts`.
506506

507-
`src/combos/failover.ts` uses a 10-minute fallback for a spent account usage window (codes `usage_limit_exceeded`, `usage_limit_reached`, `1308`, or `usage limit reached` / `usage limit has been reached` / `token-plan <window> quota has been exhausted` prose, including HTTP 502) and for provider-scoped credential or billing failure codes such as `invalid_api_key` and `insufficient_quota`. This duration does not change failure classification or cooldown scope; upstream retry/reset signals and configured durations retain precedence. It caps explicit upstream `Retry-After` target cooldowns at 24 hours while reset-derived, configured, and fallback cooldowns remain capped at 10 minutes.
507+
`src/combos/failover.ts` uses a 10-minute fallback for a spent account usage window (codes `usage_limit_exceeded`, `usage_limit_reached`, `1308`, or `usage limit reached` / `usage limit has been reached` / `token-plan <window> quota has been exhausted` prose, including HTTP 502) and for provider-scoped credential or billing failure codes such as `invalid_api_key` and `insufficient_quota`. This duration does not change failure classification or cooldown scope; upstream retry/reset signals and configured durations retain precedence. It caps explicit upstream `Retry-After` target cooldowns at 24 hours while reset-derived, configured, and fallback cooldowns remain capped at 10 minutes. `src/combos/resolve.ts` omits a target cooldown for a 429 only when the failed child identifies one account in an Anthropic OAuth or canonical Codex pool and that account has a live pool cooldown. `src/server/responses/core-combo.ts` checks the pool's health record before passing that attribution; unknown accounts, ambiguous labels, API-key and generic OAuth providers, and other failures keep their ordinary target cooldown.
508508

509509
## Combo default effort precedence
510510

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.