Skip to content

fix: avoid repeated xAI OAuth refresh during discovery - #140434

Merged
shakkernerd merged 1 commit into
mainfrom
fix/xai-catalog-refresh
Sep 6, 2026
Merged

shakkernerd merged 1 commit into
mainfrom
fix/xai-catalog-refresh

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Related: #137120

What Problem This Solves

Fixes an issue where refreshing xAI models could resend an OAuth refresh request after credential preparation had already failed. This also happened when a usable configured API key was available as the fallback. Repeating an ambiguous failed refresh is unsafe for rotating tokens.

Why This Change Was Made

The xAI catalog now honors exhausted preparation and keeps a prepared environment or configuration fallback from reopening implicit profile selection. It uses the existing runtime auth option for direct fallback attempts; selected stored profiles and genuinely absent catalog auth retain their existing resolution paths.

User Impact

Model discovery does not repeat failed OAuth preparation. Valid stored, configured, and environment API-key fallbacks still work, and failed discovery retains its existing profile-scoped outcomes and compatible-inventory behavior. No new settings, dependencies, schema changes, or session-pin policy are introduced.

Evidence

  • On unchanged base e1c1bc37c77f527c4c33b2dc3dd054f0886e1fdc, the real planner and registered xAI plugin made two refresh attempts for one exhausted profile and four for two. The configured-key fallback also refreshed the failed profile twice. Stored-key fallback controls passed.
  • Six focused planner cases pass on the candidate: one/two-profile exhaustion, xAI stored/configured/environment key fallback, and the existing OpenAI stored-key control. All 48 xAI provider tests pass, including genuine absent-auth runtime discovery, OAuth catalog behavior, and API-key fallback.
  • Changed-path formatting, typed lint, conflict/assertion/line ratchets, and independent review through P2 pass.
  • All seven affected test files and the complete remote changed-path gate pass, including the owning production/test type graphs, lint, boundary checks, and ratchets. Exact-head CI is green.
  • Real built Gateway models.list calls against temporary SQLite auth stores reproduce two failed refresh requests per profile before the fix and one after it. Matched before/after cases cover an ambiguous transport disconnect, two profiles returning HTTP 503, and a usable configured API-key fallback. The fallback still makes one correctly authenticated model request and reports ready.
  • Prepared-only reads make no additional provider requests, and persisted credential data remains unchanged in every case. Each Gateway, fixture server, and temporary state directory was cleaned up.

The runtime probes use synthetic credentials and controlled loopback HTTPS through a managed proxy. They establish request count, credential selection, and runtime behavior, not vendor credential acceptance. No provider API contract changes.

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 5:30 PM ET / 21:30 UTC.

ClawSweeper review

What this changes

The xAI plugin stops repeating failed OAuth refresh attempts during model discovery while preserving API-key fallbacks, with expanded planner regression coverage.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main still repeats credential resolution after OAuth preparation fails. No blocking correctness findings were found, and the maintainer-authored PR is protected from automated closure.

Priority: P2
Reviewed head: e6195eb0b5f8436b7a03d20e3454cfeb82400f64

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful regression coverage and useful reported runtime observations; no blocking defect was found.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate, and no material authority expansion triggers additional proof. Its body reports built-Gateway models.list fault probes through real HTTP boundaries with fewer refresh requests, preserved configured-key discovery, and unchanged stored credentials.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate, and no material authority expansion triggers additional proof. Its body reports built-Gateway models.list fault probes through real HTTP boundaries with fewer refresh requests, preserved configured-key discovery, and unchanged stored credentials.
Evidence reviewed 7 items Current main still needs the fix: At the fetched main revision, the xAI catalog unconditionally calls the runtime resolver after reading prepared auth; it neither checks preparationFailed nor disables implicit profile fallback for prepared direct credentials.
Existing discovery contract: The provider SDK documentation explicitly says exhausted preparation must not restart resolution of the same profiles. The preparation owner excludes failed candidates and sets preparationFailed only when no usable credential remains.
Narrow use of existing runtime controls: The introduced guard returns before runtime resolution on exhausted preparation. The existing allowAuthProfileFallback option produces an empty implicit profile order; explicit selected profiles remain locked, and genuinely absent auth retains its original path. No plugin API, persisted setting, schema, or provider protocol is added.
Findings None None.
Security None None.

How this fits together

Model discovery prepares provider credentials before asking the xAI plugin for available models. Its results and failure outcomes feed OpenClaw’s model inventory and determine whether compatible previously discovered models remain available.

flowchart TD
  A[Model refresh request] --> B[Prepare ordered credentials]
  B --> C{xAI authentication result}
  C -->|Preparation exhausted| D[Report unavailable and retain compatible inventory]
  C -->|Usable credential| E[Resolve selected authentication]
  E --> F[Fetch xAI model catalog]
  F --> G[Publish model inventory]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests +48. Total +53 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 0 +5
Tests 1 128 80 +48
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 133 80 +53

Review metrics

None.

Technical review

Best possible solution:

Keep xAI discovery bound to prepared authentication, preserve usable fallbacks, and retain compatible inventory when preparation is exhausted.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes the path: failed OAuth preparation excludes a profile, but current main’s xAI hook reopens implicit profile resolution. The PR reports matching Gateway before/after probes; this review did not execute them.

