fix: wrap _pool_may_recover_from_rate_limit call through run_agent namespace

The conversation_loop.py references _pool_may_recover_from_rate_limit which
was defined in run_agent.py. After the conversation-loop extraction refactor,
the helper was no longer in the same module scope. Wrap the call as
_ra()._pool_may_recover_from_rate_limit() to route through the run_agent
monkeypatch namespace where the helper is available.

Adds regression test in test_gemini_fast_fallback.py.

Fixes: MAILROOM Email Triage NameError, OPS Execution Monitor NameError.
This commit is contained in:
AceWattGit 2026-05-18 20:04:51 -07:00 committed by Teknium
parent 2e09d2567c
commit 25e0f4d465
2 changed files with 17 additions and 1 deletions

View file

@ -2332,7 +2332,7 @@ def run_conversation(
# still recover. See _pool_may_recover_from_rate_limit
# for the single-credential-pool and CloudCode-quota
# exceptions. Fixes #11314 and #13636.
pool_may_recover = _pool_may_recover_from_rate_limit(
pool_may_recover = _ra()._pool_may_recover_from_rate_limit(
agent._credential_pool,
provider=agent.provider,
base_url=getattr(agent, "base_url", None),

View file

@ -5,8 +5,10 @@ rotation and fallback-provider activation. For CloudCode (Gemini CLI /
Gemini OAuth) the 429 is an account-wide throttle, so waiting for pool
rotation is pointless prefer fallback immediately.
"""
import inspect
from unittest.mock import MagicMock
from agent import conversation_loop
from run_agent import _pool_may_recover_from_rate_limit
@ -60,3 +62,17 @@ def test_exhausted_pool_skips_rotation():
def test_no_pool_skips_rotation():
assert _pool_may_recover_from_rate_limit(None) is False
def test_conversation_loop_resolves_pool_helper_through_run_agent_module():
"""Extracted conversation loop must honor tests/patches on run_agent.
conversation_loop intentionally lazy-loads run_agent via _ra(). If this
call site uses a bare imported helper, monkeypatching run_agent in tests (and
production wrappers that patch run_agent) will not propagate into the
extracted loop; older code also hit NameError in this branch.
"""
source = inspect.getsource(conversation_loop.run_conversation)
assert "_ra()._pool_may_recover_from_rate_limit(" in source
assert "pool_may_recover = _pool_may_recover_from_rate_limit(" not in source