fix(quota): prefer Grok weekly credits for xAI dashboard - #1290
Conversation
OpenCodex still showed the legacy 30-day Grok billing window while the real SuperGrok gate is weekly. Prefer GET /v1/billing?format=credits and keep monthly /v1/billing only as fallback when weekly data is unavailable. Closes #1283
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe xAI quota provider now prefers weekly credits data, derives the required account identity, sends compatibility headers, and falls back to monthly billing data. Tests cover parsing, request requirements, privacy, failures, and missing identity. ChangesxAI weekly quota reporting
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Dashboard
participant XaiQuotaProvider
participant WeeklyCreditsAPI
participant MonthlyBillingAPI
Dashboard->>XaiQuotaProvider: request xAI quota
XaiQuotaProvider->>WeeklyCreditsAPI: request weekly credits with identity and headers
WeeklyCreditsAPI-->>XaiQuotaProvider: weekly credits or failure
XaiQuotaProvider->>MonthlyBillingAPI: request monthly billing when weekly data is unavailable
MonthlyBillingAPI-->>XaiQuotaProvider: monthly quota or failure
XaiQuotaProvider-->>Dashboard: quota report or no report
Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0fe140f911
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| [XAI_GROK_COMPATIBILITY.headers.tokenAuth]: "xai-grok-cli", | ||
| [XAI_GROK_COMPATIBILITY.headers.authenticateResponse]: "authenticate-response", | ||
| "x-userid": userId, | ||
| [XAI_GROK_COMPATIBILITY.headers.clientVersion]: XAI_GROK_CLIENT_VERSION, |
There was a problem hiding this comment.
Send the required Grok client-mode header
The source-backed weekly billing contract recorded in devlog/_fin/260716_grok_weekly_credits_crossrepo/000_plan.md requires the Grok client-mode header in addition to the bearer, user ID, token-auth, authentication-response, and version headers. This request omits x-grok-client-mode, so production billing servers that validate the Grok CLI fingerprint reject the credits request and silently fall back to the same monthly quota this change is intended to replace. Add the required client-mode value and cover it in the request-header assertion.
Useful? React with 👍 / 👎.
| return report(provider, "xai:grok-billing", quota); | ||
|
|
||
| // Prefer the SuperGrok weekly credits window that actually gates prompting (#1283). | ||
| const userId = getCredential("xai")?.accountId?.trim() || xaiUserIdFromAccessToken(accessToken); |
There was a problem hiding this comment.
Keep the xAI user ID bound to the resolved token
If the active xAI account is switched while getValidAccessToken("xai") is awaiting a refresh, this subsequent active-credential lookup can return account B's ID while accessToken belongs to account A. The weekly request then mixes identities and may fail or report the wrong account's quota; account switching is a supported management flow and can overlap a dashboard refresh. Resolve an access-token snapshot and derive the user ID from that snapshot's exact account credential rather than rereading whichever account is currently active.
Useful? React with 👍 / 👎.
Summary
xaidashboard quota viaGET /v1/billing?format=credits, mappingcreditUsagePercent+ weekly period toweeklyPercent/weeklyResetAt.GET /v1/billing(monthlyLimit/used) only as fallback when weekly data or identity is unavailable.Closes #1283
Verification
bun test tests/provider-quota.test.ts— 89 pass / 0 failbun run typecheck— pass--no-verify); one pre-existing unrelated failure observed on tip:tests/translator-budget.test.ts(--ignoreConfig/ TS5023)Checklist
Summary by CodeRabbit
New Features
Bug Fixes