fix: eager fallback on billing 402#23707
Open
luoxiao6645 wants to merge 1 commit into
Open
Conversation
Collaborator
1 task
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.
Summary
Fix eager fallback when the primary provider returns HTTP 402 /
FailoverReason.billing.The real bug was not in cron wiring.
cron/scheduler.pyalready passes bothfallback_modelandcredential_poolintoAIAgent. The failure was in theeager-fallback guard: billing exhaustion was grouped with rate limits, then
_pool_may_recover_from_rate_limit()could still block fallback while waitingfor credential-pool rotation.
That is wrong for billing/account exhaustion. Rotating credentials should not
delay fallback for
FailoverReason.billing.Fixes #23138.
Changes
_pool_may_recover_from_rate_limit()about the failover reasonFalseforFailoverReason.billingclassified.reasoninto the eager-fallback guard inrun_conversation()HTTP 402 -> immediate fallbackWhy this fixes the issue
Before this change, a primary
402 Insufficient Balancecould be treated as"maybe credential rotation can recover", which prevented eager fallback from
activating even though
fallback_providerswas configured.After this change,
402 -> FailoverReason.billingskips pool-rotation gatingand switches to the fallback provider immediately.
Validation
Passed:
venv\Scripts\python.exe -m pytest tests/run_agent/test_run_agent.py -k billing_error_triggers_eager_fallback_before_retry_budget -qvenv\Scripts\python.exe -m pytest tests/run_agent/test_provider_fallback.py tests/agent/test_credential_pool_routing.py tests/agent/test_error_classifier.py -q