The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 23:15 UTC
fix(server): preserve Claude final-result API error text (#19136)
Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Ibrahim Elkamali committed
Oct 20, 2026 at 07:24 UTC
55a8fe9a938c61ef6e6bce718c58647ebdb4c88d
2 files changed
+100
-3
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+93
-2
@@ -3642,6 +3642,97 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3642
),
3643
);
3644
3645
+ it.effect.each([
3646
+ {
3647
+ name: "an unflagged result with surrounding whitespace",
3648
+ isError: false,
3649
+ result: " API Error: 400 Request rejected by a safeguard.\n",
3650
+ expected: "API Error: 400 Request rejected by a safeguard.",
3651
+ },
3652
+ {
3653
+ name: "a secret crossing the truncation boundary",
3654
+ isError: true,
3655
+ result: `API Error: 400 ${"x".repeat(440)} {"token":"${"synthetic-secret".repeat(100)}"} ${"y".repeat(100)}`,
3656
+ expected: `API Error: 400 ${"x".repeat(440)} {"token":"[REDACTED]"} `.padEnd(500, "y"),
3657
+ },
3658
+ {
3659
+ name: "ordinary assistant text",
3660
+ isError: true,
3661
+ result: "I found three files.",
3662
+ expected: "Claude gave up after repeated API errors.",
3663
+ },
3664
+ {
3665
+ name: "a listed non-diagnostic error",
3666
+ isError: true,
3667
+ result: "API Error: 400 Request rejected.",
3668
+ errors: ["[ede_diagnostic] internal detail", "Tool execution failed: EACCES"],
3669
+ expected: "Tool execution failed: EACCES",
3670
+ },
3671
+ {
3672
+ name: "an HTTP 529 overload",
3673
+ isError: true,
3674
+ result: "API Error: 529 Specific overload detail.",
3675
+ apiErrorStatus: 529,
3676
+ expected: "Claude API is overloaded (529). Try again shortly.",
3677
+ },
3678
+ {
3679
+ name: "an HTTP 429 rate limit",
3680
+ isError: true,
3681
+ result: "API Error: 429 Specific rate limit detail.",
3682
+ apiErrorStatus: 429,
3683
+ expected: "Claude API rate limit reached. Try again later.",
3684
+ },
3685
+ {
3686
+ name: "a different terminal reason",
3687
+ isError: true,
3688
+ result: "API Error: 400 Request rejected.",
3689
+ terminalReason: "prompt_too_long" as const,
3690
+ expected:
3691
+ "Claude stopped: the prompt exceeds the model's context window. Run /compact or start a new thread.",
3692
+ },
3693
+ ])("reports terminal API error text for $name", (input) =>
3694
+ Effect.gen(function* () {
3695
+ const harness = yield* makeWakeHarness;
3696
+ const now = yield* DateTime.now;
3697
+ yield* harness.runtime.startTurn(
3698
+ makeClaudeTestTurnInput({
3699
+ threadId: harness.threadId,
3700
+ providerThread: harness.providerThread,
3701
+ now,
3702
+ attemptId: RunAttemptId.make("attempt-claude-specific-api-error"),
3703
+ text: "Continue.",
3704
+ attachments: [],
3705
+ }),
3706
+ );
3707
+ const apiErrorStatus = input.apiErrorStatus ?? 400;
3708
+ yield* Queue.offer(
3709
+ harness.sdkMessages,
3710
+ makeResultFrame({
3711
+ uuid: "00000000-0000-4000-8000-000000000699",
3712
+ result: input.result,
3713
+ terminalReason: input.terminalReason ?? "api_error",
3714
+ apiErrorStatus,
3715
+ isError: input.isError,
3716
+ ...(input.errors === undefined ? {} : { errors: input.errors }),
3717
+ }),
3718
+ );
3719
+
3720
+ const terminal = yield* Queue.take(harness.terminalReceipts);
3721
+ assert.equal(terminal.status, "failed");
3722
+ if (terminal.status !== "failed") return;
3723
+ assert.equal(terminal.failure.message, input.expected);
3724
+ assert.equal(terminal.failure.code, `api_error_${apiErrorStatus}`);
3725
+ assert.equal(
3726
+ terminal.failure.class,
3727
+ apiErrorStatus === 429 ? "usage_limit" : "provider_error",
3728
+ );
3729
+ }).pipe(
3730
+ Effect.provide(
3731
+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3732
+ ),
3733
+ ),
3734
+ );
3735
+
3736
it.effect("names an expired Claude login instead of the terminal API error", () =>
3737
Effect.gen(function* () {
3738
const configDir = "/synthetic/Claude config";
@@ -3673,7 +3764,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3764
}),
3765
makeResultFrame({
3766
uuid: "00000000-0000-4000-8000-000000000607",
3676
- result: "API Error",
3767
+ result: "API Error: 401 Credentials expired.",
3768
terminalReason: "api_error",
3769
}),
3770
]);
@@ -3932,7 +4023,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4023
harness.sdkMessages,
4024
makeResultFrame({
4025
uuid: "00000000-0000-4000-8000-000000000610",
3935
- result: "API Error",
4026
+ result: recovered ? "API Error" : "API Error: 400 Specific provider detail.",
4027
terminalReason: "api_error",
4028
}),
4029
);
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+7
-1
@@ -2958,11 +2958,17 @@ function providerFailureFromResult(
2958
? "usage_limit"
2959
: "provider_error";
2960
const listedError = resultUserFacingError(message);
2961
+ const apiErrorMessage =
2962
+ message.subtype === "success" &&
2963
+ message.terminal_reason === "api_error" &&
2964
+ message.result.trim().startsWith("API Error:")
2965
+ ? makeProviderFailure({ message: message.result }).message.slice(0, 500)
2966
+ : undefined;
2967
const structuredError = isOverloadedResult(message)
2968
? "Claude API is overloaded (529). Try again shortly."
2969
: message.subtype === "success" && message.api_error_status === 429
2970
? "Claude API rate limit reached. Try again later."
2965
- : terminalResultError(message.terminal_reason, failureHint);
2971
+ : terminalResultError(message.terminal_reason, failureHint ?? apiErrorMessage);
2972
if (message.subtype !== "success") {
2973
return makeProviderFailure({
2974
message: listedError ?? structuredError ?? message.errors.join("\n"),