fix(aux): trigger fallback on 429 rate-limit errors in auxiliary client#13579
Closed
zeejaytan wants to merge 1 commit into
Closed
fix(aux): trigger fallback on 429 rate-limit errors in auxiliary client#13579zeejaytan wants to merge 1 commit into
zeejaytan wants to merge 1 commit into
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 NousResearch#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: NousResearch#8023, NousResearch#12554, NousResearch#11034
Co-authored-by: Zeejay <zjtan1@gmail.com>
Author
Real-world impactThis bug caused session search summarization to silently fail when Nous hit its RPH (requests per hour) limit. The symptom:
The user's wiki work (165+ papers, 123 wiki pages) persisted on disk, but the session index was gone because summarization never completed. How this interacts with existing PRs
ScopeOnly |
13 tasks
2 tasks
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.
What does this PR do?
Adds fallback triggering for 429 rate-limit errors in the auxiliary client (
call_llm/async_call_llm). Previously, only payment/billing errors (402) and connection errors triggered fallback — rate-limit 429s were silently retried against the same rate-limited provider until all attempts were exhausted.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. Soshould_fallback = _is_payment_error(...) or _is_connection_error(...)was always False for rate limits, and all 3 retries hit the same rate-limited endpoint.Real-world impact: Session search summarization lost session metadata when Nous hit RPH limits, because all retries failed against the same rate-limited provider instead of falling back to OpenRouter.
Changes
New:
_is_rate_limit_error()(after_is_payment_error)RateLimitErrorby class name (may omit.status_code) — covers the same bug as PR fix(agent): force 429 classification for RateLimitError + rate-limit cooldown on primary restore #8023_is_payment_error's job)Updated:
should_fallbackincall_llmandasync_call_llmUpdated:
reasonstringThree-way dispatch: "payment error" / "rate limit" / "connection error"
Updated: max_tokens retry path
Added
_is_rate_limit_errorto the fallthrough check alongside payment/connection.Tests
TestIsRateLimitError— 10 tests covering: rate-limit keywords, billing exclusions, generic 429,RateLimitErrorclass detection, non-429 errorsTestCallLlmPaymentFallback::test_429_rate_limit_triggers_fallback— end-to-end test showing 429 on primary → fallback to next providerAll 87 tests in
test_auxiliary_client.pypass.Relationship to existing PRs
run_agent.py— forceRateLimitErrorclassification + cooldownrun_agent.py— single-credential pool rotationrun_agent.py— fail over on provider overload (503/529)This PR fills the gap in
auxiliary_client.pywhich none of the above touch. It should land cleanly alongside any of them.How to test
Unit test (quick):