Skip to content

fix(agent): share fallback pool recovery helper#27734

Closed
qWaitCrypto wants to merge 1 commit into
NousResearch:mainfrom
qWaitCrypto:fix/conversation-loop-pool-fallback-helper
Closed

fix(agent): share fallback pool recovery helper#27734
qWaitCrypto wants to merge 1 commit into
NousResearch:mainfrom
qWaitCrypto:fix/conversation-loop-pool-fallback-helper

Conversation

@qWaitCrypto

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR fixes a post-refactor fallback crash in the extracted agent conversation
loop.

agent/conversation_loop.py now owns the main run_conversation() body, but the
rate-limit fallback path still referenced _pool_may_recover_from_rate_limit()
as if it were local to that module. The helper was still defined in
run_agent.py, so quota/rate-limit fallback could raise NameError before the
configured fallback provider was attempted.

The fix moves the helper into a small shared module and imports it from the
conversation loop. run_agent._pool_may_recover_from_rate_limit remains as a
compatibility alias for existing tests and external patch/import sites.

Related Issue

Related to #27719 and #27370.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Added agent/fallback_utils.py with pool_may_recover_from_rate_limit().
  • Updated agent/conversation_loop.py to import and call the shared helper
    directly in the rate-limit fallback path.
  • Kept run_agent._pool_may_recover_from_rate_limit as a compatibility alias.
  • Updated the Gemini/CloudCode fallback regression test to verify the
    conversation loop imports the shared helper and the old run_agent alias
    still points to the same function.

How to Test

  1. Run the focused fallback tests:

    pytest -q tests/agent/test_gemini_fast_fallback.py tests/run_agent/test_provider_fallback.py -k "pool or cloudcode or fallback"
  2. Run ruff on the touched files:

    python -m ruff check agent/fallback_utils.py agent/conversation_loop.py run_agent.py tests/agent/test_gemini_fast_fallback.py
  3. Local results:

    29 passed in 70.91s
    All checks passed!
    

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: WSL/Linux checkout

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

$ pytest -q tests/agent/test_gemini_fast_fallback.py tests/run_agent/test_provider_fallback.py -k "pool or cloudcode or fallback"
.............................                                            [100%]
29 passed in 70.91s (0:01:10)

$ python -m ruff check agent/fallback_utils.py agent/conversation_loop.py run_agent.py tests/agent/test_gemini_fast_fallback.py
All checks passed!

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

Copy link
Copy Markdown
Collaborator

Duplicate of #27359 (fix for NameError on _pool_may_recover_from_rate_limit, #27370). This PR takes a different approach — extracting the helper into agent/fallback_utils.py — but addresses the same bug. Multiple competing fix PRs already exist: #27359, #27374, #27468, #27583.

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Closing as fixed-on-main

Thanks for the patch — appreciated! Closing as redundant: the same one-line _ra()._pool_may_recover_from_rate_limit(...) wrap landed via PR #28345 (salvage of @AceWattGit's PR #28159), merged 2026-05-19, before this PR could be reviewed. Same code change, just a different cherry-pick.

Several contributors converged on the same fix here (#27370, #27465, #27468, #27583, #27686, #27732, #27734, #27735, #27750, #27891, #27903, #28304) — your diagnosis was correct in every case. Sorry for the duplicate-work cleanup; the volume of independent reports made it hard to coordinate.

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