diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index faddf5fa837b2..62b724e612220 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -9710,6 +9710,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); + const gatewayLimitWithCountdown = + "API Error: Server is temporarily limiting requests (not your usage limit) · All credentials for model claude-opus-5-5 are cooling down (last error: rate_limit_error: This request would exceed your account's rate limit. Please try again later.) (reset after 2h26m17s)"; + it.effect.each([ { status: 503, cooldown: "4m 6s", seconds: 246 }, { status: 503, cooldown: "1h 2m 3s", seconds: 3723 }, @@ -9745,8 +9748,25 @@ describe("ClaudeAdapterV2 background wake turns", () => { proxy: true, sdkResetSeconds: null, sdkLimitType: null, - result: - "API Error: Server is temporarily limiting requests (not your usage limit) · All credentials for model claude-opus-5-5 are cooling down (last error: rate_limit_error: This request would exceed your account's rate limit. Please try again later.) (reset after 2h26m17s)", + result: gatewayLimitWithCountdown, + }, + { + status: 429, + cooldown: "untyped assistant rejection", + seconds: 8777, + proxy: true, + assistantResetSeconds: null, + result: gatewayLimitWithCountdown, + }, + { + status: 429, + cooldown: "untyped rejection and a later assistant reset", + seconds: 9000, + proxy: true, + sdkResetSeconds: null, + sdkLimitType: null, + assistantResetSeconds: 9000, + result: gatewayLimitWithCountdown, }, ])("recovers wrapped gateway limits with status $status and cooldown $cooldown", (input) => Effect.gen(function* () { @@ -9786,6 +9806,22 @@ describe("ClaudeAdapterV2 background wake turns", () => { makeAssistantErrorFrame({ uuid: "00000000-0000-4000-8000-000000000652", error: input.proxy ? "rate_limit" : "server_error", + ...(input.assistantResetSeconds !== undefined + ? { + apiErrorParams: { + rate_limit_info: { + status: "rejected", + isUsingOverage: false, + ...(input.assistantResetSeconds === null + ? {} + : { + resetsAt: + DateTime.toEpochMillis(now) / 1000 + input.assistantResetSeconds, + }), + }, + }, + } + : {}), }), makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000653", diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 46441a539c0ad..e1e08a8078e68 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -12128,15 +12128,20 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( const resultResetAt = resultFailure?.class === "usage_limit" ? resultFailure.resetAt : null; // An untyped rejection without a reset is the gateway's own 429; its text names the reset. + const isGatewayEcho = (type: string, time: string | null | undefined) => + type === "unknown" && time === null && resultResetAt != null; const resetTimes = Array.from(context.rateLimitResetTimes) - .filter( - ([type, time]) => !(type === "unknown" && time === null && resultResetAt != null), - ) + .filter(([type, time]) => !isGatewayEcho(type, time)) .map(([, time]) => time); const assistantLimit = context.latestAssistantRateLimit; if ( assistantLimit?.type != null && - !context.rateLimitResetTimes.has(assistantLimit.type) + !isGatewayEcho(assistantLimit.type, assistantLimit.resetAt) && + (!context.rateLimitResetTimes.has(assistantLimit.type) || + isGatewayEcho( + assistantLimit.type, + context.rateLimitResetTimes.get(assistantLimit.type), + )) ) { resetTimes.push(assistantLimit.resetAt); }