Fix: add profile credential pool fallback to resolve_xai_http_credentials - #43513
Fix: add profile credential pool fallback to resolve_xai_http_credentials#43513palebluewanders wants to merge 3 commits into
Conversation
|
Verification: credential pool fallback looks correct Reviewed the new
One minor observation: the |
|
Thanks for this, @palebluewanders — same root cause, resolved a different way. This adds the credential-pool/profile fallback directly in Closing as superseded by #46614. Your diagnosis of the credential-pool-vs-singleton mismatch was spot on and matches what landed. |
What does this PR do?
When the xAI OAuth provider state (
providers.xai-oauth.tokens) is cleared by a terminal token-refresh failure (expired refresh token, tier gate, etc.),resolve_xai_http_credentialsfalls through to the bareXAI_API_KEYenv fallback — even when valid tokens exist in the credential pool written byhermes auth add xai-oauth. This causes thex_searchtool to silently degrade to synthesized responses with no real citations.The breakage happens because
hermes auth addwrites fresh tokens to the credential pool (credential_pool.xai-oauth) but thex_searchtool reads from the provider state singleton. xAI revokes the old refresh token on re-auth, the provider state gets cleared during the next refresh attempt, and the credential pool — which still has valid tokens — is never consulted.Add a third resolution tier that walks
<hermes_home>/profiles/*/auth.jsonand readsaccess_token+base_urlfrom each profile's credential poolxai-oauthentries. Usingget_hermes_home()(notHERMES_HOMEenv) avoids a silent CWD-relativePath("profiles")trap when the env var is unset or empty.Related Issue
Similar to PR #38440: fix(auth): resolve xAI OAuth credentials across profiles but fills the gap of when tokens exist in profile-specific
auth.json.Type of Change
Changes Made
Added a third credential-resolution fallback to
resolve_xai_http_credentials()intools/xai_http.py: when the runtime provider and provider state both fail, walk<hermes_home>/profiles/*/auth.jsonand readaccess_tokenfrom each profile'scredential_pool.xai-oauthentries. The first valid token wins (sorted alphabetically by profile name).How to Test
How to reproduce the bug
hermes auth add xai-oauth --no-browser)cat ~/.hermes/profiles/<profile>/auth.json | jq '.credential_pool["xai-oauth"][0].access_token'shows a valid token, butproviders["xai-oauth"].tokens.access_tokenis emptyHow to test the fix
x_search— should return real results with citationstests/tools/test_xai_credential_fallback.pyChecklist
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/A