Skip to content

fix(conversation_loop): use _ra() to access _pool_may_recover_from_rate_limit#28189

Closed
medardoacevallos wants to merge 1 commit into
NousResearch:mainfrom
medardoacevallos:fix/conversation-loop-pool-recover-nameerror
Closed

fix(conversation_loop): use _ra() to access _pool_may_recover_from_rate_limit#28189
medardoacevallos wants to merge 1 commit into
NousResearch:mainfrom
medardoacevallos:fix/conversation-loop-pool-recover-nameerror

Conversation

@medardoacevallos

Copy link
Copy Markdown

Summary

One-line fix for a latent NameError on the rate-limit eager-fallback path.

agent/conversation_loop.py:2320 calls _pool_may_recover_from_rate_limit(...) as a bare name, but that symbol is defined in run_agent.py (line 239) and is never imported into agent/conversation_loop.py. Everywhere else in this file, run_agent symbols are reached through the _ra() lazy-import helper defined on lines 76–82 (also used on 553, 555, 3765, 3814). This single site was missed.

- pool_may_recover = _pool_may_recover_from_rate_limit(
+ pool_may_recover = _ra()._pool_may_recover_from_rate_limit(

Reproduction

Triggered when a provider returns a rate-limit / quota / billing error and a fallback_chain is configured. Observed in production on a homercrm profile gateway after the primary OpenAI Codex provider returned HTTP 429; the conversation crashed instead of switching to the fallback provider:

File ".../agent/conversation_loop.py", line 2320, in run_conversation
    pool_may_recover = _pool_may_recover_from_rate_limit(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
NameError: name '_pool_may_recover_from_rate_limit' is not defined

The existing tests in tests/run_agent/test_provider_fallback.py and tests/agent/test_gemini_fast_fallback.py exercise the function directly via from run_agent import _pool_may_recover_from_rate_limit, so they don't catch this call-site bug — they bypass the conversation-loop import scope.

Test plan

  • Manual: patched gateway restarted (launchd KeepAlive), production conversation that previously crashed now succeeds the rate-limit decision path
  • inspect.getsource(agent.conversation_loop) contains _ra()._pool_may_recover_from_rate_limit
  • (Suggested followup, not in this PR) Add a conversation-loop-level test that simulates a 429 with a configured fallback chain — the existing unit tests cover the helper but not the call site

Refs #11314, #13636 — the issues the existing comment block points to.

…te_limit

The bare-name reference at agent/conversation_loop.py:2320 raises
NameError because _pool_may_recover_from_rate_limit is defined in
run_agent.py and is never imported into agent/conversation_loop.py.
This module accesses run_agent symbols via the _ra() lazy-import
helper everywhere else (see the helper at lines 76-82, and call sites
at 553, 555, 3765, 3814); this single call site was missed.

Triggered only when a provider returns rate-limit / quota / billing
and a fallback_chain is configured — i.e. the rate-limit eager-fallback
decision path. Easy to miss in routine testing.

Refs NousResearch#11314, NousResearch#13636 (the issues the existing comment block points to).
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent loop, run_agent.py, prompt builder duplicate This issue or pull request already exists labels May 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #27359 — same one-line fix for NameError on _pool_may_recover_from_rate_limit() in conversation_loop.py after the run_agent.py extraction refactor. 15+ duplicate fix PRs already exist for this issue (#27370). Canonical fix PR: #27359.

@outsourc-e outsourc-e left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Validated locally on clean upstream/main worktree. Targeted fallback tests passed (28 passed). Narrow one-line call-site fix; no security concerns.

@teknium1

Copy link
Copy Markdown
Contributor

Closing as duplicate of #28159 by @AceWattGit, which has been merged via salvage PR #28345 (commit 25e0f4d). All three of your PRs converged on the same fix (routing the call through `_ra()`), and AceWattGit's version also ships an inspect-based regression test guarding the call shape. Thanks for spotting the NameError — community signal helped triage it fast.

@teknium1 teknium1 closed this May 19, 2026
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.

4 participants