Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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* () {
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 9 additions & 4 deletions apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading