fix(xai-oauth): serialize refreshes across profiles - #81383
Conversation
|
Maintainer request: this PR (and several sibling fork PRs from the same contributor) have Could a NousResearch maintainer please click Approve and run workflows on this PR (and, if convenient, the related open PRs from @alexgunsberg)? Happy to rebase anything that has gone stale once checks can run. Related open PRs currently also showing zero checks: #81802, #81927, #82508, #82537, #82607, #82608, #83155, #83181, #83183, #83337. |
|
Independent confirmation of this race from a production multi-profile deployment (10 profile gateways, per-profile HERMES_HOME, shared root grant): repeated xai-oauth grants died within minutes of One adjacent bug worth a look while in this code: on terminal refresh failure the quarantine path writes the emptied provider state into the active profile's store, which creates a shadowing |
Problem
xAI rotates OAuth refresh tokens after each use. In profile mode, Hermes previously serialized refreshes only on each profile's own
auth.lock. Two profiles could therefore hold different locks while spending the same global-root fallback token. A parallel worker burst made one refresh succeed and the others replay the consumed token, permanently returninginvalid_grant/Refresh token has been revoked.The credential-pool path had the same cross-profile gap: each profile's local pool mirror could remain stale even after another profile rotated the root singleton.
Fix
Regression coverage
The new threaded regression creates two profile auth stores sharing one root xAI grant and starts simultaneous refreshes through both runtime paths:
resolve_xai_oauth_runtime_credentials()load_pool("xai-oauth").select()Before the fix, both tests observe two refresh POSTs. After the fix, exactly one refresh occurs and both profiles receive the rotated access token.
Verification
61 passedacross the new regression and existing xAI auth/pool/recovery suitesruff checkpassed on changed filescompileallpassed on changed files