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 pool-held 429 must not park the combo target past the … · AgentRadarLabs/opencodex@d9a8539

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/server/responses
    • core-combo.ts
  • tests/routing
    • always-on-429-failover.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: src/server/responses/core-combo.ts
+47-9Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ import { routeConcreteModel, comboRouteDecisionTrace } from "../../router";
4848
import { memoryModelRouteReason } from "./memory-models";
4949
import { poolAccountProviderLabel } from "../../providers/label";
5050
import { getAccountSet } from "../../oauth/store";
51-
import { formatAnthropicProviderForLog, getAnthropicAccountHealthSnapshot } from "../../oauth/anthropic-routing";
51+
import {
52+
formatAnthropicProviderForLog,
53+
getAnthropicAccountHealthSnapshot,
54+
getAnthropicPoolRetryAfterSeconds,
55+
getEligibleAnthropicAccounts,
56+
} from "../../oauth/anthropic-routing";
5257
import { codexAccountLogLabel } from "../../codex/account-label";
5358
import { codexQuotaScopeForModel, getCodexQuotaHealthSnapshot } from "../../codex/routing";
5459
import { isCanonicalOpenAiForwardProvider } from "../../providers/openai-tiers";
@@ -119,6 +124,33 @@ function cooledPoolAccountLabel(config: OcxConfig, providerName: string, modelId
119124
}
120125

121126

