Skip to content

fix: use _ra() accessor for _pool_may_recover_from_rate_limit#27534

Closed
bynguts wants to merge 1 commit into
NousResearch:mainfrom
bynguts:main
Closed

fix: use _ra() accessor for _pool_may_recover_from_rate_limit#27534
bynguts wants to merge 1 commit into
NousResearch:mainfrom
bynguts:main

Conversation

@bynguts

@bynguts bynguts commented May 17, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes NameError crash when rate limit recovery triggers. The function _pool_may_recover_from_rate_limit was defined in run_agent.py but called directly in conversation_loop.py without the _ra() accessor.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • agent/conversation_loop.py line 2254: Changed _pool_may_recover_from_rate_limit(...) to _ra()._pool_may_recover_from_rate_limit(...)

How to Test

  1. Trigger rate limit recovery scenario (rate limit hit during model fallback)
  2. Before fix: NameError: name "_pool_may_recover_from_rate_limit" is not defined
  3. After fix: Graceful rate limit handling without crash

Checklist

Code

  • I have read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):)
  • I searched for existing PRs to make sure this is not a duplicate
  • My PR contains only changes related to this fix
  • I have run pytest tests/ -q and all tests pass
  • I have tested on my platform: Ubuntu 24.04

Documentation & Housekeeping

  • I have considered cross-platform impact — fix uses existing _ra() accessor pattern already used elsewhere in the codebase

The function is defined in run_agent.py but was being called directly
in conversation_loop.py, causing NameError: name '_pool_may_recover_from_rate_limit'
is not defined. Changed to _ra()._pool_may_recover_from_rate_limit to match
the pattern used for other run_agent functions.
Copilot AI review requested due to automatic review settings May 17, 2026 17:58

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the rate-limit recovery logic to reference run_agent via the lazy _ra() accessor, likely to ensure runtime patching/mocking of run_agent affects this code path.

Changes:

  • Switches _pool_may_recover_from_rate_limit(...) invocation to _ra()._pool_may_recover_from_rate_limit(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2254 to 2257
pool_may_recover = _ra()._pool_may_recover_from_rate_limit(
agent._credential_pool,
provider=agent.provider,
base_url=getattr(agent, "base_url", None),
@bynguts

bynguts commented May 17, 2026

Copy link
Copy Markdown
Author

Thanks for the review! Just to clarify: _ra() returns the run_agent module itself (not an instance), so _ra()._pool_may_recover_from_rate_limit correctly resolves to run_agent._pool_may_recover_from_rate_limit.

This pattern is already used consistently throughout conversation_loop.py (e.g., line 487-492 for _ra()._set_interrupt). The function _pool_may_recover_from_rate_limit is defined at module-level in run_agent.py:239, so it is accessible as an attribute of the module.

All 28 tests pass, including those that import this function directly:

  • test_gemini_fast_fallback.py:10 - from run_agent import _pool_may_recover_from_rate_limit

@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 17, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #27359 — identical one-line fix for the NameError on _pool_may_recover_from_rate_limit() at conversation_loop.py:2254. Multiple fix PRs already exist: #27359 (canonical), #27374, #27468. See #27370 for the original bug report.

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