Skip to content

fix(conversation_loop): NameError on rate-limit fallback path - #27945

Closed
ta3pks wants to merge 1 commit into
NousResearch:mainfrom
ta3pks:fix/rate-limit-fallback-nameerror
Closed

fix(conversation_loop): NameError on rate-limit fallback path#27945
ta3pks wants to merge 1 commit into
NousResearch:mainfrom
ta3pks:fix/rate-limit-fallback-nameerror

Conversation

@ta3pks

@ta3pks ta3pks commented May 18, 2026

Copy link
Copy Markdown

Summary

The eager-fallback path for 429 errors calls _pool_may_recover_from_rate_limit() as a bare name, but the function is defined in run_agent.py and is never imported into agent/conversation_loop.py. When this code path executes, it crashes with NameError instead of evaluating the pool-recovery check — which means the fallback chain never fires for single-credential providers that cannot rotate.

The Bug

# agent/conversation_loop.py:2320 — before fix
pool_may_recover = _pool_may_recover_from_rate_limit(
    agent._credential_pool,
    provider=agent.provider,
    base_url=getattr(agent, "base_url", None),
)

_pool_may_recover_from_rate_limit is a module-level function in run_agent.py (introduced in 1fc77f995). conversation_loop.py does not from run_agent import it, nor is it defined locally. Every other cross-module call in this file uses the _ra() lazy accessor pattern (e.g. _ra()._set_interrupt, _ra().handle_function_call).

The Fix

One-line change: _pool_may_recover_from_rate_limit(_ra()._pool_may_recover_from_rate_limit(

Why It Wasn't Caught

The code path only executes when both conditions are true:

  1. A 429/rate-limit error occurs
  2. The fallback chain has available entries (_fallback_index < len(_fallback_chain))

With few fallback entries or rare rate limits, the buggy line is never reached. In production, observed as cron jobs dying silently on 429 instead of falling through to the configured fallback_providers.

Test Plan

  • All 28 existing tests in tests/run_agent/test_provider_fallback.py and tests/agent/test_gemini_fast_fallback.py pass
  • Verified the function is accessible via _ra()._pool_may_recover_from_rate_limit at runtime
  • Manual: trigger a 429 against a single-credential provider with a fallback configured — confirm fallback activates instead of NameError

Introduced in 1fc77f995 (fix(agent): fall back on rate limit when pool has no rotation room).

…_rate_limit

The eager-fallback path on 429 calls _pool_may_recover_from_rate_limit()
as a bare name, but the function lives in run_agent.py and is never imported
into conversation_loop.py. When a rate-limit error actually reaches this
code path, it crashes with NameError instead of evaluating the pool-recovery
check — which means the fallback chain never fires for single-credential
providers that can't rotate.

Use _ra()._pool_may_recover_from_rate_limit() to access it through the
lazy run_agent reference, consistent with every other cross-module call
in this file.

The bug is latent because the code path only executes when BOTH conditions
are met: (1) a 429/rate-limit error occurs AND (2) the fallback chain has
available entries. With few fallback entries or rare rate limits, the buggy
line is never reached.

Introduced in 1fc77f9 (fix(agent): fall back on rate limit when pool has
no rotation room).

@bbernstein616 bbernstein616 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watchdog verification: one-line fix correctly resolves _pool_may_recover_from_rate_limit through the existing _ra() lazy run_agent accessor. Independently tested PR head 72dfb84: scripts/run_tests.sh tests/agent -k 'rate_limit or fallback' -q => 121 passed; ruff check agent/conversation_loop.py => passed. Claude scoped worker also reviewed PR head and ran scripts/run_tests.sh tests/run_agent/test_provider_fallback.py tests/agent/test_gemini_fast_fallback.py => 28 passed. Coverage caveat: existing tests do not drive the exact conversation_loop 429 branch end-to-end, but the static NameError fix is correct and low risk.

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists labels May 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #27359 / #27370 — this is the 14th+ duplicate fix PR for the _pool_may_recover_from_rate_limit NameError in conversation_loop.py. See #27370 for the tracking issue and #27359 for the canonical fix PR.

@ta3pks

ta3pks commented May 18, 2026

Copy link
Copy Markdown
Author

Duplicate of #27359 / #27370 — this is the 14th+ duplicate fix PR for the _pool_may_recover_from_rate_limit NameError in conversation_loop.py. See #27370 for the tracking issue and #27359 for the canonical fix PR.

Closing then sorry didnt check that first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint 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