Skip to content

Fix zero-percent Grok usage visibility#8336

Closed
sdhilip200 wants to merge 1 commit into
stablyai:mainfrom
sdhilip200:fix/grok-usage-response
Closed

Fix zero-percent Grok usage visibility#8336
sdhilip200 wants to merge 1 commit into
stablyai:mainfrom
sdhilip200:fix/grok-usage-response

Conversation

@sdhilip200

Copy link
Copy Markdown
Contributor

Summary

  • treat an omitted Grok creditUsagePercent as zero when the billing response declares a weekly credit period
  • preserve the existing unavailable state for billing configs that do not expose a weekly credit window
  • add regression coverage for Grok's proto3 zero-value omission

Closes #8278

Testing

  • pnpm exec vitest run --config config/vitest.config.ts src/main/rate-limits/grok-fetcher.test.ts src/main/rate-limits/grok-auth.test.ts src/main/rate-limits/service.test.ts src/renderer/src/components/stats/GrokUsagePane.test.tsx src/renderer/src/components/status-bar/status-bar-provider-visibility.test.ts (86 tests passed)
  • pnpm typecheck
  • pnpm build (desktop, web, and native builds passed)
  • changed-file oxfmt, oxlint, and git diff --check
  • pnpm lint — existing missing localization keys in UsagePercentageDisplayChangeNotice.tsx, unrelated to this change
  • pnpm test — 28,481 passed; 29 unrelated failures across five suites under unsupported Node 26, plus one asynchronous renderer-test cleanup error

AI Review Report

  • Cross-platform: no path, process, or platform-specific behavior changed.
  • Remote/SSH: Grok usage remains a main-process account fetch; remote and SSH session routing are unchanged.
  • Provider compatibility: the change is restricted to Grok's weekly billing mapper and does not affect other usage providers.
  • Performance: no additional requests, polling, or persistent state were introduced.
  • Security: authentication headers, credential parsing, endpoint selection, and renderer exposure are unchanged.
  • UI: no layout change; valid zero-percent weekly usage now produces the existing Grok meter instead of an unavailable state.

Notes

Grok's billing endpoint is proto3 JSON, which omits scalar fields at their default value. A declared weekly period with no creditUsagePercent therefore represents 0% usage, not a missing quota.

The repository requests Node 24; the full local suite was run on Node 26.0.0. The focused regression tests, typecheck, and full build pass in that environment.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e8feab78-0c78-4bdf-b6c7-7e938eb82bc3

📥 Commits

Reviewing files that changed from the base of the PR and between eaddccf and e688412.

📒 Files selected for processing (2)
  • src/main/rate-limits/grok-fetcher.test.ts
  • src/main/rate-limits/grok-fetcher.ts

📝 Walkthrough

Walkthrough

Weekly Grok credit mapping now treats an omitted creditUsagePercent as 0 for weekly usage periods. A test covers a billing response containing weekly period metadata without credit usage fields and verifies an ok status with zero weekly usage.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main fix to Grok usage visibility.
Description check ✅ Passed The description is mostly complete and covers summary, testing, review, and notes, with only minor template omissions.
Linked Issues check ✅ Passed The change fixes #8278 by showing zero weekly Grok usage when proto3 omits creditUsagePercent, matching the reported bug.
Out of Scope Changes check ✅ Passed The PR stays focused on Grok usage mapping and regression coverage, with no unrelated feature or platform changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@bbingz

bbingz commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Superseded by #9219

Hi — after reconciling Grok usage mapping against current main and the open-sourced Grok Build billing shape (proto3 omits zero scalars):

#9219 (fix(grok): honor zero-usage weekly reset, merged) already treats an omitted creditUsagePercent as 0% when a weekly period is confirmed via matching currentPeriod + billing period bounds. That is a stricter, safer version of the fix this PR proposes (avoids treating a bare weekly-looking currentPeriod on monthly unified-billing responses as zero).

Monthly unified-billing fallback remains covered by #8769.

Recommend closing this PR as superseded by #9219 to free review bandwidth. Happy to help if a remaining SuperGrok response shape still fails after #9219 — please reopen with a redacted billing JSON fixture if so.

(Contributor note: no merge rights; leaving this for maintainers/authors.)

@brennanb2025

Copy link
Copy Markdown
Contributor

Taking a look!

@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for this! The same fix shipped on main via #9219, which uses a stricter weekly-period guard that also handles the monthly unified-billing case. Closing in favor of #9219 — appreciate you flagging the zero-percent bug 🙏

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] Just FYI - Grok Usage Not Populating

3 participants