fix(host-service): show the Grok weekly reset when the percent is omitted

Closed
KU
15d ago
+36-2

What & why

parseGrokQuotaPayload returned null whenever the reply had no fixed32 percent, even after it had found the weekly reset. The Grok card then said "No weekly quota data returned." and the usage bar showed a dash. Proto3 doesn't send a float field whose value is 0, so a reply with only the period fields is how the server encodes 0% used. An omitted percent is now read as 0 when the reset is present, and a reply with neither still returns null.

Fixes #9188.

One open point: the reporter saw this during active Grok Build use, and the billing JSON omits creditUsagePercent for isUnifiedBillingUser accounts. If unified-billing accounts report usage somewhere other than this field, showing 0% is better than "unavailable" but still not the real number. Happy to follow up if you know where that lives.

How I tested it

In packages/host-service, bun test src/trpc/router/usage/grok-quota.test.ts. The new case (reset fields, no percent) fails on main with null and passes with the fix. A second new case checks that a reply with neither field still returns null. biome check is clean on both files.

Checklist

  • PR title follows conventional commits
  • bun run lint and bun run typecheck pass (only biome check on the changed files was run locally)
  • "Allow edits from maintainers" is checked

Summary by cubic

parseGrokQuotaPayload returned null whenever the reply had no percent, so the Grok card showed "No weekly quota data returned." and a dash. Proto3 doesn't send a float field whose value is 0, so a reply with only the weekly reset period fields means 0% used.

An omitted percent is now read as 0 when the weekly reset field (1.5.1) is present, restoring the reset display. A reply with only the week start (1.4.1) or neither field still returns null, since both are future timestamps that don't indicate usage. Fixes #9188.

Note: unified-billing accounts may omit creditUsagePercent and report usage elsewhere, so showing 0% is better than "unavailable" but may not reflect the real number.

Summary by CodeRabbit

  • Bug Fixes
    • Quota information now remains available when a reset time is provided without a usage percentage. In that case, usage is shown as 0%; if neither value is available, no quota is reported. Existing percentage handling remains unchanged, so reported usage continues to follow the same limits when a valid percentage is provided.