Repository navigation
fix(llm): classify image-count limit errors as context overflow (#51073) - #52702
Open
JerryLiu369 wants to merge 1 commit into
Open
JerryLiu369 wants to merge 1 commit into
JerryLiu369 wants to merge 1 commit into
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #51073
Type of change
What does this PR do?
A session whose history exceeds the gateway's per-request image cap receives
400 [invalid_request_error] Too many images in request: N > 30on every full-history turn. That message was not recognised by the provider-error classifier, so the 400 was surfaced as a hardinvalid-requestfailure instead of a recoverable overflow. Overflow recovery never engaged, every retry repeated the identical 400, and the session was permanently bricked — matching the/compact-also-fails symptom in the report.This classifies the image-count limit as a context-overflow condition so the existing overflow-recovery path takes over.
packages/llm/src/provider-error.ts— added two patterns topatterns:/too many images?/i— matches the gateway message (Too many images in request: 31 > 30) and the upstream variant (.messages[0]: Too many images: max 600 images per request, got 601)./(?:exceed|maximum|limit).*images?|images?.*(?:exceed|maximum|limit)/i— covers upstream phrasings such asMaximum number of images exceeded/Image limit exceeded.Both require the word
image, so there is no bare/too many/pattern. The existingexclusions(throttling error:/rate limit/too many requests) are evaluated first, so rate-limit and throttling messages stay out of context-overflow.packages/llm/test/provider-error.test.ts— added 4 positive cases and a negative test asserting that throttling/flood messages containing "too many" are not classified as context overflow.No changes were needed in the recovery path itself.
executor.ts:262setsclassification: "context-overflow"fromisContextOverflow(body)on HTTP 400 and the protocol handlers (anthropic-messages,openai-responses,bedrock-converse) set it fromisContextOverflow(message);isContextOverflowFailurealready handles both theInvalidRequestReasonandProviderErrorEventshapes. With the classification in place,packages/core/src/session/runner/llm.ts:294runscompactAfterOverflow, whose summary request is text-only (compaction.tsserialises attachments to[Attached <mime>: <name>]placeholders and persiststext+recentas strings), so the rebuilt window carries no images and the retried request fits under the cap.This is the client-side half of the report's ask 2 ("classify
Too many images in request: ...as a recoverable/overflow condition so compaction can run"), and ties into #47493 and #39677. Ask 1 (uniform cap configuration across gateway routing targets) is server-side and out of scope here.How did you verify your code works?
bun test test/provider-error.test.tsfrompackages/llm: 3 pass, 0 fail.bun testfrompackages/llm(whole package): 299 pass, 30 skip, 0 fail, 667 expect() calls, 329 tests across 30 files — no regressions.Independent spot check of the classifier, including the exact production strings from the report:
Too many images in request: 31 > 30Too many images in request: 33 > 30Upstream request failed: [invalid_request_error] Too many images in request: 31 > 30.messages[0]: Too many images: max 600 images per request, got 601Maximum number of images exceeded/Image limit exceededToo many requests/Throttling error: too many requests/rate limit exceededUnsupported parameter: image_url.detail is not supportedBad request: model does not existScreenshots / recordings
N/A (provider error classification bugfix)
Checklist