127+
/**
128+
* True only for the Anthropic OAuth pool's OWN "all accounts cooled" 429. Its Retry-After is the
129+
* earliest per-account cooldown restated (`getAnthropicPoolRetryAfterSeconds`), which the pool
130+
* keeps enforcing locally, so it must not also park the combo target: an account added, resumed or
131+
* cleared a minute later would otherwise sit ignored until the target expired, up to the 24h
132+
* server-delay ceiling.
133+
*
134+
* Provenance, not just current state: the target must be the OAuth pool, no account may have been
135+
* identified for the failure, and the pool must be holding the wait right now. An upstream 429 on
136+
* a pool account always cools and names that account, and an API-key provider never qualifies, so
137+
* a genuine upstream Retry-After still parks the target in full.
138+
*/
139+
export function isAnthropicPoolLocalRefusal(
140+
config: OcxConfig,
141+
providerName: string,
142+
status: number,
143+
failedAccount: string | undefined,
144+
now = Date.now(),
145+
): boolean {
146+
return providerName === "anthropic"
147+
&& config.providers[providerName]?.authMode === "oauth"
148+
&& status === 429
149+
&& failedAccount === undefined
150+
&& getEligibleAnthropicAccounts(now).length === 0
151+
&& getAnthropicPoolRetryAfterSeconds(now) !== null;
152+
}
153+
122154
/**
123155
* A combo's execution policy is DECLARED by the combo, not inherited from the single-target
124156
* profile.
@@ -988,8 +1020,20 @@ export async function executeComboResponses(
9881020
});
9891021
const failedTargetKey = targetKey(pick.target);
9901022
let failedTargetCooldownRecorded = false;
1023+
// The dispatch rewrote this to name the pool account that actually served the turn.
1024+
const failedAccount = cooledPoolAccountLabel(
1025+
config,
1026+
pick.target.provider,
1027+
pick.target.model,
1028+
poolAccountProviderLabel(childLog.provider, pick.target.provider),
1029+
);
1030+
// The target still cools on the pool's own refusal (the anti-hammer guard), but for the local
1031+
// fallback rather than the pool's restated per-account Retry-After.
1032+
const poolLocalRefusal = isAnthropicPoolLocalRefusal(
1033+
config, pick.target.provider, failure.response.status, failedAccount, failureNow,
1034+
);
9911035
const nextPick = advanceComboAfterFailure(config, pick, {
992-
retryAfter: failure.retryAfter,
1036+
retryAfter: poolLocalRefusal ? undefined : failure.retryAfter,
9931037
resetAt: failure.resetAt,
9941038
cooldownMs: combo.cooldownMs,
9951039
now: failureNow,
@@ -998,13 +1042,7 @@ export async function executeComboResponses(
9981042
status: failure.response.status,
9991043
code: failure.upstreamCode,
10001044
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-
),
1045+
failedAccount,
10081046
onCooldownRecorded: target => {
10091047
failedTargetCooldownRecorded ||= targetKey(target) === failedTargetKey;
10101048
},
Collapse file

‎tests/routing/always-on-429-failover.test.ts‎

Copy file name to clipboardExpand all lines: tests/routing/always-on-429-failover.test.ts
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
1414
import { mkdtempSync } from "node:fs";
1515
import { tmpdir } from "node:os";
1616
import { join } from "node:path";
17+
import { clearComboTargetCooldowns, coolComboTarget, isComboTargetInCooldown } from "../../src/combos/failover";
18+
import { isAnthropicPoolLocalRefusal } from "../../src/server/responses/core-combo";
1719
import {
1820
clearAnthropicAccountPoolState,
21+
getAnthropicPoolRetryAfterSeconds,
1922
getEligibleAnthropicAccounts,
2023
hasAnthropicFailoverQuorum,
2124
isAnthropicAccountPoolEnabled,
@@ -136,6 +139,57 @@ describe("Anthropic reactive 429 failover without the pool flag", () => {
136139
expect(rotateAnthropicAccountOn429(poolAbsent(), ids[0]!, null)).toBe(ids[1]);
137140
expect(rotateAnthropicAccountOn429(poolAbsent(), ids[1]!, null)).toBeNull();
138141
});
142+
143+
// The combo layer keys its target cooldown off this. While the pool holds the wait, its 429
144+
// Retry-After is only its own earliest account cooldown restated, so the combo must not also
145+
// park the target on it -- otherwise an account added a minute later sits ignored until the
146+
// target cooldown expires, which for a weekly window is the 24h server-delay ceiling.
147+
test("only the OAuth pool's own all-cooled 429 is a local refusal", async () => {
148+
const ids = await seedAccounts(2);
149+
const oauth = poolAbsent();
150+
const refusal = (config = oauth, account?: string) =>
151+
isAnthropicPoolLocalRefusal(config, "anthropic", 429, account);
152+
expect(refusal()).toBe(false);
153+
const weekly = String(4 * 86_400);
154+
expect(rotateAnthropicAccountOn429(oauth, ids[0]!, weekly)).toBe(ids[1]);
155+
// One account still eligible: an upstream 429 here is about THAT account, not the pool.
156+
expect(refusal()).toBe(false);
157+
expect(rotateAnthropicAccountOn429(oauth, ids[1]!, weekly)).toBeNull();
158+
expect(getAnthropicPoolRetryAfterSeconds()).toBeGreaterThan(86_400);
159+
expect(refusal()).toBe(true);
160+
// Provenance, not just pool state: an identified account or an API-key provider is upstream
161+
// speaking, so its Retry-After must still park the target in full.
162+
expect(refusal(oauth, "anthropic-p0000000")).toBe(false);
163+
const apiKey = { ...oauth, providers: { anthropic: { ...oauth.providers.anthropic!, authMode: "key" } } } as OcxConfig;
164+
expect(refusal(apiKey)).toBe(false);
165+
expect(isAnthropicPoolLocalRefusal(oauth, "anthropic", 503, undefined)).toBe(false);
166+
// A fresh account makes the pool usable again at once, which a parked target would ignore.
167+
await saveCredential("anthropic", {
168+
access: "access-new", refresh: "refresh-new", expires: Date.now() + 3_600_000,
169+
accountId: "uuid-new", email: "[email protected]",
170+
} as never);
171+
expect(refusal()).toBe(false);
172+
});
173+
174+
// The combo-layer half, mirroring core-combo's call site: the target still cools (the
175+
// anti-hammer guard), but for the local fallback rather than the pool's multi-day Retry-After.
176+
// A single account is deliberately never cooled by rotation (see the no-op test above), so the
177+
// pool cannot hold the wait there and an upstream Retry-After keeps parking the target as before.
178+
test("a pool-held 429 cools the combo target for minutes, not for the pool's Retry-After", async () => {
179+
const ids = await seedAccounts(2);
180+
const weekly = String(4 * 86_400);
181+
rotateAnthropicAccountOn429(poolAbsent(), ids[0]!, weekly);
182+
rotateAnthropicAccountOn429(poolAbsent(), ids[1]!, weekly);
183+
const now = Date.now();
184+
const local = isAnthropicPoolLocalRefusal(poolAbsent(), "anthropic", 429, undefined, now);
185+
expect(local).toBe(true);
186+
const target = { provider: "anthropic", model: "claude-opus-5" };
187+
clearComboTargetCooldowns("pool-held");
188+
coolComboTarget("pool-held", target, { now, retryAfter: local ? undefined : weekly, status: 429 });
189+
expect(isComboTargetInCooldown("pool-held", target, now + 1)).toBe(true);
190+
expect(isComboTargetInCooldown("pool-held", target, now + 10 * 60_000)).toBe(false);
191+
clearComboTargetCooldowns("pool-held");
192+
});
139193
});
140194

141195
describe("proactive Anthropic routing stays opt-in", () => {

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.