fix(agent): wire up credential pool mark_used for least_used strategy#4453
Closed
dieutx wants to merge 1 commit into
Closed
fix(agent): wire up credential pool mark_used for least_used strategy#4453dieutx wants to merge 1 commit into
dieutx wants to merge 1 commit into
Conversation
9e6e11d to
ba40fc3
Compare
Contributor
Author
|
Rebased this onto current main and refreshed the least-used/request-count path.\n\nLocal: |
Collaborator
Collaborator
|
Likely duplicate of #15120 (merged). |
Contributor
|
Automated hermes-sweeper review: this PR’s credential-pool least_used fix is already present on current main via merged PR #15120. Thanks for the clear root-cause writeup and tests here; the merged salvage addressed the same behavior. Evidence:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The `least_used` credential pool strategy doesn't actually distribute load. All credentials stay at `request_count=0` forever, so `min()` always picks the first one — making `least_used` behave identically to `fill_first`. One key hits rate limits while others sit idle.
Root Cause
`mark_used()` in `credential_pool.py:399` increments `request_count`, but it's never called from any production code path. Searched the entire codebase (excluding tests) — zero callers. The runtime uses `mark_exhausted_and_rotate()` and `try_refresh_current()` but never `mark_used()`.
Additionally, `mark_used()` didn't call `_persist()`, so even if it were called, counts would reset on process restart.
Fix
`run_agent.py`: Call `self._credential_pool.mark_used()` after each successful API call (line 6503), right at `api_call_count += 1`.
`credential_pool.py`: Add `self._persist()` inside `mark_used()` so counts survive restarts.
Tests
4 tests: mark_used increments current, increments specific entry, persists to disk, and least_used rotates after mark.
```
4 passed
```