You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Classify only HTTP 400 context-window overflows using canonical provider error fields and a conservative message fallback.
Raise provider-specific API-error subclasses across the OpenRouter tool-call, text-based, and Responses adapters, plus Requesty, so permanent failures abort immediately.
Preserve existing retries for unrelated 400 responses, transient 5xx responses, and network errors.
Independent corroboration from a black-box PoC (no source patching): against the shipped default stop_after_attempt(10), a context_length_exceeded HTTP 400 from the provider goes through up to 10 total attempts (1 initial plus 9 retries) before giving up, while a 401 correctly aborts at attempt 1. We also verified the bug is provider-symmetric: OpenRouter and Requesty share the same retry.py, so both exhibit the same retry waste. This PR's is_context_window_error() plus a dedicated ContextWindowError in abort_exceptions moves the 400 from "retry to budget" to "abort at attempt 1", and the added test proving generic 400/500/token_limit_exceeded still retry confirms it doesn't over-suppress. One scope note: only context_length_exceeded-shaped 400s abort; other permanent 4xx still retry to the budget, worth a follow-up.
Thanks for independently validating this. Agreed that broader permanent-4xx handling should remain a follow-up, this PR intentionally scopes the non-retry behavior to recognized context-window errors.
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
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.
Summary
Closes #921
Testing
pytest -q tests/models/test_context_window_errors.py tests/models/test_openrouter_textbased_model.py(16 passed)pytest -q -n auto(552 passed, 76 skipped)