fix(cron): fallback providers when OAuth token refresh returns 429 - #46535
fix(cron): fallback providers when OAuth token refresh returns 429#46535immuhammadfurqan wants to merge 1 commit into
Conversation
The except Exception handler in cron/scheduler.py raised RuntimeError immediately without consulting the fallback_providers chain. This caused cron jobs using OAuth providers (e.g. openai-codex) to crash when the primary credential pool was exhausted and the token refresh endpoint returned HTTP 429, rather than falling back to a configured alternative. Now the Exception handler mirrors the existing AuthError handler and walks fallback_providers/fallback_model before giving up. Secondary fix: stop forwarding a fully-exhausted credential pool to AIAgent. pool.has_available() guards the assignment so that a pool with entries but no usable tokens does not prevent the agent-level fallback chain from firing. Fixes NousResearch#46511
|
Code Review — clean ✅ Reviewed the full diff (2 files, +222/-9). Findings:
No issues found. The fix is well-scoped and the tests document the intended behavior clearly. |
|
Thanks for the focused cron investigation. This is already implemented on current
|
Summary
Fixes #46511 — cron jobs using OAuth providers (e.g.
openai-codex) crashed withRuntimeErrorwhen the credential pool was exhausted and the primary provider resolution failed with a non-AuthErrorexception (e.g. HTTP 429 from the token refresh endpoint), instead of using the configuredfallback_providerschain.except Exceptionhandler incron/scheduler.pynow walksfallback_providers/fallback_modelbefore raisingRuntimeError, mirroring the existingAuthErrorhandler above it.pool.has_available()guards thecredential_poolassignment so a fully-exhausted pool (entries exist but all on cooldown) is no longer forwarded toAIAgent, allowing the agent-level fallback chain to fire cleanly.Root cause
resolve_codex_runtime_credentials()reads an expired OAuth access token, attemptsrefresh_codex_oauth_pure(), and the OpenAI token refresh endpoint returns HTTP 429. This raises a plainException(notAuthError). Theexcept AuthErrorhandler already had correct fallback logic; theexcept Exceptionhandler did not.Test plan
test_non_auth_exception_uses_fallback_providers— primary raises plainException, job succeeds viafallback_providerstest_non_auth_exception_no_fallback_raises— no fallback configured, job fails cleanlytest_all_fallbacks_exhausted_raises— all fallback entries also fail, job fails cleanlytest_exhausted_pool_not_passed_to_agent—has_available()=Falseresults incredential_pool=Nonein AIAgent kwargstest_available_pool_is_passed_to_agent—has_available()=Truepool is forwarded as expected