Skip to content

fix(error_classifier): read FastAPI-style {"detail": ...} error bodies; recognise session/weekly usage limits - #100783

Closed
i-Hun wants to merge 1 commit into
NousResearch:mainfrom
i-Hun:fix/error-classifier-detail-body
Closed

i-Hun wants to merge 1 commit into
NousResearch:mainfrom
i-Hun:fix/error-classifier-detail-body

Conversation

@i-Hun

@i-Hun i-Hun commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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 at error.message, message, errorMessage and errorArgs.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_000 and 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

  • New _detail_message(body) reads detail as a string, a dict (proxies nesting an OpenAI-ish object) or a list (FastAPI's own validation errors, keeping loc and type so the message stays actionable).
  • It is consulted after the existing keys in 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 descriptive detail is a format_error, not a compression trigger, even when str(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 through detail is still an overflow; error.message still wins over detail. Session and weekly limits classify as rate_limit.

Existing error-classifier / failover tests pass (191 tests).

…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>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Sep 2, 2026
@Enough1122

Copy link
Copy Markdown
Contributor

AI code review — automated review for reference; please use your judgment.

  • Correct fix: FastAPI/Starlette proxy errors ({"detail": "..."}) previously read as blank and tripped the "generic 400 on large session = context overflow" heuristic, forcing healthy sessions into the compression loop; _detail_message now surfaces the real rejection text (agent/error_classifier.py:2197).
  • The three detail shapes (str/dict/list) are handled defensively; list items get loc: msg (type) formatting that keeps FastAPI validation errors actionable, and no shape crashes.
  • Precedence is preserved: error.message still wins over detail, and a genuinely bare 400 on a large session still compresses — the control tests pin both behaviors.
  • New "session limit" / "weekly limit" / "resets " patterns correctly reclassify subscription-backed usage walls as transient rate_limit; the bare "resets " match is broad but only applies within the usage-limit context, low risk.
  • Tests are thorough, including SDK body-not-in-str(error) and detail-carried-overflow cases.

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>
@teknium1

Copy link
Copy Markdown
Collaborator

Thanks @i-Hun — the work in this PR has landed on main via:

Your contribution is credited there (cherry-picked authorship / co-author trailer or credit in the PR body; see the linked PR for what was kept and what was trimmed). Closing this one as landed / superseded so the backlog reflects reality. If something in your original diff is still missing on current main, please comment and we'll reopen or follow up.

@teknium1 teknium1 closed this Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants