fix(agent): import _pool_may_recover_from_rate_limit in conversation_loop (#27719)#27732
Closed
luyao618 wants to merge 1 commit into
Closed
fix(agent): import _pool_may_recover_from_rate_limit in conversation_loop (#27719)#27732luyao618 wants to merge 1 commit into
luyao618 wants to merge 1 commit into
Conversation
…loop
The eager rate-limit fallback path in agent/conversation_loop.py calls
_pool_may_recover_from_rate_limit, but the helper is defined in
run_agent.py and was never imported here. When a primary provider (e.g.
DeepSeek) returned a 429/quota error and a fallback chain (e.g.
OpenRouter) was configured, the codepath crashed with:
NameError: name '_pool_may_recover_from_rate_limit' is not defined
instead of switching to the configured fallback provider.
Use a lazy local import to avoid the circular import that a top-level
'from run_agent import ...' would introduce (run_agent.py already
imports extensively from agent/*).
Add a regression test that:
1. Confirms the helper is callable from run_agent.
2. Asserts agent/conversation_loop.py contains the explicit import so
the historical NameError can never silently regress.
Fixes NousResearch#27719
This was referenced May 18, 2026
This was referenced May 19, 2026
Collaborator
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. |
This was referenced May 19, 2026
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
Fixes #27719 —
NameError: name '_pool_may_recover_from_rate_limit' is not definedwhen the eager rate-limit fallback path fires.Root cause
agent/conversation_loop.pycalls_pool_may_recover_from_rate_limit(...)at the rate-limit/billing fallback branch (~L2254), but the helper is defined inrun_agent.pyand was never imported intoagent/conversation_loop.py.So whenever a primary provider returned a 429/quota error and a fallback chain was configured (e.g. DeepSeek exhausted → OpenRouter fallback as in the issue), the code crashed with
NameErrorinstead of switching to the fallback provider.grepconfirms the missing reference:Fix
Use a lazy local import right above the call site:
Why lazy:
run_agent.pyalready imports extensively fromagent/*(includingagent.conversation_loop), so a top-levelfrom run_agent import ...would create a circular import. The lazy import runs only when the rate-limit fallback branch is hit, which is a cold path.Test
Added
tests/agent/test_fallback_pool_recover_import.pywith two checks:_pool_may_recover_from_rate_limitis callable fromrun_agentandNoneshort-circuits toFalse.agent/conversation_loop.pyconfirms an explicitfrom run_agent import _pool_may_recover_from_rate_limitexists — so the historical NameError cannot silently regress.Scope
agent/conversation_loop.py— 1 line added (lazy import)tests/agent/test_fallback_pool_recover_import.py— new regression test