Skip to content

fix(agent): wrap _pool_may_recover_from_rate_limit with _ra() lazy import#27374

Closed
sherman-yang wants to merge 1 commit into
NousResearch:mainfrom
sherman-yang:fix/pool-may-recover-namerror
Closed

fix(agent): wrap _pool_may_recover_from_rate_limit with _ra() lazy import#27374
sherman-yang wants to merge 1 commit into
NousResearch:mainfrom
sherman-yang:fix/pool-may-recover-namerror

Conversation

@sherman-yang

Copy link
Copy Markdown

Summary

Fixes #27370.

The eager-fallback path on rate-limit errors crashes with
NameError: name '_pool_may_recover_from_rate_limit' is not defined
because the refactor in 053025238 ("extract run_conversation to
agent/conversation_loop.py") missed one call site. The function lives
in run_agent.py:239, and every other reference to run_agent
helpers in conversation_loop.py is wrapped with the _ra() lazy
import. This one wasn't.

Change

One line, agent/conversation_loop.py:2254:

-                    pool_may_recover = _pool_may_recover_from_rate_limit(
+                    pool_may_recover = _ra()._pool_may_recover_from_rate_limit(
                         agent._credential_pool,
                         provider=agent.provider,
                         base_url=getattr(agent, "base_url", None),
                     )

Impact

Without this fix, any user with a fallback_providers chain that
contains a rate-limited or quota-exhausted provider sees the whole
conversation turn crash on 429/402, instead of cleanly switching to
the next provider. The whole point of _pool_may_recover_from_rate_limit
(introduced in 1fc77f995, "fall back on rate limit when pool has no
rotation room") is currently inert because the call site is unbound.

Test plan

  • Manually verified the fix locally: with the patch applied, a
    configured fallback chain that hits a 429 transitions to the next
    provider without raising NameError.
  • Existing CI / test suite — no new tests needed; this is a
    refactor regression and the fix restores the documented behaviour.

Notes

Reported and reproduced on v0.14.0 (2026-05-16). No upstream commits
yet attempt this fix; origin/main is still affected at the time of
this PR.

@cardtest15-coder

This comment was marked as spam.

@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 — both PRs apply the same one-line fix (prefixing _pool_may_recover_from_rate_limit with _ra(). at conversation_loop.py:2254). #27359 was triaged first.

@JeremyDev87

Copy link
Copy Markdown

ddalggak review — canonical-candidate conclusion, but not merge-ready without checks.

Blocking first: this PR has no current checks visible, so I would not treat it as ready yet.

Evidence checked:

Recommendation:

@AloisioMagalhaes

Copy link
Copy Markdown

Confirmacao de fix local (AloisioMagalhaes)

Apliquei exatamente este mesmo fix localmente e confirme:

Arquivo: agent/conversation_loop.py linha 2335
Diff:

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

Testes: 28/28 passaram em tests/agent/test_gemini_fast_fallback.py e tests/run_agent/test_provider_fallback.py.

Ambiente:

  • Hermes v0.14.0 (2026.05.18)
  • Python 3.11 / WSL Ubuntu
  • Provider principal: opencode-zen/deepseek-v4-flash-free
  • 12 fallback providers configurados

O fix restaura o comportamento documentado do fallback chain em caso de 429. Sem ele, o agente crasha com NameError antes de tentar qualquer fallback.

Recomendo merge — eh uma linha, sem side effects, e os testes existentes validam.

@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.

[Bug] NameError: '_pool_may_recover_from_rate_limit' is not defined in conversation_loop.py

7 participants