Skip to content

fix: increment request_count in least_used credential pool strategy#14631

Closed
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/least-used-strategy-request-count
Closed

fix: increment request_count in least_used credential pool strategy#14631
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/least-used-strategy-request-count

Conversation

@vominh1919

Copy link
Copy Markdown
Contributor

Problem

The least_used credential pool strategy selects entries via min(request_count), but never increments the counter. Since all entries start at request_count=0, the strategy degenerates to fill_first behavior — it always returns the first available entry with no actual load balancing.

Fix

Increments request_count on the selected entry after each select() call, and persists the update via _replace_entry().

Before vs After

Behavior Before After
Entry selection with 2 entries Always first Alternates
request_count after 3 selects 0, 0 2, 1

Tests

  • 1 new regression test in TestLeastUsedStrategy
  • Verifies request_count increments and alternation works

The least_used strategy selected entries via min(request_count) but
never incremented the counter. All entries stayed at count=0, so the
strategy degenerated to fill_first behavior with no actual load balancing.

Now increments request_count after each selection and persists the update.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder area/auth Authentication, OAuth, credential pools labels Apr 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #4453 — same root cause: least_used strategy missing request_count increment in select() of credential_pool.py.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the fix @vominh1919! This change has already landed on main.

  • Commit 461899894fix: increment request_count in least_used pool strategy — is present in the main branch history.
  • agent/credential_pool.py lines 830–833 confirm the exact min(request_count)replace(entry, request_count+1)_replace_entry() pattern from your PR.

Closing as implemented on main. The regression test you added (TestLeastUsedStrategy) also appears to have landed with it. Thanks for the contribution! 🎉

This is an automated hermes-sweeper review.

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

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants