fix(agent): rebind pool entry id after env credential refresh (salvage #79180) - #82149
Merged
Merged
Conversation
Per-turn .env adoption could rewrite agent.api_key while leaving _credential_pool_entry_id on a previously rotated fallback. The next 429 then marked the healthy fallback exhausted via credential_id precedence (#79156). - Sync pool entry id after a successful env credential refresh - First look does not stomp a pool-rotated key with the env primary - mark_exhausted_and_rotate prefers api_key_hint when it disagrees with credential_id Fixes #79156
Contributor
૮ >ﻌ< ა ci reviewran on d989b74
|
This was referenced Aug 9, 2026
19 tasks
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
Rate-limit rotation now quarantines the credential that is actually exhausted, instead of benching a healthy fallback key for days because the agent's pool entry id had gone stale.
Salvage of #79180 by @686f6c61 — cherry-picked onto current main with authorship preserved; applied cleanly, no follow-up fixes needed. Fixes #79156.
Root cause:
_try_refresh_env_client_credentialsadopts a key from the environment mid-run without callingsync_credential_pool_entry_id(), so the agent keeps pointing at the old pool entry.mark_exhausted_and_rotateresolves bycredential_idfirst — ignoring the disagreeingapi_key_hint— and quarantines the wrong entry: the healthy key gets a multi-day cooldown while the exhausted one stays live.Changes (3 layers)
run_agent.py: rebind the pool entry id right after adopting an env credential; don't treat a pool-rotated key as a boot-time env adoption.agent/credential_pool.py: whencredential_idandapi_key_hintdisagree, trust the hint (the key actually in use).tests/agent/test_credential_pool.py(+55) andtests/run_agent/test_env_credential_turn_refresh.py(+37).Validation
Duplicate #79224 (strict subset, filed ~80 min later) will be closed with credit once this lands. Contributor also flagged an adjacent
hermes auth resetno-op (_merge_disk_cooldown_stateresurrecting EXHAUSTED) — separate issue, not in scope here.Infographic