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 21, 11:00 UTC
fix(server): an oversized provider request reads as too large, not raw 413 HTML (#37156)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Sudharsan committed
Nov 15, 2026 at 17:14 UTC
ff9dca8931f5d3f9b7392109121ade9de8cc295f
2 files changed
+39
-3
packages/provider-core/src/server/failure.test.ts
+26
@@ -59,6 +59,32 @@ it("redacts credentials whose key names end in a credential word", () => {
59
);
60
});
61
62
+it("reports an oversized provider request as not retryable instead of the gateway's error page", () => {
63
+ for (const message of [
64
+ "413 <html>\n<head><title>413 Request Entity Too Large</title></head>\n<body>\n<center><h1>413 Request Entity Too Large</h1></center>\n<hr><center>nginx</center>\n</body>\n</html>",
65
+ "unexpected status 413 Payload Too Large: request body exceeds the limit",
66
+ 'API Error: 413 {"type":"error","error":{"type":"request_too_large"}}',
67
+ ]) {
68
+ const failure = makeProviderFailure({ message, class: "provider_error", retryable: true });
69
+
70
+ assert.equal(failure.class, "provider_error");
71
+ assert.equal(failure.retryable, false);
72
+ assert.equal(
73
+ failure.message,
74
+ "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.",
75
+ );
76
+ }
77
+ for (const message of [
78
+ "Request too large for gpt-4o on tokens per min (TPM): Limit 30000, Requested 41300.",
79
+ "Rate limited after 413 requests.",
80
+ "Tool result content too large to return.",
81
+ ]) {
82
+ const failure = makeProviderFailure({ message, retryable: true });
83
+ assert.equal(failure.message, message);
84
+ assert.equal(failure.retryable, true);
85
+ }
86
+});
87
+
88
it("does not split a surrogate pair at the truncation boundary", () => {
89
const failure = makeProviderFailure({
90
message: `${"a".repeat(MAX_PROVIDER_FAILURE_MESSAGE_LENGTH - 2)}🚀tail`,
packages/provider-core/src/server/failure.ts
+13
-3
@@ -40,6 +40,12 @@ const MAX_PROVIDER_FAILURE_CODE_LENGTH = 128;
40
41
const DEFAULT_PROVIDER_FAILURE_MESSAGE = "Provider turn failed.";
42
43
+// Gateways answer an oversized body with a 413 page; resending the same history fails identically.
44
+const REQUEST_TOO_LARGE_STATUS = /^\s*(?:(?:API Error|Error|HTTP|status)(?:\s*:)?\s*)?413\b/iu;
45
+const REQUEST_TOO_LARGE_REASON = /\b(?:Request Entity|Payload|Content) Too Large\b/u;
46
+const REQUEST_TOO_LARGE_MESSAGE =
47
+ "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.";
48
+
49
const PROVIDER_FAILURE_CATEGORIES: Partial<
50
Record<string, { readonly summary: string; readonly guidance: string }>
51
> = {
@@ -276,8 +282,12 @@ export function makeProviderFailure(input: {
282
readonly resetAt?: string | null;
283
}): OrchestrationV2ProviderFailure {
284
const curated = curatedCauseMessages(input.cause);
279
- const rawMessage =
280
- input.message ?? curated.known ?? curated.category ?? DEFAULT_PROVIDER_FAILURE_MESSAGE;
285
+ const requestTooLarge =
286
+ input.message !== undefined &&
287
+ (REQUEST_TOO_LARGE_STATUS.test(input.message) || REQUEST_TOO_LARGE_REASON.test(input.message));
288
+ const rawMessage = requestTooLarge
289
+ ? REQUEST_TOO_LARGE_MESSAGE
290
+ : (input.message ?? curated.known ?? curated.category ?? DEFAULT_PROVIDER_FAILURE_MESSAGE);
291
const message = boundedText(rawMessage, MAX_PROVIDER_FAILURE_MESSAGE_LENGTH);
292
const rawCode = input.code ?? stringField(input.cause, "code") ?? null;
293
const code =
@@ -287,7 +297,7 @@ export function makeProviderFailure(input: {
297
class: input.class ?? "unknown",
298
message: message || DEFAULT_PROVIDER_FAILURE_MESSAGE,
299
code,
290
- retryable: input.retryable ?? null,
300
+ retryable: requestTooLarge ? false : (input.retryable ?? null),
301
...(input.class === "usage_limit" &&
302
input.resetAt != null &&
303
Number.isFinite(Date.parse(input.resetAt))