Fixed chats that are too large being sent again and again - #988
Merged
SommerEngineering merged 9 commits intoSep 22, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
When a chat grows past what the model accepts, some providers answer with 413 Request Entity Too Large instead of describing the problem in a 400 body. BaseProvider.SendRequest recognizes a full context window only in its BadRequest branch, by looking for "context" and "token" in the error body, so a 413 matches none of the status code branches and falls through to the retry loop.
That loop then resends the very same oversized request six times with growing delays — 4, 16, 64, and then 90 seconds each, so the user waits about six minutes and is finally told "Even after 6 retries, there were some problems with the request", which explains nothing.
The chat path now has its own branch for it, right before the BadRequest one, and says what a full context window means. It reuses the wording the 400 path already uses, so no new translations are needed. The embedding path already classified 413 correctly in ClassifyEmbeddingRequestFailure. The two classifications stay apart on purpose, as the comment there explains, so only the chat path was extended.
Not tested against a live provider: this needs a counterpart that actually answers 413, which I could not set up. The change is confined to one new status code branch that mirrors its neighbours.