Skip to content

fix(auth): resolve xAI OAuth credentials across profiles + write rotated tokens back to root - #46614

Merged
kshitijk4poor merged 3 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/xai-oauth-profile-writethrough
Jun 15, 2026
Merged

kshitijk4poor merged 3 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/xai-oauth-profile-writethrough

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Contributor

Salvages #38440 (@capt-marbles) onto current main and pairs it with the write-through half of the fix so the cross-profile xAI OAuth grant stays coherent in both directions.

Commits

  1. fix(auth): resolve xAI OAuth credentials across profiles@capt-marbles' commit, verbatim, authorship preserved. _read_xai_oauth_tokens now resolves usable xAI OAuth tokens through profile state → profile credential pool → global-root store, so profile/cron contexts stop raising xai_auth_missing_access_token when usable credentials exist (fixes the read side of xAI OAuth credential resolution broken in Docker sandboxes (hermes-default, coding-agent) #39276).
  2. fix(auth): write rotated xAI OAuth tokens back to global root (Bug: profile auth shadowing + rotating refresh tokens guarantees grant revocation on multi-profile installs #43589) — the missing write-through. The read fallback alone made the Bug: profile auth shadowing + rotating refresh tokens guarantees grant revocation on multi-profile installs #43589 cascade worse: a profile that reads root's grant and refreshes it (xAI rotates the refresh_token every refresh) saved the rotated chain only to the profile, leaving root holding a revoked token that kills every other profile. Now, when a profile lacks its own providers.xai-oauth block (i.e. it read root via fallback), the rotated chain is written back to root too — best-effort, TOCTOU-safe (reuses _save_auth_store with an explicit target path), with a pytest seat belt. A profile that genuinely shadows root is untouched; classic mode is a no-op; a failed root write never breaks the profile's own save.
  3. chore: AUTHOR_MAP entry for the salvaged commit's author.

Why both halves

resolve_xai_http_credentials (x_search / image_gen / TTS) already funnels through _read_xai_oauth_tokens, so commit 1 fixes the HTTP path at the single chokepoint too. But read-fallback without write-through is exactly the trap #43589 documents, so they must land together.

Tests

  • Salvaged read tests (3) — pool fallback, global fallback, still-broken path.
  • New write-through tests (4) — drive the real on-disk save: writes back to root when profile has no own state; does NOT touch root when profile shadows it; classic-mode no-op; failed root write doesn't break profile save. Proven as a real regression guard (neutering the write-through fails the key test).
  • test_auth_xai_oauth_provider (82) + test_auth_profile_fallback (16) green — the _save_auth_store optional-target signature is back-compatible.

Closes #43589. Supersedes the read-path duplicates #43513 and #39069 (same fix, further downstream + larger).

capt-marbles and others added 3 commits June 15, 2026 17:03
…search#43589)

The salvaged read-side fix lets a profile resolve the xAI OAuth grant from
the global-root auth store when it has no own providers.xai-oauth block.
But _save_xai_oauth_tokens still wrote rotated tokens only to the active
profile store. Because xAI rotates the refresh_token on every refresh, a
profile that reads root's grant and refreshes it left root holding a now-
revoked refresh token — killing every other profile reading the stale root
grant with invalid_grant once its access token expired (NousResearch#43589).

Detect the read-from-root case (profile lacks its own providers.xai-oauth
block) and, after the profile save, write the rotated chain back to the
global root too via a best-effort, TOCTOU-safe write-through that reuses
_save_auth_store with an explicit target path. A profile that genuinely
shadows root (has its own block) is left untouched, classic mode is a
no-op, and a failed root write never breaks the profile's own save.

Pairs with the read fallback in the preceding commit so the cross-profile
xAI grant stays coherent in both directions.
Salvaged commit in this PR is authored by capt-marbles
(andrewdmwalker@gmail.com), a bare gmail that does not auto-resolve in
the check-attribution job. Add the AUTHOR_MAP entry.
@kshitijk4poor
kshitijk4poor enabled auto-merge June 15, 2026 11:42
@kshitijk4poor
kshitijk4poor merged commit 8844e09 into NousResearch:main Jun 15, 2026
29 checks passed
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
…oauth-profile-writethrough

fix(auth): resolve xAI OAuth credentials across profiles + write rotated tokens back to root
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…oauth-profile-writethrough

fix(auth): resolve xAI OAuth credentials across profiles + write rotated tokens back to root
Methodician added a commit to Methodician/hermes-agent that referenced this pull request Jul 4, 2026
…oauth-profile-writethrough

fix(auth): resolve xAI OAuth credentials across profiles + write rotated tokens back to root
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…oauth-profile-writethrough

fix(auth): resolve xAI OAuth credentials across profiles + write rotated tokens back to root
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…oauth-profile-writethrough

fix(auth): resolve xAI OAuth credentials across profiles + write rotated tokens back to root
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…oauth-profile-writethrough

fix(auth): resolve xAI OAuth credentials across profiles + write rotated tokens back to root
@kshitijk4poor
kshitijk4poor deleted the salvage/xai-oauth-profile-writethrough branch August 5, 2026 07:09
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…oauth-profile-writethrough

fix(auth): resolve xAI OAuth credentials across profiles + write rotated tokens back to root
melon-xf added a commit to melon-xf/hermes-agent that referenced this pull request Sep 3, 2026
…oauth-profile-writethrough

fix(auth): resolve xAI OAuth credentials across profiles + write rotated tokens back to root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: profile auth shadowing + rotating refresh tokens guarantees grant revocation on multi-profile installs

2 participants