@@ -3146,6 +3146,114 @@ describe("ClaudeAdapterV2 background wake turns", () => {
31463146 ),
31473147 );
31483148
3149+ it.effect.each([
3150+ {
3151+ name: "an error result",
3152+ isError: true,
3153+ result: "API Error: 400 Request rejected by a safeguard.",
3154+ expected: "API Error: 400 Request rejected by a safeguard.",
3155+ },
3156+ {
3157+ name: "an unflagged API error result",
3158+ isError: false,
3159+ result: "API Error: 400 Request rejected by a safeguard.",
3160+ expected: "API Error: 400 Request rejected by a safeguard.",
3161+ },
3162+ {
3163+ name: "surrounding whitespace",
3164+ isError: true,
3165+ result: " API Error: 400 Request rejected.\n",
3166+ expected: "API Error: 400 Request rejected.",
3167+ },
3168+ {
3169+ name: "an overlong error",
3170+ isError: true,
3171+ result: `API Error: 400 ${"x".repeat(1_000)}`,
3172+ expected: `API Error: 400 ${"x".repeat(485)}`,
3173+ },
3174+ {
3175+ name: "an empty error",
3176+ isError: true,
3177+ result: "",
3178+ expected: "Claude gave up after repeated API errors.",
3179+ },
3180+ {
3181+ name: "ordinary assistant text",
3182+ isError: true,
3183+ result: "I found three files.",
3184+ expected: "Claude gave up after repeated API errors.",
3185+ },
3186+ {
3187+ name: "a listed non-diagnostic error",
3188+ isError: true,
3189+ result: "API Error: 400 Request rejected.",
3190+ errors: ["[ede_diagnostic] internal detail", "Tool execution failed: EACCES"],
3191+ expected: "Tool execution failed: EACCES",
3192+ },
3193+ {
3194+ name: "an HTTP 529 overload",
3195+ isError: true,
3196+ result: "API Error: 529 Specific overload detail.",
3197+ apiErrorStatus: 529,
3198+ expected: "Claude API is overloaded (529). Try again shortly.",
3199+ },
3200+ {
3201+ name: "an HTTP 429 rate limit",
3202+ isError: true,
3203+ result: "API Error: 429 Specific rate limit detail.",
3204+ apiErrorStatus: 429,
3205+ expected: "Claude API rate limit reached. Try again later.",
3206+ },
3207+ {
3208+ name: "a different terminal reason",
3209+ isError: true,
3210+ result: "API Error: 400 Request rejected.",
3211+ terminalReason: "prompt_too_long" as const,
3212+ expected: "Claude stopped: the prompt exceeds the model's context window.",
3213+ },
3214+ ])("reports terminal API error text for $name", (input) =>
3215+ Effect.gen(function* () {
3216+ const harness = yield* makeWakeHarness;
3217+ const now = yield* DateTime.now;
3218+ yield* harness.runtime.startTurn(
3219+ makeClaudeTestTurnInput({
3220+ threadId: harness.threadId,
3221+ providerThread: harness.providerThread,
3222+ now,
3223+ attemptId: RunAttemptId.make("attempt-claude-specific-api-error"),
3224+ text: "Continue.",
3225+ attachments: [],
3226+ }),
3227+ );
3228+ const apiErrorStatus = input.apiErrorStatus ?? 400;
3229+ yield* Queue.offer(
3230+ harness.sdkMessages,
3231+ makeResultFrame({
3232+ uuid: "00000000-0000-4000-8000-000000000699",
3233+ result: input.result,
3234+ terminalReason: input.terminalReason ?? "api_error",
3235+ apiErrorStatus,
3236+ isError: input.isError,
3237+ ...(input.errors === undefined ? {} : { errors: input.errors }),
3238+ }),
3239+ );
3240+
3241+ const terminal = yield* Queue.take(harness.terminalReceipts);
3242+ assert.equal(terminal.status, "failed");
3243+ if (terminal.status !== "failed") return;
3244+ assert.equal(terminal.failure.message, input.expected);
3245+ assert.equal(terminal.failure.code, `api_error_${apiErrorStatus}`);
3246+ assert.equal(
3247+ terminal.failure.class,
3248+ apiErrorStatus === 429 ? "usage_limit" : "provider_error",
3249+ );
3250+ }).pipe(
3251+ Effect.provide(
3252+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3253+ ),
3254+ ),
3255+ );
3256+
31493257 it.effect("names an expired Claude login instead of the terminal API error", () =>
31503258 Effect.gen(function* () {
31513259 const configDir = "/synthetic/Claude config";
@@ -3177,7 +3285,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
31773285 }),
31783286 makeResultFrame({
31793287 uuid: "00000000-0000-4000-8000-000000000607",
3180- result: "API Error",
3288+ result: "API Error: 401 Credentials expired. ",
31813289 terminalReason: "api_error",
31823290 }),
31833291 ]);
@@ -3238,7 +3346,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
32383346 harness.sdkMessages,
32393347 makeResultFrame({
32403348 uuid: "00000000-0000-4000-8000-000000000610",
3241- result: "API Error",
3349+ result: recovered ? "API Error" : "API Error: 400 Specific provider detail. ",
32423350 terminalReason: "api_error",
32433351 }),
32443352 );
0 commit comments