Skip to content

fix(auxiliary): detect xAI OAuth 403 bad-credentials as auth error (#31527)#34431

Merged
teknium1 merged 2 commits into
mainfrom
fix/31527-aux-xai-oauth-403
May 29, 2026
Merged

fix(auxiliary): detect xAI OAuth 403 bad-credentials as auth error (#31527)#34431
teknium1 merged 2 commits into
mainfrom
fix/31527-aux-xai-oauth-403

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

The auxiliary client now recognizes xAI's HTTP 403 + unauthenticated:bad-credentials as an expired-OAuth-token signal and triggers refresh/rotation, instead of letting title generation / compression / vision routing silently fail when an aux task runs against xAI OAuth.

Salvages PR #31527 (@Moikapy). Distinct from the recently-merged #30872 / #29344 fix, which covered the main agent loop's run_agent._is_entitlement_failure + _recover_with_credential_pool paths. The auxiliary client has its own parallel recovery system (_is_auth_error, _refresh_provider_credentials, _recoverable_pool_provider) that the previous fix didn't touch.

Three gaps

Function Pre-fix Post-fix
_is_auth_error Only matched HTTP 401 Also matches HTTP 403 + bad-credentials, and unauthenticated:bad-credentials substring
_refresh_provider_credentials Branches for openai-codex, nous, anthropic Adds xai-oauth branch: pool-level try_refresh_current() first, falls back to resolve_xai_oauth_runtime_credentials(force_refresh=True)
_recoverable_pool_provider Hostname map covered chatgpt.com, openrouter.ai, api.anthropic.com, etc. Adds api.x.aixai-oauth

Salvage details

Resolved one merge conflict in _recoverable_pool_provider — main grew a main_runtime-based PROVIDER_REGISTRY fallback block between the PR's branch point and now. Kept both: the new api.x.ai host check + the PROVIDER_REGISTRY fallback. Verified by behavior — the PR's tests still pass against this resolution.

Validation

scripts/run_tests.sh tests/agent/test_auxiliary_client_xai_oauth_recovery.py \
                     tests/agent/test_auxiliary_client.py
=== 196 tests passed, 0 failed in 3.7s ===

PR ships 14 new tests covering all three functions (detection, host mapping, refresh structure) — no follow-up tests needed from us; the existing coverage was already complete.

Credit

@Moikapy — clean diagnosis, three minimal-scope fixes at the right intervention points. The tests directly mirror the bug pattern (xAI's actual 403 response shape) so future regressions get caught.

Moikapy and others added 2 commits May 28, 2026 23:45
xAI returns HTTP 403 (not 401) with unauthenticated:bad-credentials
when an OAuth2 access token has expired or is invalid. The existing
_is_auth_error() only checked for 401 status codes, so these tokens
were never refreshed and the 403 propagated as a generic permission
denied error.

Three fixes:

1. _is_auth_error: Recognize xAI's 403+bad-credentials pattern as
   an auth failure, triggering token refresh instead of silent failure.

2. _refresh_provider_credentials: Add xai-oauth branch with
   pool-level refresh (try_refresh_current with select to ensure
   current entry) then fallback to singleton resolver with
   force_refresh=True.

3. _recoverable_pool_provider: Map api.x.ai host to xai-oauth
   pool for auto-resolved providers, matching existing pattern for
   openai-codex/openrouter/nous/anthropic.

Includes 14 tests covering the new detection logic, host mapping,
and graceful fallback behavior.

Signed-off-by: moikapy <moikapy@devmoi.com>
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: fix/31527-aux-xai-oauth-403 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9431 on HEAD, 9425 on base (🆕 +6)

🆕 New issues (2):

Rule Count
unresolved-import 1
unresolved-attribute 1
First entries
tests/agent/test_auxiliary_client_xai_oauth_recovery.py:11: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
tests/agent/test_auxiliary_client_xai_oauth_recovery.py:78: [unresolved-attribute] unresolved-attribute: Unresolved attribute `status_code` on type `Exception`

✅ Fixed issues: none

Unchanged: 4891 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder provider/xai xAI (Grok) labels May 29, 2026
@teknium1 teknium1 merged commit c1485d5 into main May 29, 2026
25 checks passed
@teknium1 teknium1 deleted the fix/31527-aux-xai-oauth-403 branch May 29, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P3 Low — cosmetic, nice to have provider/xai xAI (Grok) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants