@devries-cameron20 / t3code-1 / commits / 0cab7d5ab9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): Grok accounts with no usage yet no longer vanish from Limits (#12799)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>

Jake Leventhal committed Sep 24, 2026 at 21:38 UTC 0cab7d5ab978a8adaee6827f81693249d0dfeee5
2 files changed +13 -2
apps/server/src/provider/Layers/GrokProvider.test.ts
+4 -1
@@ -564,7 +564,10 @@ describe("Grok usage limits", () => {
564 for (const response of [{}, { config: {} }, { config: { creditUsagePercent: NaN } }]) {
565 const limits = grokUsageResponseToLimits(response, checkedAt);
566 expect(limits.windows).toEqual([]);
567 - expect(limits.unavailable?.reason).toBe("unsupported");
567 + // Nothing metered yet, which xAI reports by omitting the field until
568 + // usage registers. Marking it `unsupported` would drop the account from
569 + // the Limits view for good; leaving the marker off keeps it listed.
570 + expect(limits.unavailable).toBeUndefined();
571 }
572 expect(
573 grokUsageResponseToLimits({ config: { creditUsagePercent: 0 } }, checkedAt).windows,
apps/server/src/provider/Layers/grokUsageLimits.ts
+9 -1
@@ -41,7 +41,15 @@ export function grokUsageResponseToLimits(
41 ) {
42 const usedPercent = response.config?.creditUsagePercent;
43 if (usedPercent === undefined || !Number.isFinite(usedPercent)) {
44 - return makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" });
44 + // A billing read that succeeded but carries no percentage is an account
45 + // with nothing metered yet, not one that can never report: xAI omits the
46 + // field entirely (rather than sending 0) until usage registers, then fills
47 + // it in. Calling that `unsupported` would strand the account — the Limits
48 + // view drops unsupported entries and deliberately mutes their notice, so a
49 + // freshly signed-in Grok account would vanish with no explanation until it
50 + // happened to be used, and `applyUsageLimitsUpdate` would refuse the
51 + // mid-turn windows that could have recovered it.
52 + return makeUsageLimits({ checkedAt, windows: [] });
53 }
54 const period = response.config?.currentPeriod;
55 const periodType = period?.type?.replace(/^USAGE_PERIOD_TYPE_/, "");