fix(ai): classify Workers AI context window rejections as context overflow (#52128)

This commit is contained in:
Aiden Cline
2026-09-29 23:49:03 -05:00
committed by GitHub
parent bf97a0443f
commit a80a00011d
2 changed files with 13 additions and 0 deletions
+2
View File
@@ -16,6 +16,8 @@ import {
const patterns = [
/prompt is too long/i,
/input is too long for requested model/i,
// Cloudflare Workers AI reports this as HTTP 413.
/exceeded this model context window limit/i,
/exceeds the context window/i,
/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\d,]+ tokens?|\s*\([\d,]+\))/i,
/input token count.*exceeds the maximum/i,
+11
View File
@@ -355,6 +355,17 @@ describe("provider error rawBody classification", () => {
}
})
test("classifies Workers AI context window rejections as context overflow despite HTTP 413", () => {
const message =
"AiError: Ai: The estimated number of input and maximum output tokens (900047) exceeded this model context window limit (32000). (17851589-f2e6-405d-b67c-5550e52ee1c1)"
const reason = classifyProviderFailure({
message,
status: 413,
rawBody: JSON.stringify({ errors: [{ message, code: 5021 }], success: false, result: {}, messages: [] }),
})
expect(reason._tag === "InvalidRequest" ? reason.classification : reason._tag).toBe("context-overflow")
})
test("classifies Google invalid API keys as authentication failures", () => {
const rawBody = JSON.stringify({
error: {