Skip to content

Commit c958c48

Browse files
committed
fix(claude): a 413 API error frame shows as it does on main
The adapter holds an API error frame only when its own text does not read as a 413, because a 413 failure shows the 413 guidance in place of the frame. A failure the retry budget substitutes now carries its own message as the text the held frame is compared with.
1 parent 2d78900 commit c958c48

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8972,6 +8972,41 @@ describe("ClaudeAdapterV2 background wake turns", () => {
89728972
apiErrorStatus: 429,
89738973
shown: true,
89748974
},
8975+
{
8976+
name: "keeps the CLI's API error frame when the failure rewrites a 413",
8977+
text: 'API Error: 413 {"type":"error","error":{"type":"request_too_large","message":"Request exceeds the maximum size"}}',
8978+
failure:
8979+
"This thread's request is too large for the provider (HTTP 413), so retrying fails the same way. Start a fresh session with /clear, or continue in a new thread.",
8980+
apiErrorStatus: 413,
8981+
shown: true,
8982+
},
8983+
{
8984+
name: "keeps the CLI's API error frame when the failure rewrites a 413 behind a control character",
8985+
text: "API Error:\u0000413 gateway rejected the request",
8986+
failure:
8987+
"This thread's request is too large for the provider (HTTP 413), so retrying fails the same way. Start a fresh session with /clear, or continue in a new thread.",
8988+
apiErrorStatus: 413,
8989+
shown: true,
8990+
},
8991+
{
8992+
name: "drops the CLI's API error frame when the failure redacts it",
8993+
text: "API Error: 400 https://gateway.example/v1/messages?api_key=test-key-123",
8994+
failure: "API Error: 400 https://gateway.example/v1/messages",
8995+
apiErrorStatus: 400,
8996+
shown: false,
8997+
},
8998+
{
8999+
name: "drops the CLI's API error frame when an error result lists the 413 guidance itself",
9000+
text: "This thread's request is too large for the provider (HTTP 413), so retrying fails the same way. Start a fresh session with /clear, or continue in a new thread.",
9001+
subtype: "error_during_execution",
9002+
errors: [
9003+
"This thread's request is too large for the provider (HTTP 413), so retrying fails the same way. Start a fresh session with /clear, or continue in a new thread.",
9004+
],
9005+
failure:
9006+
"This thread's request is too large for the provider (HTTP 413), so retrying fails the same way. Start a fresh session with /clear, or continue in a new thread.",
9007+
apiErrorStatus: 400,
9008+
shown: false,
9009+
},
89759010
{
89769011
name: "keeps the CLI's API error frame when the turn is interrupted",
89779012
text: "API Error: rejected",

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
226226
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
227227
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
228228
import {
229+
isRequestTooLargeMessage,
229230
makeProviderFailure,
230231
makeProviderRetryTurnItem,
231232
PROVIDER_RETRY_BUDGET_MS,
@@ -4616,6 +4617,14 @@ function failureRepeatsFrame(source: string | undefined, frameText: string): boo
46164617
return source.trim() === frame || uncappedProviderFailureMessage(source) === frame;
46174618
}
46184619

4620+
/** True when a failure built from `text`, or from its API error excerpt, shows the 413 guidance instead. */
4621+
function isRequestTooLargeFrame(text: string): boolean {
4622+
return (
4623+
isRequestTooLargeMessage(text) ||
4624+
isRequestTooLargeMessage(makeProviderFailure({ message: text }).message)
4625+
);
4626+
}
4627+
46194628
/** Exclude CLI-internal "[ede_diagnostic] ..." telemetry from error banners. */
46204629
function resultUserFacingError(result: SDKResultMessage): string | undefined {
46214630
const errors = "errors" in result && Array.isArray(result.errors) ? result.errors : [];
@@ -9439,7 +9448,12 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
94399448
const retryBudgetFailure = requested.context.retryBudgetFailure;
94409449
const input =
94419450
requested.status === "interrupted" && retryBudgetFailure !== undefined
9442-
? { ...requested, status: "failed" as const, failure: retryBudgetFailure }
9451+
? {
9452+
...requested,
9453+
status: "failed" as const,
9454+
failure: retryBudgetFailure,
9455+
failureSource: retryBudgetFailure.message,
9456+
}
94439457
: requested;
94449458
input.context.steersClosed = true;
94459459
yield* reasoningDeltas.flushTurn(input.context.nativeTurnId);
@@ -11998,7 +12012,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1199812012
if (heldApiError !== null && heldApiError.nativeItemId !== assistantText.nativeItemId) {
1199912013
yield* emitAssistantTextArtifacts({ context, ...heldApiError });
1200012014
}
12001-
if (message.type === "assistant" && message.error !== undefined) {
12015+
if (
12016+
message.type === "assistant" &&
12017+
message.error !== undefined &&
12018+
!isRequestTooLargeFrame(assistantText.text)
12019+
) {
1200212020
context.assistant.apiErrorFrame = assistantText;
1200312021
return;
1200412022
}

‎packages/provider-core/src/server/failure.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ export function uncappedProviderFailureMessage(message: string): string {
292292
return redactProviderFailureText(message) || DEFAULT_PROVIDER_FAILURE_MESSAGE;
293293
}
294294

295+
/** True when `makeProviderFailure` replaces `message` with the 413 guidance. */
296+
export function isRequestTooLargeMessage(message: string): boolean {
297+
return REQUEST_TOO_LARGE_STATUS.test(message) || REQUEST_TOO_LARGE_REASON.test(message);
298+
}
299+
295300
function boundedText(value: string, maxLength: number): string {
296301
const redacted = redactProviderFailureText(value);
297302
if (redacted.length <= maxLength) return redacted;

0 commit comments

Comments
 (0)