Skip to content

fix(grok): tolerate missing creditUsagePercent in billing API#8298

Open
choiwjun wants to merge 1 commit into
stablyai:mainfrom
choiwjun:fix/grok-usage-billing-fallbacks
Open

fix(grok): tolerate missing creditUsagePercent in billing API#8298
choiwjun wants to merge 1 commit into
stablyai:mainfrom
choiwjun:fix/grok-usage-billing-fallbacks

Conversation

@choiwjun

Copy link
Copy Markdown

Problem

Orca status bar Grok usage shows: Grok billing response did not include credit usage.

Root cause: SuperGrok unified billing (/v1/billing?format=credits) sometimes omits creditUsagePercent while still returning weekly period metadata. Orca treated that as unavailable.

Fix

  • Prefer creditUsagePercent when present
  • Fall back to productUsage[].usagePercent sum
  • If counters are missing, also fetch default /v1/billing and use used / monthlyLimit
  • If weekly pool metadata exists without counters after merge, show 0% instead of an error
  • Read subscriptionTier from response root when nested under config is absent

Test plan

  • Unit tests updated in grok-fetcher.test.ts
  • Manual: SuperGrok account shows percent after restart
  • Manual: missing creditUsagePercent no longer errors

SuperGrok unified billing sometimes omits creditUsagePercent on
/billing?format=credits. Fall back to productUsage, used/monthlyLimit
from default /billing, and 0% when weekly pool metadata is present.
@coderabbitai

coderabbitai Bot commented Jul 11, 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: 12561e40-5423-430a-95a5-ea07bf74234c

📥 Commits

Reviewing files that changed from the base of the PR and between ff8192a and b8b57bf.

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

📝 Walkthrough

Walkthrough

Grok rate-limit fetching now supports multiple billing payload formats, including product usage, numeric money wrappers, sibling subscription tiers, and unified weekly metadata. It derives weekly usage from available counters, merges credits data with a default billing response when needed, and uses shared handling for HTTP, authorization, JSON, and network errors. Tests cover fallback requests, weekly reset and usage mapping, zero-usage metadata, and unavailable responses.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers problem, fix, and tests, but it omits required template sections for screenshots, AI review, security audit, and notes. Add the missing template sections with the required headings, including screenshot status, AI review report, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: handling missing creditUsagePercent in Grok billing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

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.

2 participants