Skip to content

fix(grok): honor zero-usage weekly reset - #9219

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-grok-reset-time
Jul 17, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-grok-reset-time

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Treat an omitted Grok creditUsagePercent as protobuf zero only when the declared weekly period is corroborated by matching billing-period bounds.
  • Keep that confirmed weekly period and reset authoritative instead of falling back to the unrelated monthly billing boundary.
  • Preserve monthly included-usage fallback for unified-billing responses that carry an ambiguous weekly-looking currentPeriod without matching billing bounds.
  • Add regression coverage for both live response shapes and their network-request counts.

Fixes #9214

Testing

  • pnpm vitest run src/main/rate-limits src/main/ipc/rate-limits.test.ts src/shared/rate-limit-types.test.ts (315 tests)
  • pnpm vitest run --config config/vitest.config.ts src/renderer/src/components/status-bar/tooltip.test.ts (41 tests)
  • pnpm vitest run --config config/vitest.config.ts src/renderer/src/components/settings/GrokAccountsSection.test.tsx src/renderer/src/components/status-bar/provider-segment-monthly-window.test.tsx (5 tests)
  • pnpm run typecheck:node
  • Focused Oxlint, type-aware lint, and formatting checks
  • Max-lines ratchet and reliability gates
  • Electron dev validation against the real Grok account response: the visible menu showed Weekly, 0% used, and Resets in 6d 23h, matching the July 24 weekly reset in backing state.

Performance

  • Confirmed zero-usage weekly responses make exactly one billing request.
  • Ambiguous unified-billing responses make exactly two requests so monthly quota remains correct; tests assert both request budgets.

Electron validation

Orca dev instance showing Grok weekly usage and the corrected reset countdown

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updated Grok rate-limit mapping to default missing weekly usage percentages to 0 while preserving validation for other periods. Added coverage for weekly billing periods without usage percentages, including reset timing and a single billing fetch, and adjusted monthly unified-billing coverage to omit a weekly period.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description has Summary and Testing, but it misses required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections with brief content, including screenshots/no visual change, AI review report, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement the reported weekly reset fix and preserve monthly fallback for ambiguous responses, matching issue #9214.
Out of Scope Changes check ✅ Passed The diff appears limited to the issue fix, related regression tests, and comment updates, with no clear unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise and matches the main change: Grok weekly reset handling for omitted zero usage.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 336fba50-906a-4422-bac3-0e20839dd5f7

📥 Commits

Reviewing files that changed from the base of the PR and between 632a124 and ab86e0e.

📒 Files selected for processing (2)
  • src/main/rate-limits/grok-fetcher.test.ts
  • src/main/rate-limits/grok-fetcher.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/rate-limits/grok-fetcher.ts

headers: expect.objectContaining({ Authorization: 'Bearer access-token' })
})
)
expect(netFetchMock).toHaveBeenCalledTimes(2)

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Retain the fallback endpoint assertion.

toHaveBeenCalledTimes(2) confirms only that a second request occurred; it will not catch a regression where the second request targets the wrong billing endpoint. Keep the existing nth-call URL/argument assertion, optionally alongside the count assertion.

@brennanb2025
brennanb2025 merged commit e6933fe into main Jul 17, 2026
1 of 2 checks passed
nwparker added a commit that referenced this pull request Aug 22, 2026
Review follow-ups on the omitted-percent fix:

- The used/monthlyLimit pair was being divided into a WEEKLY percent inside
  resolveWeeklyPercent while mapMonthlyUsage maps the identical pair as a
  43_200-minute monthly window. The credits view now routes that pair through
  mapMonthlyUsage into the monthly slot (still one request), so it can no
  longer render as "Weekly credits"/"wk".
- The dropped-protobuf-zero inference keyed on "any parseable money field",
  but only an explicitly-emitted ZERO proves the encoder keeps defaults. A
  #9214/#9219 account carrying only non-zero money fields regressed from a
  correct 0% to unavailable. The inference now requires an explicit zero, and
  also stands down when a computable budget pair already speaks for
  consumption. The broader predicate stays only for the error wording.
Jiiinww added a commit to Jiiinww/orca that referenced this pull request Sep 22, 2026
Review noted the no-pool branch had no dedicated coverage and could flip a
zero-cap payload carrying a non-zero used amount from unavailable to 0%.
Confirmed: onDemandCap {val:0} with used {val:37.5} resolved to 0%, which
claims the opposite of what the payload reports.

The structural zeros still say nothing, but consumption does, so the branch
now treats a positive onDemandUsed or used as a withheld percent. A balance
is not consumption, so the stablyai#9214/stablyai#9219 prepaidBalance shape keeps its 0%.
Adds coverage for that case and for an entirely absent cap.

Co-Authored-By: Claude Opus 5 <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(grok): honor zero-usage weekly reset

* fix(grok): preserve ambiguous monthly billing fallback
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 reset time calculation is off -> might be because the Grok team changed their reset recently

1 participant