Conversation
…ognise session/weekly limits FastAPI/Starlette proxies (Open WebUI, LiteLLM, self-hosted gateways) report errors under `detail`. _classify_400() did not know that key, so a long descriptive 400 read as blank, tripped the "bare 400 on a large session = context overflow" heuristic and pushed a healthy session into the compression loop until it was auto-reset. Add _detail_message() (str / dict / list shapes) and consult it after the existing keys in classification and in the reported message. Also add "session limit" / "weekly limit" usage-limit patterns and the bare "resets " transient signal used by subscription-backed providers. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Contributor
|
teknium1
added a commit
that referenced
this pull request
Sep 19, 2026
… a bare 400
`agent/error_classifier.py::_body_message_candidates` never yielded the
FastAPI-style top-level `detail` key (string, or nested `{"message": ...}`),
so the Codex gateway's `{"detail": "The '<model>' model is not supported when
using Codex with a ChatGPT account."}` 400 read as a *bare* 400. On a large
session `_classify_400`'s generic-400 heuristic then classified it as
context_overflow: the loop burned compression attempts ("Context length
exceeded (109,962 tokens). Cannot compress further.") and, because
`is_client_error` excludes overflow, the entitlement marker from #106549 never
ran. Reading `detail` makes it a descriptive rejection (format_error: abort +
fall back, no compression) and surfaces the provider's text as the message
instead of `Error code: 400 - {...}`. The pydantic list shape of `detail` is
still handled by `_oversized_message_content_rejection` and is not yielded.
Slim re-port of #100783's detail-body half onto the rule-table classifier;
the session/weekly usage-limit half is a separate class and was dropped.
Refs #81558
Refs #106475
Co-authored-by: Oleg Nagornyy <nagornyy.o@gmail.com>
Collaborator
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.
Problem 1: FastAPI-style error bodies read as blank
Proxies built on FastAPI / Starlette (Open WebUI, LiteLLM, most self-hosted OpenAI-compatible gateways) report errors as
{"detail": "..."}._classify_400()only looked aterror.message,message,errorMessageanderrorArgs.reason. With none of those present, a long and perfectly descriptive rejection looked like an empty message, the "generic 400 on a large session means context overflow" heuristic fired, and a healthy session was pushed into the compression loop until it was auto-reset with "max compression attempts reached". The real cause (an upstream router error) never reached the user.This only triggers when
context_length <= 256_000and the session has more than 80 messages, so the same error is harmless on one model and kills the session on another. That made it hard to reproduce and easy to blame on the wrong thing.Problem 2: subscription usage walls classified as unknown or billing
Subscription-backed providers name the wall by its window: "You've hit your session limit · resets 2:20pm", "You've hit your weekly limit ...". Neither matched the usage-limit patterns, so the error classified as
unknown(no backoff, no Retry-After) or, when it did match, as a permanent billing failure because "resets 2:20pm" matched neither "resets at" nor "resets in".Fix
_detail_message(body)readsdetailas a string, a dict (proxies nesting an OpenAI-ish object) or a list (FastAPI's own validation errors, keepinglocandtypeso the message stays actionable).classify_api_error(),_classify_400()and_extract_message(), so the standard OpenAI shape keeps precedence."session limit"and"weekly limit"added to the usage-limit patterns; bare"resets "added to the transient signals.Tests
New
tests/agent/test_error_classifier_detail_body.py(11 tests). The fix: a descriptivedetailis aformat_error, not a compression trigger, even whenstr(error)does not carry the body; the operator sees the router text; dict and list shapes do not crash. Controls: a genuinely bare 400 on a large session still compresses; a real overflow reported throughdetailis still an overflow;error.messagestill wins overdetail. Session and weekly limits classify asrate_limit.Existing error-classifier / failover tests pass (191 tests).