Skip to content

fix(quota): restore Grok usage for current CLI auth and billing schema - #2372

Closed
JOUYO wants to merge 1 commit into
getpaseo:mainfrom
JOUYO:fix/grok-usage-plan-credits
Closed

fix(quota): restore Grok usage for current CLI auth and billing schema#2372
JOUYO wants to merge 1 commit into
getpaseo:mainfrom
JOUYO:fix/grok-usage-plan-credits

Conversation

@JOUYO

@JOUYO JOUYO commented Jul 23, 2026

Copy link
Copy Markdown

Linked issue

Closes #2352

Type of change

  • Bug fix
  • New feature (with prior issue + design alignment)
  • Refactor / code improvement
  • Docs

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:

  1. Auth store: live ~/.grok/auth.json nests the JWT under key (and may use a top-level direct entry). The old reader only accepted top-level access_token, so token lookup returned null and the billing fetch never ran.
  2. Billing schema: current GET /v1/billing reports usage as config.used.val, while the fetcher only looked at legacy usage.creditUsage.
  3. Plan label: also read subscription_tier_display from /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

  • Unit tests: 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)
  • Live host check against a logged-in Grok CLI:
    • nested/key auth.json parses and billing returns monthly credits (used / limit)
    • settings returns subscription_tier_display: "SuperGrok Heavy"
    • daemon provider.usage.list then reports Grok as available with plan label + monthly credits balance
  • npm run lint / format / server typecheck clean on the touched files

Checklist

  • One focused change. Unrelated cleanups split out.
  • npm run typecheck passes
  • npm run lint passes
  • Linked issue present for bug fix / behavior change
  • Verification section filled with what I actually ran

Made with Cursor

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>
@greptile-apps

greptile-apps Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Restores Grok quota reporting for the current CLI credential and billing formats.

  • Parses nested and direct Grok CLI credentials, including account metadata and expiry information.
  • Refreshes expired or rejected CLI credentials and retries billing requests after authorization failure.
  • Reads current billing counters and subscription labels while retaining legacy usage compatibility.
  • Adds focused provider and service coverage for authentication, refresh, retry, and quota normalization.

Confidence Score: 3/5

The account-source mismatch should be fixed before merging because environment-authenticated usage can be displayed alongside another account’s CLI metadata.

Billing and settings consistently use the environment token when present, but the returned account details are always copied from the local CLI auth store, allowing one usage result to combine two account identities.

packages/server/src/services/quota-fetcher/providers/grok.ts

Important Files Changed

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 ?? [],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

@JOUYO

JOUYO commented Jul 24, 2026

Copy link
Copy Markdown
Author

Superseded by #2385, which includes this change (and later polish) on current main.

@JOUYO JOUYO closed this Jul 24, 2026
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: Grok Usage card missing plan credits (auth.json + billing schema drift)

1 participant