fix(ai): recognize LiteLLM context overflow errors (#60692)

This commit is contained in:
Aiden Cline
2026-10-30 15:40:56 -05:00
committed by GitHub
Unverified
parent 9321c2cec0
commit 208ea0e0f7
3 changed files with 24 additions and 0 deletions
+2
View File
@@ -42,6 +42,8 @@ const patterns = [
// Hugging Face Text Generation Inference, e.g. Together
/`inputs` tokens \+ `max_new_tokens` must be <= \d+/i,
/context window exceeds limit/i,
// LiteLLM's ContextWindowExceededError
/context window exceeded/i,
/exceeded model token limit/i,
/context[_ ]length[_ ]exceeded/i,
/context length is only \d+ tokens/i,
+2
View File
@@ -21,6 +21,8 @@ describe("provider error classification", () => {
"Prompt exceeds max length",
"The input is too long for the selected model.",
"This text request is too large for the model's configured input limit.",
// LiteLLM's own check, before it calls the model.
"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.",
]
expect(messages.every(isContextOverflow)).toBe(true)
+20
View File
@@ -5952,6 +5952,26 @@ describe("SessionRunnerLLM", () => {
})
}
scenario("compacts when the provider cuts an oversized prompt to its window and replies with nothing", function* (s) {
// Xiaomi MiMo answers an oversized prompt with HTTP 200, finish "length", no output, and a prompt count that fills
// the window instead of rejecting it.
s.currentModel = recoveryModel
yield* s.llm.push(
TestLLM.complete({ reason: { normalized: "length" }, usage: { inputTokens: 199_994, nonCachedInputTokens: 199_994, outputTokens: 0 } }),
TestLLM.text("## Objective\n- summary", "summary"),
TestLLM.text("Done", "done"),
)
yield* s.runPrompt("Large prompt")
expect(s.requests).toHaveLength(3)
expect(userTexts(s.requests[1]).at(-1)).toContain("Summarize only what the user and the assistant said and did")
expect((yield* s.messages).filter((message) => message.type === "compaction")).toMatchObject([
{ status: "completed" },
])
expect((yield* s.context).at(-1)).toMatchObject(Expected.assistant({ finish: "stop" }, [Expected.text("Done")]))
})
for (const tools of ["hosted", "unfinished"] as const) {
scenario(`caps output token limit continuations and resets for new input (${tools})`, function* (s) {
const toolEvents =