fix(agent): check credential pool exhaustion before restoring primary runtime (#15298) - #15434
Open
Tranquil-Flow wants to merge 1 commit into
Open
Tranquil-Flow wants to merge 1 commit into
Tranquil-Flow wants to merge 1 commit into
Conversation
5 tasks
This was referenced May 13, 2026
Closed
Tranquil-Flow
force-pushed
the
fix/restore-primary-check-credential-pool
branch
2 times, most recently
from
May 25, 2026 11:05
8c75dd0 to
287fccd
Compare
teknium1
reviewed
Jul 12, 2026
teknium1
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for targeting the repeated primary-restore retry path. The pool-aware gap still exists on current main: after the fixed cooldown expires, agent/agent_runtime_helpers.py:1163-1199 restores the snapshot key and client; the pool is only considered when has_available() is true at :1220-1222.
Problems
- The new direct comparison at
agent/agent_runtime_helpers.py:897-900does not cover named custom providers. Custom pools are keyedcustom:<name>while the agent runtime stayscustom(agent/credential_pool.py:117-120). Current main resolves this safely throughget_custom_provider_pool_key()atagent/agent_runtime_helpers.py:1235-1249. - Current HEAD deliberately tests the inverse empty-pool behavior:
tests/agent/test_restore_primary_pool_reselect.py:162-175expects the snapshot key to be restored when no pool credential is available. This PR needs to reconcile that contract, not just add parallel mock coverage.
Suggested changes
- Rework the gate against the current helper and reuse its canonical custom-pool matching logic.
- Add a real exhausted-pool regression case, including
custom:<name>, and update the existing empty-pool expectation if the intended contract is now to remain on fallback.
This is an automated hermes-sweeper review.
| # Also defer if the credential pool for the primary provider reports | ||
| # all credentials still exhausted — avoids burning retries while the | ||
| # provider's own cooldown hasn't elapsed. | ||
| if hasattr(agent, '_credential_pool') and agent._credential_pool is not None: |
Collaborator
There was a problem hiding this comment.
This direct provider equality misses named custom pools: their pool key is custom:<name> while the runtime provider remains custom. Please reuse the canonical custom-pool matching approach now used in restore_primary_runtime so an exhausted named custom endpoint is also gated.
… runtime (NousResearch#15298) After the 60-second rate-limit timer expires, restore_primary_runtime() attempted to restore the primary provider every turn even if the credential pool still marked all credentials as exhausted. This burned retries and generated noise during extended outages. Now, after the _rate_limited_until check, if the agent has a _credential_pool for the primary provider and the pool reports no available credentials (all exhausted), restoration is skipped. This integrates with the existing credential pool architecture (has_available / _mark_exhausted) rather than adding another independent timer. Adapted from the original PR: main has refactored _restore_primary_runtime into agent.agent_runtime_helpers.restore_primary_runtime; the gate now lives in the helper. Tests reach the helper transparently through the forwarder on AIAgent.
Tranquil-Flow
force-pushed
the
fix/restore-primary-check-credential-pool
branch
from
July 13, 2026 16:55
677b3ac to
0a5ef57
Compare
This branch has not been deployed
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.
What does this PR do?
_restore_primary_runtime()checks a 60-second rate-limit timer (_rate_limited_until) but does not consult the credential pool's exhaustion state. After the 60-second timer expires, it attempts to restore the primary provider every turn even if the credential pool still marks that provider as exhausted. This burns retries and generates noise during extended outages.Related Issue
Fixes #15298
Type of Change
Changes Made
run_agent.py— after the_rate_limited_untilcheck in_restore_primary_runtime(), added a guard that consultsself._credential_pool.has_available(). If the pool exists for the primary provider and reports all credentials exhausted, restoration is skipped. This integrates with the existingCredentialPoolarchitecture (which already tracks per-credential exhaustion with cooldowns) rather than adding another independent timer.tests/run_agent/test_primary_runtime_restore.py— 4 new tests inTestCredentialPoolExhaustionGateHow to Test
pytest tests/run_agent/test_primary_runtime_restore.py::TestCredentialPoolExhaustionGate -v— 4 new tests cover:Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
N/A — see commit description and PR diff.