fix(aux): discard stale credentials after auth refresh - #72263
Closed
marveon wants to merge 1 commit into
Closed
Conversation
Collaborator
Duplicate of #62008: its current generic retry path already clears the stale request-scoped API key after a successful auxiliary auth refresh, including the Anthropic case covered here. |
Contributor
|
Thanks for the focused reproduction. The stale-key premise is confirmed on current main: the sync retry forwards Problems
Suggested changes
Automated hermes-sweeper review. |
Auxiliary auth-refresh retries could replay request-scoped or main-runtime credentials after the provider store was refreshed. Rebuild retry clients from the refreshed auth store instead of passing the token that just received a 401. Clear stale retry inputs for refreshable providers in both sync and async paths, including Anthropic and Codex-style auto routes, and cover the stale-input behavior with sync/async regression assertions.
marveon
force-pushed
the
fix/aux-anthropic-401-stale-token-retry
branch
from
July 31, 2026 19:18
a0c9968 to
0234c18
Compare
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
call_llm()/async_call_llm()correctly detect a 401 on an auxiliary request (context compression, title generation, ...), call_refresh_provider_credentials("anthropic")to rotate the Claude Code OAuth token on disk, and evict the cached client — but then retry using the exactresolved_api_keystring that had just been rejected._get_cached_client()treats an explicitapi_keyas authoritative and never re-derives it, so the "retry" silently rebuilds a client with the same dead token and 401s again.OAuth access token has been revokedevery ~5-9 minutes for 4+ hours while the main conversation loop (which resolves credentials independently viacredential_pool) kept working fine. Because context compression could never succeed, the session transcript grew unchecked to ~336k tokens, and the turn eventually died once the account also hit a real billing/usage cap and fell back to a local model with a much smaller context window.resolve_anthropic_token()before retrying, in both the sync and async auth-refresh-retry paths.Test plan
test_call_llm_anthropic_401_retry_does_not_reuse_stale_api_key, verified it fails against the pre-fix code (stashed the fix and re-ran) and passes with the fix.pytest tests/agent/test_auxiliary_client.py— 363 passed.pytest tests/agent/test_auxiliary_client_xai_oauth_recovery.py— all passed (unaffected provider paths).