Skip to content

Commit ce56f72

Browse files
committed
fix: preserve server retry policy fidelity
1 parent 3002a2d commit ce56f72

6 files changed

Lines changed: 8 additions & 6 deletions

File tree

lib/request/failure-policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export function evaluateFailurePolicy(
135135
markRateLimited: false,
136136
removeAccount: false,
137137
cooldownMs,
138-
cooldownReason: cooldownMs > 0 ? "network-error" : undefined,
138+
cooldownReason: cooldownMs > 0 ? "server-error" : undefined,
139139
retrySameAccount,
140140
retryDelayMs: retrySameAccount ? 500 : undefined,
141141
handoffStrategy: "hard",

lib/request/response-metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const MAX_RETRY_HINT_MS = 5 * 60 * 1000;
1+
const MAX_RETRY_HINT_MS = 24 * 60 * 60 * 1000;
22

33
function clampRetryHintMs(value: number): number | null {
44
if (!Number.isFinite(value)) return null;

lib/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export type AccountIdSourceFromSchema = z.infer<typeof AccountIdSourceSchema>;
8181
/**
8282
* Cooldown reason for temporary account suspension.
8383
*/
84-
export const CooldownReasonSchema = z.enum(["auth-failure", "network-error", "rate-limit"]);
84+
export const CooldownReasonSchema = z.enum(["auth-failure", "network-error", "server-error", "rate-limit"]);
8585

8686
export type CooldownReasonFromSchema = z.infer<typeof CooldownReasonSchema>;
8787

lib/storage/migrations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { MODEL_FAMILIES, type ModelFamily } from "../prompts/codex.js";
77
import type { AccountIdSource } from "../types.js";
88
import type { Workspace } from "../accounts.js";
99

10-
export type CooldownReason = "auth-failure" | "network-error" | "rate-limit";
10+
export type CooldownReason = "auth-failure" | "network-error" | "server-error" | "rate-limit";
1111

1212
export interface RateLimitStateV3 {
1313
[key: string]: number | undefined;

test/failure-policy.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe("failure policy", () => {
6565
expect(decision.retryDelayMs).toBe(500);
6666
expect(decision.rotateAccount).toBe(false);
6767
expect(decision.handoffStrategy).toBe("hard");
68+
expect(decision.cooldownReason).toBe("server-error");
6869
});
6970

7071
it("marks rate limit without cooldown mutation", () => {
@@ -146,6 +147,7 @@ describe("failure policy", () => {
146147
expect(decision.retrySameAccount).toBe(false);
147148
expect(decision.rotateAccount).toBe(true);
148149
expect(decision.cooldownMs).toBe(3_000);
150+
expect(decision.cooldownReason).toBe("server-error");
149151
});
150152

151153
it("uses override cooldowns for network and server kinds", () => {

test/response-metadata.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ describe("response metadata helpers", () => {
2323
expect(parseRetryAfterHintMs(headers)).toBe(1200);
2424
});
2525

26-
it("parses retry-after seconds and caps large values", () => {
26+
it("parses retry-after seconds and caps extreme values to one day", () => {
2727
const headers = new Headers({ "retry-after": "999999" });
2828

29-
expect(parseRetryAfterHintMs(headers)).toBe(300000);
29+
expect(parseRetryAfterHintMs(headers)).toBe(86_400_000);
3030
});
3131

3232
it("parses retry-after dates and x-ratelimit-reset timestamps", () => {

0 commit comments

Comments
 (0)