@devries-cameron20 / t3code-1 / commits / 487733ba0a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): recover Claude cooldown reset times from proxy errors (#36642)

Co-authored-by: greyxp1 <greyxp999@gmail.com> Co-authored-by: Grey <120752906+greyxp1@users.noreply.github.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Julius Marminge committed Nov 14, 2026 at 02:27 UTC 487733ba0a06dcd2362f1a3efc2add8caac06c19
2 files changed +71 -18
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+48 -4
@@ -8918,6 +8918,25 @@ describe("ClaudeAdapterV2 background wake turns", () => {
8918 { status: 503, cooldown: "999999999999999999999999h", seconds: 0 },
8919 { status: 503, cooldown: "4m 6s", seconds: 0, errorType: "overloaded_error" },
8920 { status: 401, cooldown: "4m 6s", seconds: 0 },
8921 + { status: 429, cooldown: "1h2m3s", seconds: 3723, proxy: true, sdkResetSeconds: 60 },
8922 + { status: 429, cooldown: "1h2m3s", seconds: 7200, proxy: true, sdkResetSeconds: 7200 },
8923 + { status: 429, cooldown: "1h2m3s", seconds: 0, proxy: true, sdkResetSeconds: null },
8924 + {
8925 + status: 429,
8926 + cooldown: "nested 1h",
8927 + seconds: 0,
8928 + proxy: true,
8929 + result:
8930 + "API Error: Request rejected (429) · All credentials for model claude-opus-5-5 are cooling down (last error: rate_limit_error (reset after 1h))",
8931 + },
8932 + {
8933 + status: 429,
8934 + cooldown: "outer cooldown",
8935 + seconds: 60,
8936 + proxy: true,
8937 + result:
8938 + "API Error: Request rejected (429) · All credentials for model claude-opus-5-5 are cooling down (reset after 1m) (last error: All credentials for model upstream are cooling down (reset after 1h))",
8939 + },
8940 ])("recovers wrapped gateway limits with status $status and cooldown $cooldown", (input) =>
8941 Effect.gen(function* () {
8942 const harness = yield* makeWakeHarness;
@@ -8933,13 +8952,35 @@ describe("ClaudeAdapterV2 background wake turns", () => {
8952 }),
8953 );
8954 yield* Queue.offerAll(harness.sdkMessages, [
8955 + ...(input.sdkResetSeconds !== undefined
8956 + ? [
8957 + claudeSdkFrame({
8958 + type: "rate_limit_event",
8959 + rate_limit_info: {
8960 + status: "rejected",
8961 + rateLimitType: "five_hour",
8962 + ...(input.sdkResetSeconds === null
8963 + ? {}
8964 + : {
8965 + resetsAt: DateTime.toEpochMillis(now) / 1000 + input.sdkResetSeconds,
8966 + }),
8967 + },
8968 + uuid: "00000000-0000-4000-8000-000000000651",
8969 + session_id: WAKE_NATIVE_SESSION,
8970 + }),
8971 + ]
8972 + : []),
8973 makeAssistantErrorFrame({
8974 uuid: "00000000-0000-4000-8000-000000000652",
8938 - error: "server_error",
8975 + error: input.proxy ? "rate_limit" : "server_error",
8976 }),
8977 makeResultFrame({
8978 uuid: "00000000-0000-4000-8000-000000000653",
8942 - result: `API Error: ${input.status} [claude/claude-opus-5-5] [429]: {"type":"error","error":{"type":"${input.errorType ?? "rate_limit_error"}","message":"Please try again later."}} (reset after ${input.cooldown}).`,
8979 + result:
8980 + input.result ??
8981 + (input.proxy
8982 + ? `API Error: Request rejected (429) · All credentials for model claude-opus-5-5 are cooling down (reset after ${input.cooldown}) (last error: rate_limit_error: Please try again later.)`
8983 + : `API Error: ${input.status} [claude/claude-opus-5-5] [429]: {"type":"error","error":{"type":"${input.errorType ?? "rate_limit_error"}","message":"Please try again later."}} (reset after ${input.cooldown}).`),
8984 terminalReason: "api_error",
8985 isError: true,
8986 apiErrorStatus: input.status,
@@ -8948,7 +8989,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
8989 const terminal = yield* Queue.take(harness.terminalReceipts);
8990 assert.equal(terminal.status, "failed");
8991 if (terminal.status !== "failed") return;
8951 - assert.equal(terminal.failure.class, input.seconds > 0 ? "usage_limit" : "provider_error");
8992 + assert.equal(
8993 + terminal.failure.class,
8994 + input.seconds > 0 || input.proxy ? "usage_limit" : "provider_error",
8995 + );
8996 if (input.seconds > 0) {
8997 assert.equal(terminal.failure.retryable, true);
8998 assert.equal(
@@ -8958,7 +9002,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
9002 ),
9003 );
9004 } else {
8961 - assert.isUndefined(terminal.failure.resetAt);
9005 + assert.equal(terminal.failure.resetAt, input.proxy ? null : undefined);
9006 }
9007 }).pipe(
9008 Effect.provide(
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+23 -14
@@ -4637,7 +4637,13 @@ function providerFailureFromResult(
4637 const resetAt =
4638 apiErrorStatus === 429 && message.result.startsWith("API Error:")
4639 ? gatewayCooldownResetAt(
4640 - /\(reset after (?:(\d+)h ?)?(?:(\d+)m ?)?(?:(\d+)s)?\)/.exec(message.result),
4640 + // CLIProxyAPI nests upstream errors in its message; only its own cooldown counts.
4641 + (message.result.startsWith(
4642 + "API Error: Request rejected (429) · All credentials for model ",
4643 + )
4644 + ? /^API Error: Request rejected \(429\) · All credentials for model [^\s()]+ are cooling down \(reset after (?:(\d+)h ?)?(?:(\d+)m ?)?(?:(\d+)s)?\)/
4645 + : /\(reset after (?:(\d+)h ?)?(?:(\d+)m ?)?(?:(\d+)s)?\)/
4646 + ).exec(message.result),
4647 receivedAt,
4648 )
4649 : undefined;
@@ -11469,18 +11475,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11475 usageLimited && message.subtype === "success" && message.local_command === "compact"
11476 ? context.compactionFailure
11477 : null;
11472 - const resetTimes = Array.from(context.rateLimitResetTimes.values());
11473 - const assistantLimit = context.latestAssistantRateLimit;
11474 - if (
11475 - assistantLimit?.type != null &&
11476 - !context.rateLimitResetTimes.has(assistantLimit.type)
11477 - ) {
11478 - resetTimes.push(assistantLimit.resetAt);
11479 - }
11480 - const resetAt =
11481 - resetTimes.length > 0 && resetTimes.every((time) => time !== null)
11482 - ? resetTimes.reduce((latest, time) => (time! > latest ? time! : latest), "")
11483 - : null;
11478 const resultFailure = interrupted
11479 ? null
11480 : limitedCompaction !== null
@@ -11495,9 +11489,24 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11489 failureHint,
11490 usageLimited,
11491 );
11492 + const resetTimes = Array.from(context.rateLimitResetTimes.values());
11493 + const assistantLimit = context.latestAssistantRateLimit;
11494 + if (
11495 + assistantLimit?.type != null &&
11496 + !context.rateLimitResetTimes.has(assistantLimit.type)
11497 + ) {
11498 + resetTimes.push(assistantLimit.resetAt);
11499 + }
11500 + if (resultFailure?.class === "usage_limit" && resultFailure.resetAt != null) {
11501 + resetTimes.push(resultFailure.resetAt);
11502 + }
11503 + const resetAt =
11504 + resetTimes.length > 0 && resetTimes.every((time) => time !== null)
11505 + ? resetTimes.reduce((latest, time) => (time! > latest ? time! : latest), "")
11506 + : null;
11507 const terminalFailure =
11508 resultFailure?.class === "usage_limit"
11500 - ? { ...resultFailure, resetAt: resetAt ?? resultFailure.resetAt ?? null }
11509 + ? { ...resultFailure, resetAt }
11510 : resultFailure;
11511 yield* finalizeActiveTurn({
11512 context,