Repository navigation
fix(grok): honor zero-usage weekly reset - #9219
Conversation
📝 WalkthroughWalkthroughUpdated Grok rate-limit mapping to default missing weekly usage percentages to 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 336fba50-906a-4422-bac3-0e20839dd5f7
📒 Files selected for processing (2)
src/main/rate-limits/grok-fetcher.test.tssrc/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) |
There was a problem hiding this comment.
🎯 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.
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.
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]>
* fix(grok): honor zero-usage weekly reset * fix(grok): preserve ambiguous monthly billing fallback
Summary
creditUsagePercentas protobuf zero only when the declared weekly period is corroborated by matching billing-period bounds.currentPeriodwithout matching billing bounds.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:nodePerformance
Electron validation