Skip to content

fix: resolve NameError in fallback provider logic (_pool_may_recover_from_rate_limit)#27891

Closed
ketchalegend wants to merge 1 commit into
NousResearch:mainfrom
ketchalegend:fix/pool-may-recover-nameerror
Closed

fix: resolve NameError in fallback provider logic (_pool_may_recover_from_rate_limit)#27891
ketchalegend wants to merge 1 commit into
NousResearch:mainfrom
ketchalegend:fix/pool-may-recover-nameerror

Conversation

@ketchalegend

Copy link
Copy Markdown

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_providers configured, Hermes crashes with:

Error: name '_pool_may_recover_from_rate_limit' is not defined

The error occurs at the eager-fallback check in conversation_loop.py before _try_activate_fallback is ever called, so the fallback chain never runs.

Root Cause

The function _pool_may_recover_from_rate_limit is defined in run_agent.py (line 239) but called from agent/conversation_loop.py. Due to circular import constraints, code in conversation_loop.py uses a _ra() lazy-import helper to access symbols from run_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.

-                    pool_may_recover = _pool_may_recover_from_rate_limit(
+                    pool_may_recover = _ra()._pool_may_recover_from_rate_limit(

Testing

All 28 related tests pass:

  • tests/run_agent/test_provider_fallback.py
  • tests/agent/test_gemini_fast_fallback.py

Fixes model fallback not triggering on HTTP 429 / rate limit for any user with fallback_providers configured.

…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 bbernstein616 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent loop, run_agent.py, prompt builder duplicate This issue or pull request already exists labels May 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #27359 (fix PR) / #27370 (bug report). This is the same one-line _ra()._pool_may_recover_from_rate_limit() fix. Multiple prior PRs exist: #27374 (open), #27433, #27532, #27534, #27583, #27686, #27732, #27735 (all duplicates). See #27370 for tracking.

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Closing as fixed-on-main

Thanks for the patch — appreciated! Closing as redundant: the same one-line _ra()._pool_may_recover_from_rate_limit(...) wrap landed via PR #28345 (salvage of @AceWattGit's PR #28159), merged 2026-05-19, before this PR could be reviewed. Same code change, just a different cherry-pick.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder duplicate This issue or pull request already exists P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants