fix(quota): restore Grok usage for current CLI auth and billing schema - #2372
fix(quota): restore Grok usage for current CLI auth and billing schema#2372JOUYO wants to merge 1 commit into
Conversation
Grok CLI stores the token as nested `key` and reports usage under `config.used.val`, so the Settings usage card never showed monthly credits for normal CLI logins. Also surface the subscription plan label from settings and account details from auth.json. Co-authored-by: Cursor <cursoragent@cursor.com>
|
| Filename | Overview |
|---|---|
| packages/server/src/services/quota-fetcher/providers/grok.ts | Implements current Grok authentication, refresh, billing, and plan-label support, but can associate CLI account metadata with quota fetched using a different environment credential. |
| packages/server/src/services/quota-fetcher/providers/grok.test.ts | Adds module-interface coverage for nested credentials, expired-token refresh, and a billing 401 retry. |
| packages/server/src/services/quota-fetcher/service.test.ts | Updates service-level Grok coverage to verify subscription labels while preserving zero-valued balances. |
Reviews (1): Last reviewed commit: "fix(quota): restore Grok usage from curr..." | Re-trigger Greptile
| balances, | ||
| details: [], | ||
| balances: resolveGrokBalances(resp), | ||
| details: storedAuth?.details ?? [], |
There was a problem hiding this comment.
Account identity sources diverge
When GROK_API_KEY or GROK_TOKEN identifies a different account from ~/.grok/auth.json, billing and settings use the environment token while details still come from the stored CLI account, causing the usage panel to display quota and identity information for two different accounts.
|
Superseded by #2385, which includes this change (and later polish) on current main. |
Linked issue
Closes #2352
Type of change
What does this PR do
Grok Settings → Usage never showed monthly credits for normal CLI logins because the fetcher was out of date with the current Grok CLI:
~/.grok/auth.jsonnests the JWT underkey(and may use a top-level direct entry). The old reader only accepted top-levelaccess_token, so token lookup returned null and the billing fetch never ran.GET /v1/billingreports usage asconfig.used.val, while the fetcher only looked at legacyusage.creditUsage.subscription_tier_displayfrom/v1/settings(e.g.SuperGrok Heavy) and surface account details from auth.json.Includes unit coverage for nested CLI credentials, expired-token refresh, and 401 retry.
How did you verify it
npx vitest run packages/server/src/services/quota-fetcher/providers/grok.test.ts packages/server/src/services/quota-fetcher/service.test.ts --bail=1(31 passed)keyauth.json parses and billing returns monthly credits (used/limit)subscription_tier_display: "SuperGrok Heavy"provider.usage.listthen reports Grok asavailablewith plan label + monthly credits balancenpm run lint/ format / server typecheck clean on the touched filesChecklist
npm run typecheckpassesnpm run lintpassesMade with Cursor