Is this the best way to solve the issue?

Yes. The patch honors the existing preparation contract using an existing resolver option, with coverage for exhausted profiles and all three API-key fallback sources.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c2941a8db981.

Labels

Label justifications:

  • P2: This repairs a bounded xAI discovery failure that repeats rotation-sensitive OAuth refresh attempts while preserving existing fallback behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate, and no material authority expansion triggers additional proof. Its body reports built-Gateway models.list fault probes through real HTTP boundaries with fewer refresh requests, preserved configured-key discovery, and unchanged stored credentials.

Evidence

What I checked:

  • Current main still needs the fix: At the fetched main revision, the xAI catalog unconditionally calls the runtime resolver after reading prepared auth; it neither checks preparationFailed nor disables implicit profile fallback for prepared direct credentials. (extensions/xai/index.ts:208, c2941a8db981)
  • Existing discovery contract: The provider SDK documentation explicitly says exhausted preparation must not restart resolution of the same profiles. The preparation owner excludes failed candidates and sets preparationFailed only when no usable credential remains. Public docs: docs/plugins/sdk-provider-plugins.md. (docs/plugins/sdk-provider-plugins.md:309, e6195eb0b5f8)
  • Narrow use of existing runtime controls: The introduced guard returns before runtime resolution on exhausted preparation. The existing allowAuthProfileFallback option produces an empty implicit profile order; explicit selected profiles remain locked, and genuinely absent auth retains its original path. No plugin API, persisted setting, schema, or provider protocol is added. (extensions/xai/index.ts:209, e6195eb0b5f8)
  • Regression and sibling coverage: The planner tests cover xAI stored, configured, and environment API-key fallbacks plus one- and two-profile exhaustion, asserting refresh counts, request credentials, outcomes, and inventory retention. Existing xAI tests also cover absent-auth runtime discovery and OAuth catalog failure without another catalog-auth retry. Tests were inspected, not executed in this read-only review. (test/openai-model-discovery-auth-order.test.ts:169, e6195eb0b5f8)
  • Captured runtime observations: The supplied complete PR body, captured under sourceRevision d9c99b0498471d11ff11dcfaec432e9e897daf7381a9a26cc5a515bf4a30fbf2, reports built-Gateway models.list probes using temporary SQLite stores and controlled loopback HTTPS. Disconnect and HTTP 503 cases reduced failed refreshes from two per profile to one; configured-key fallback still sent one correctly authenticated catalog request and reported ready. These are contributor-reported observations, not a reviewer-executed run or proof of vendor credential acceptance. (e6195eb0b5f8)
  • Related merged work and routing history: Current-main history records Shakker’s work on credential selection, preparation deadlines, and inventory retention. The supplied GitHub metadata confirms fix: keep OpenAI model discovery on configured auth profile #137120 merged; its broader OpenAI selection repair provides context but does not replace this remaining xAI fix. Exact line-introduction attribution was not established. (src/agents/models-config.providers.discovery-auth.runtime.ts, 21a4cae241e9)

Likely related people:

  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-06T20:46:09.212Z sha e6195eb :: needs maintainer review before merge. :: none

@shakkernerd shakkernerd self-assigned this Sep 6, 2026
@shakkernerd
shakkernerd merged commit 8ff2721 into main Sep 6, 2026
153 checks passed
@shakkernerd
shakkernerd deleted the fix/xai-catalog-refresh branch September 6, 2026 21:37
@shakkernerd

Copy link
Copy Markdown
Member Author

Fixed: xAI model discovery no longer repeats failed OAuth refresh attempts while retaining valid API-key fallback.

vincentkoc added a commit that referenced this pull request Sep 6, 2026
* commit '294df333c58f2da104eccffc623ccb3c4d43d4d8': (1802 commits)
  fix: clear stale diagnostics after Gateway changes (#140426)
  fix: keep plugin catalogs intact after discovery timeouts (#140441)
  perf(tui): prepare session picker rows once per overlay (#140462)
  refactor(config): reuse environment substitution for write-back (#140460)
  refactor(discord): remove retired auto-presence templates (#140463)
  fix(ui): finish roster refreshes during session activity (#140459)
  fix(setup): match prepared credentials to the model provider (#140461)
  fix: keep MiniMax discovery on the selected credential (#140438)
  refactor(tests): remove unused parent context cache reset (#140456)
  fix: avoid repeated xAI OAuth refresh during discovery (#140434)
  perf(routing): reuse prepared event session targets (#140454)
  fix(media): keep deferred audio and extraction providers discoverable (#139231)
  refactor(codex): remove redundant app-server forwarding (#140451)
  fix(test): avoid false native polling timeouts (#140119)
  test(gateway): retain saved source in reload fixtures (#140453)
  fix(gateway): reduce repeated model work when listing sessions (#140414)
  fix(feishu): fall back to post mode over table limit (#136382)
  fix: use the bundle-compatible Proxyline runtime under Bun (#140411)
  refactor(trace): reuse the canonical usage counter type (#140444)
  refactor(node-host): share execution policy result fields (#140446)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
Prevent duplicate failed xAI OAuth refresh requests during model discovery while preserving valid API-key fallback and profile-scoped failure outcomes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: xai maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant