fix(fallback): NameError on 429 rate-limit — missing _pool_may_recover_from_rate_limit import#27433
Closed
Ding-tech777 wants to merge 1 commit into
Closed
Conversation
…limit
The run_agent.py refactor extracted fallback error-handling into
agent/conversation_loop.py but the call to _pool_may_recover_from_rate_limit
on line 2254 was left as a bare name without an import. When the primary
model hits a 429 rate limit the agent crashes with:
NameError: name '_pool_may_recover_from_rate_limit' is not defined
Use the existing _ra() lazy-import helper (already used by other
run_agent symbols in this file) to resolve the function at call time,
avoiding both the NameError and circular-import risk.
Adds regression tests in test_provider_fallback.py that verify the
_ra() path resolves the function and that arguments are forwarded
correctly.
Collaborator
Author
|
Thanks for triaging! Closing as duplicate of #27359 — confirmed the same fix. Added regression tests in this PR that may be useful if needed. |
This was referenced May 17, 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.
Bug
After the
run_agent.pyrefactor (splitting ~12k LOC into ~15 modules underagent/), the fallback rate-limit handling inagent/conversation_loop.pycalls_pool_may_recover_from_rate_limit()as a bare name — but the function is defined inrun_agent.pyand was never imported.When the primary model returns a 429 (rate limit or billing quota), the agent crashes with:
This breaks the entire fallback chain: the user sees the error and
/resetdoes not help because the import is missing at module level.Root Cause
The call site at
agent/conversation_loop.py:2254was moved fromrun_agent.pyduring the refactor but the import was not added. A top-levelfrom run_agent import _pool_may_recover_from_rate_limitwould risk circular imports sincerun_agent.pyimports fromagent/modules.Fix
Use the existing
_ra()lazy-import helper (already used by otherrun_agentsymbols inconversation_loop.py, e.g._ra()._set_interrupt(...),_ra().AIAgent._get_tool_call_name_static(...)) to resolve the function at call time:Testing
Added 3 regression tests in
tests/run_agent/test_provider_fallback.py:test_ra_resolves_pool_may_recover— verifies_ra()resolves the functiontest_call_with_none_returns_false— end-to-end: None pool → Falsetest_call_with_pool_passthrough— end-to-end: multi-credential pool → TrueAll 25 tests in the file pass (including 22 pre-existing + 3 new).
Files Changed
agent/conversation_loop.py_pool_may_recover_from_rate_limit(→_ra()._pool_may_recover_from_rate_limit(tests/run_agent/test_provider_fallback.py