fix(auth): honor anthropic credential pool oauth - #26351
Closed
LeonSGP43 wants to merge 1 commit into
Closed
Conversation
5 tasks
|
Reporter here — thanks for the quick turnaround. The pool-API path with native refresh is the right call for our deployment: we hit this on a Hermes-PKCE-only setup with multiple cron jobs spanning token-expiry boundaries (e.g. morning briefings after overnight access-token expiry). A raw pool read without the refresh layer would have only pushed the failure to the next expiry window. Happy to validate against our PKCE-only deployment once merged. |
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?
Fixes Anthropic runtime credential resolution for OAuth-only Hermes setups.
resolve_anthropic_token()now consults the Anthropiccredential_poolafter Claude Code credentials and before theANTHROPIC_API_KEYfallback, so cron and runtime paths can reuse Hermes-native PKCE auth stored in~/.hermes/auth.json.Related Issue
Fixes #26344
Type of Change
Changes Made
_resolve_anthropic_pool_token()inagent/anthropic_adapter.pyto enumerate the Anthropiccredential_pool, refresh expiring OAuth entries through the existing pool machinery, and return the first available OAuth token.resolve_anthropic_token()priority order so Hermes PKCE entries in~/.hermes/auth.jsonare considered before falling back toANTHROPIC_API_KEY.tests/agent/test_anthropic_adapter.pycovering pool-only resolution and pool-OAuth precedence overANTHROPIC_API_KEY.How to Test
python3 -m pytest -o addopts='' tests/agent/test_anthropic_adapter.py -k 'resolve_anthropic_token or auto_refresh_on_expired_creds or static_env_oauth_token_does_not_block_refreshable_claude_creds'.python3 -m py_compile agent/anthropic_adapter.py tests/agent/test_anthropic_adapter.py.git diff --check.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
python3 -m pytest -o addopts='' tests/agent/test_anthropic_adapter.py -k 'resolve_anthropic_token or auto_refresh_on_expired_creds or static_env_oauth_token_does_not_block_refreshable_claude_creds'python3 -m py_compile agent/anthropic_adapter.py tests/agent/test_anthropic_adapter.pygit diff --checktests/agent/test_anthropic_adapter.pystill has 3 preexisting unrelated failures onmaininTestRunOauthSetupTokenbecause those tests patchsubprocess.runwith aMagicMocklacking.stdout, which breaks the keychain read path before this PR's code runs.