fix: resolve NameError in fallback provider logic (_pool_may_recover_from_rate_limit)#27891
fix: resolve NameError in fallback provider logic (_pool_may_recover_from_rate_limit)#27891ketchalegend wants to merge 1 commit into
Conversation
…from_rate_limit) The function _pool_may_recover_from_rate_limit is defined in run_agent.py but called from agent/conversation_loop.py. Due to circular import constraints, conversation_loop.py uses a _ra() lazy import helper (import run_agent) to access symbols from run_agent.py, but this call site was missing the _ra(). prefix, causing a NameError at runtime when a rate-limited provider attempted fallback. This meant that users with fallback_providers configured never actually fell back — the error crashed the retry loop before _try_activate_fallback could run. Fixes the NameError: name '_pool_may_recover_from_rate_limit' is not defined that occurs when a primary provider (e.g. OpenAI Codex, GPT-5.5, Google Gemini) hits HTTP 429 / usage limit and fallback_providers are configured.
bbernstein616
left a comment
There was a problem hiding this comment.
Watchdog independent verification: checked out this PR in /tmp/hermes-pr27891, reviewed the one-line change in agent/conversation_loop.py, and ran scripts/run_tests.sh tests/run_agent/test_run_agent.py -q -> 336 passed in 55.72s. The change correctly resolves the lazy run_agent reference via _ra()._pool_may_recover_from_rate_limit, matching surrounding circular-import patterns. I don't have push/merge permission on this repo, so no merge attempted.
Closing as fixed-on-mainThanks for the patch — appreciated! Closing as redundant: the same one-line Several contributors converged on the same fix here (#27370, #27465, #27468, #27583, #27686, #27732, #27734, #27735, #27750, #27891, #27903, #28304) — your diagnosis was correct in every case. Sorry for the duplicate-work cleanup; the volume of independent reports made it hard to coordinate. |
Bug
When a primary provider (e.g. OpenAI Codex / GPT-5.5, Google Gemini) hits HTTP 429 or usage limit, and the user has
fallback_providersconfigured, Hermes crashes with:The error occurs at the eager-fallback check in
conversation_loop.pybefore_try_activate_fallbackis ever called, so the fallback chain never runs.Root Cause
The function
_pool_may_recover_from_rate_limitis defined inrun_agent.py(line 239) but called fromagent/conversation_loop.py. Due to circular import constraints, code inconversation_loop.pyuses a_ra()lazy-import helper to access symbols fromrun_agent.py. However this call site at line ~2320 used the bare name instead of_ra()._pool_may_recover_from_rate_limit(...).Fix
Changed the bare name call to use the
_ra()helper, consistent with every other cross-module reference in this file.Testing
All 28 related tests pass:
tests/run_agent/test_provider_fallback.pytests/agent/test_gemini_fast_fallback.pyFixes model fallback not triggering on HTTP 429 / rate limit for any user with
fallback_providersconfigured.