@@ -3017,7 +3017,65 @@ describe("ClaudeAdapterV2 background wake turns", () => {
30173017 ),
30183018 );
30193019
3020- it.effect.each([429, 401, 529])(
3020+ it.effect.each([
3021+ { status: 503, cooldown: "4m 6s", seconds: 246 },
3022+ { status: 503, cooldown: "1h 2m 3s", seconds: 3723 },
3023+ { status: 503, cooldown: "7s", seconds: 7 },
3024+ { status: 503, cooldown: "0s", seconds: 0 },
3025+ { status: 503, cooldown: "unknown", seconds: 0 },
3026+ { status: 503, cooldown: "999999999999999999999999h", seconds: 0 },
3027+ { status: 503, cooldown: "4m 6s", seconds: 0, errorType: "overloaded_error" },
3028+ { status: 401, cooldown: "4m 6s", seconds: 0 },
3029+ ])("recovers wrapped gateway limits with status $status and cooldown $cooldown", (input) =>
3030+ Effect.gen(function* () {
3031+ const harness = yield* makeWakeHarness;
3032+ const now = yield* DateTime.now;
3033+ yield* harness.runtime.startTurn(
3034+ makeClaudeTestTurnInput({
3035+ threadId: harness.threadId,
3036+ providerThread: harness.providerThread,
3037+ now,
3038+ attemptId: RunAttemptId.make("attempt-gateway-limit"),
3039+ text: "Continue.",
3040+ attachments: [],
3041+ }),
3042+ );
3043+ yield* Queue.offerAll(harness.sdkMessages, [
3044+ makeAssistantErrorFrame({
3045+ uuid: "00000000-0000-4000-8000-000000000652",
3046+ error: "server_error",
3047+ }),
3048+ makeResultFrame({
3049+ uuid: "00000000-0000-4000-8000-000000000653",
3050+ 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}).`,
3051+ terminalReason: "api_error",
3052+ isError: true,
3053+ apiErrorStatus: input.status,
3054+ }),
3055+ ]);
3056+ const terminal = yield* Queue.take(harness.terminalReceipts);
3057+ assert.equal(terminal.status, "failed");
3058+ if (terminal.status !== "failed") return;
3059+ assert.equal(terminal.failure.class, input.seconds > 0 ? "usage_limit" : "provider_error");
3060+ if (input.seconds > 0) {
3061+ assert.equal(terminal.failure.retryable, true);
3062+ assert.equal(
3063+ terminal.failure.resetAt,
3064+ DateTime.formatIso(
3065+ DateTime.makeUnsafe(DateTime.toEpochMillis(now) + input.seconds * 1_000),
3066+ ),
3067+ );
3068+ } else {
3069+ assert.isUndefined(terminal.failure.resetAt);
3070+ }
3071+ }).pipe(
3072+ Effect.provide(
3073+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3074+ ),
3075+ ),
3076+ );
3077+
3078+ it.effect.each([429, 401, 503, 529])(
30213079 "classifies the current Claude API status %s after rate-limit evidence",
30223080 (apiErrorStatus) =>
30233081 Effect.gen(function* () {
0 commit comments