fix(conversation_loop): NameError on rate-limit — _pool_may_recover_from_rate_limit not in scope - #27608
Closed
abeperl wants to merge 1 commit into
Closed
Conversation
…r _pool_may_recover_from_rate_limit
run_conversation() in agent/conversation_loop.py calls
_pool_may_recover_from_rate_limit(), but the symbol is defined in
run_agent.py and not imported by this module. The call would raise
NameError: name '_pool_may_recover_from_rate_limit' is not defined
the moment a rate-limit or billing failover code path is entered.
Triggered in practice on any 429 from a provider — e.g. Gemini
RESOURCE_EXHAUSTED — and surfaces to users as a crashed turn:
Sorry, I encountered an error (NameError).
name '_pool_may_recover_from_rate_limit' is not defined
The unit tests in tests/agent/test_gemini_fast_fallback.py and
tests/run_agent/test_provider_fallback.py import the function
directly from run_agent, so they exercise the helper itself but
never hit the missing reference in conversation_loop.
Route the call through the existing _ra() lazy module accessor
(line 76), matching how this file already reaches other run_agent
symbols. Avoids the cross-module circular-import issue that
motivated _ra() in the first place.
Author
|
Thanks for the quick triage — closing as duplicate of #27370. Will track the canonical issue. Glad to know fixes are already in flight; the local one-line patch keeps our deployment healthy in the meantime. |
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.
What
run_conversation()inagent/conversation_loop.pycalls_pool_may_recover_from_rate_limit(), but the symbol is defined inrun_agent.py(line 239) and is not imported anywhere inconversation_loop.py. The call therefore raises:the moment the rate-limit / billing failover code path is entered (
agent/conversation_loop.py:2254on currentmain).Why this isn't caught by the existing tests
The two tests that exercise this helper —
tests/agent/test_gemini_fast_fallback.pytests/run_agent/test_provider_fallback.py— both import the function directly from
run_agent(from run_agent import _pool_may_recover_from_rate_limit). They confirm the helper itself behaves correctly but never exercise the call site insideconversation_loop.run_conversation(), so the missing reference is invisible to CI.Reproduction
Trigger any provider 429 on the primary while a fallback chain is configured. The simplest natural repro is a Gemini
RESOURCE_EXHAUSTED:In a deployed agent (Slack / API server), this surfaces to users as:
The whole turn dies instead of falling through to either pool rotation or the configured fallback provider — exactly the recovery behavior this code path is meant to gate.
Fix
One-line change: route the call through the existing
_ra()lazy module accessor (agent/conversation_loop.py:76) that this file already uses for otherrun_agentsymbols. Avoids the cross-module circular-import issue that motivated_ra()in the first place, and matches the convention noted in its docstring (so test patches onrun_agent.*continue to work).How to test
NameError.run_conversation()with a rate-limit-raising fake API client would prevent this class of bug going forward — happy to add one in a follow-up if maintainers prefer.Platforms tested
Linux (Ubuntu 24.04, Python 3.14.3), Hermes Agent v0.14.0 + this patch, running under systemd as the gateway service.