Skip to content

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
NousResearch:mainfrom
Ding-tech777:fix/missing-pool-may-recover-import
Closed

fix(fallback): NameError on 429 rate-limit — missing _pool_may_recover_from_rate_limit import#27433
Ding-tech777 wants to merge 1 commit into
NousResearch:mainfrom
Ding-tech777:fix/missing-pool-may-recover-import

Conversation

@Ding-tech777

Copy link
Copy Markdown

Bug

After the run_agent.py refactor (splitting ~12k LOC into ~15 modules under agent/), the fallback rate-limit handling in agent/conversation_loop.py calls _pool_may_recover_from_rate_limit() as a bare name — but the function is defined in run_agent.py and was never imported.

When the primary model returns a 429 (rate limit or billing quota), the agent crashes with:

NameError: name '_pool_may_recover_from_rate_limit' is not defined

This breaks the entire fallback chain: the user sees the error and /reset does not help because the import is missing at module level.

Root Cause

The call site at agent/conversation_loop.py:2254 was moved from run_agent.py during the refactor but the import was not added. A top-level from run_agent import _pool_may_recover_from_rate_limit would risk circular imports since run_agent.py imports from agent/ modules.

Fix

Use the existing _ra() lazy-import helper (already used by other run_agent symbols in conversation_loop.py, e.g. _ra()._set_interrupt(...), _ra().AIAgent._get_tool_call_name_static(...)) to resolve the function at call time:

# Before (crashes):
pool_may_recover = _pool_may_recover_from_rate_limit(...)

# After (works):
pool_may_recover = _ra()._pool_may_recover_from_rate_limit(...)

Testing

Added 3 regression tests in tests/run_agent/test_provider_fallback.py:

  • test_ra_resolves_pool_may_recover — verifies _ra() resolves the function
  • test_call_with_none_returns_false — end-to-end: None pool → False
  • test_call_with_pool_passthrough — end-to-end: multi-credential pool → True

All 25 tests in the file pass (including 22 pre-existing + 3 new).

Files Changed

File Change
agent/conversation_loop.py _pool_may_recover_from_rate_limit(_ra()._pool_may_recover_from_rate_limit(
tests/run_agent/test_provider_fallback.py +3 regression tests

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

Copy link
Copy Markdown
Collaborator

Duplicate of #27359 — identical one-line fix (_pool_may_recover_from_rate_limit_ra()._pool_may_recover_from_rate_limit at conversation_loop.py:2254). #27374 also fixes the same issue. See #27370 for the bug report.

@Ding-tech777

Copy link
Copy Markdown
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.

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.

3 participants