fix(aux): trigger fallback on 429 rate-limit errors (salvage #13579)#20294
Merged
Conversation
When a provider returns a 429 rate-limit error (not billing-related),
the auxiliary client's call_llm/async_call_llm previously did NOT trigger
the fallback chain. This caused auxiliary tasks like session_search to
exhaust all 3 retries against the same rate-limited endpoint, losing
session metadata that depended on the summarization completing.
Root cause: `_is_payment_error()` only matched 429s containing billing
keywords ("credits", "insufficient funds", etc.). Provider-specific
rate-limit messages like Nous's "Hold up for a bit, you've exceeded the
rate limit on your API key" didn't match, so `_is_payment_error` returned
False, `_is_connection_error` returned False, and `should_fallback` was
False — all retries hit the same rate-limited provider.
Fix:
- New `_is_rate_limit_error()` function that detects 429 + rate-limit
keywords, generic 429 without billing keywords, and OpenAI SDK
`RateLimitError` class instances (which may omit .status_code).
- Updated `should_fallback` in both `call_llm` and `async_call_llm` to
include `_is_rate_limit_error`.
- Updated the max_tokens retry path to also check for rate-limit errors.
- Updated the reason string to include "rate limit".
This complements the Nous rate guard (PR #10568) which prevents new calls
to Nous when already rate-limited — this fix handles the case where a
request is already in flight when the 429 arrives.
Related: #8023, #12554, #11034
Co-authored-by: Zeejay <zjtan1@gmail.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.
Salvages @zeejaytan's PR #13579 onto current main (conflicts with main's newer Nous-auth-refresh + credential-refresh retry blocks resolved — both preserved).
What it does
Auxiliary calls that 429 with non-billing rate-limit text previously exhausted all retries against the same endpoint instead of falling back.
_is_payment_erroronly matched billing-keyword 429s, so Nous's 'Hold up for a bit' and similar generic rate-limit messages fell through. Adds_is_rate_limit_errorand includes it inshould_fallbackon both the sync and async paths.Changes
agent/auxiliary_client.py— new_is_rate_limit_errorhelper;should_fallbackin bothcall_llmandasync_call_llmnow or's in rate-limit; max_tokens retry path also checks.tests/agent/test_auxiliary_client.py— new coverage for 429 detection.scripts/release.py— AUTHOR_MAP entry for zeejaytan.Validation
tests/agent/test_auxiliary_client.py— 134 passed locally.Closes #13579 via salvage.