From f18a6d1d2e825d9447ca46f46e20dd9555c1b586 Mon Sep 17 00:00:00 2001 From: jieyuexing Date: Wed, 14 Oct 2026 15:56:37 +0800 Subject: [PATCH 1/5] fix(server): show zero-use Grok billing periods Co-Authored-By: Codex (gpt-6.1-sol) --- .../provider-grok/src/server/usage.test.ts | 87 +++++++++++++++++++ .../provider-grok/src/server/usageLimits.ts | 28 +++--- 2 files changed, 103 insertions(+), 12 deletions(-) diff --git a/packages/provider-grok/src/server/usage.test.ts b/packages/provider-grok/src/server/usage.test.ts index d4b6122dbafbe..21e851d01f8a7 100644 --- a/packages/provider-grok/src/server/usage.test.ts +++ b/packages/provider-grok/src/server/usage.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from "@effect/vitest"; import { GROK_COST_USD_TICKS_PER_DOLLAR, parseGrokLine } from "./usage.ts"; +import { grokUsageResponseToLimits } from "./usageLimits.ts"; describe("parseGrokLine", () => { /** Shaped after a real Grok Build `turn_completed` session update. */ @@ -314,3 +315,89 @@ describe("parseGrokLine", () => { expect(records[0]?.timestampMs).toBe(1_786_372_566_000); }); }); + +describe("Grok usage limits", () => { + const checkedAt = "2026-09-16T00:00:00.000Z"; + + it("treats an omitted percentage as zero only for a complete known billing period", () => { + expect( + grokUsageResponseToLimits( + { + config: { + currentPeriod: { + type: "USAGE_PERIOD_TYPE_WEEKLY", + start: "2026-09-11T03:10:30.159171+00:00", + end: "2026-09-18T03:10:30.159171+00:00", + }, + }, + }, + checkedAt, + ).windows, + ).toEqual([ + { + id: "subscription", + kind: "weekly", + label: "Weekly", + usedPercent: 0, + resetsAt: "2026-09-18T03:10:30.159Z", + }, + ]); + + expect( + grokUsageResponseToLimits( + { + config: { + currentPeriod: { + type: "USAGE_PERIOD_TYPE_MONTHLY", + start: "2026-09-01T00:00:00.000Z", + end: "2026-10-01T00:00:00.000Z", + }, + }, + }, + checkedAt, + ).windows, + ).toEqual([ + { + id: "subscription", + kind: "monthly", + label: "Monthly", + usedPercent: 0, + resetsAt: "2026-10-01T00:00:00.000Z", + }, + ]); + + for (const currentPeriod of [ + { type: "USAGE_PERIOD_TYPE_WEEKLY", end: "2026-09-18T03:10:30.159171+00:00" }, + { type: "USAGE_PERIOD_TYPE_WEEKLY", start: "2026-09-11T03:10:30.159171+00:00" }, + { + type: "USAGE_PERIOD_TYPE_WEEKLY", + start: "invalid", + end: "2026-09-18T03:10:30.159171+00:00", + }, + { + type: "USAGE_PERIOD_TYPE_WEEKLY", + start: "2026-09-18T03:10:30.159171+00:00", + end: "2026-09-11T03:10:30.159171+00:00", + }, + { + type: "USAGE_PERIOD_TYPE_WEEKLY", + start: "2026-09-11T03:10:30.159171+00:00", + end: "invalid", + }, + { + type: "USAGE_PERIOD_TYPE_WEEKLY", + start: "2026-09-11T03:10:30.159171+00:00", + end: "2026-09-11T03:10:30.159171+00:00", + }, + { + type: "USAGE_PERIOD_TYPE_DAILY", + start: "2026-09-11T03:10:30.159171+00:00", + end: "2026-09-18T03:10:30.159171+00:00", + }, + ]) { + expect(grokUsageResponseToLimits({ config: { currentPeriod } }, checkedAt).windows).toEqual( + [], + ); + } + }); +}); diff --git a/packages/provider-grok/src/server/usageLimits.ts b/packages/provider-grok/src/server/usageLimits.ts index d4a855883a6c4..5a955e55e2798 100644 --- a/packages/provider-grok/src/server/usageLimits.ts +++ b/packages/provider-grok/src/server/usageLimits.ts @@ -31,6 +31,7 @@ const GrokUsageResponse = Schema.Struct({ currentPeriod: Schema.optional( Schema.Struct({ type: Schema.optional(Schema.String), + start: Schema.optional(Schema.String), end: Schema.optional(Schema.String), }), ), @@ -42,22 +43,25 @@ export function grokUsageResponseToLimits( response: typeof GrokUsageResponse.Type, checkedAt: string, ) { - const usedPercent = response.config?.creditUsagePercent; - if (usedPercent === undefined || !Number.isFinite(usedPercent)) { - // A billing read that succeeded but carries no percentage is an account - // with nothing metered yet, not one that can never report: xAI omits the - // field entirely (rather than sending 0) until usage registers, then fills - // it in. Calling that `unsupported` would strand the account — the Limits - // view drops unsupported entries and deliberately mutes their notice, so a - // freshly signed-in Grok account would vanish with no explanation until it - // happened to be used, and `applyUsageLimitsUpdate` would refuse the - // mid-turn windows that could have recovered it. - return makeUsageLimits({ checkedAt, windows: [] }); - } const period = response.config?.currentPeriod; const periodType = period?.type?.replace(/^USAGE_PERIOD_TYPE_/, ""); const kind = periodType === "WEEKLY" ? "weekly" : periodType === "MONTHLY" ? "monthly" : "other"; + const start = period?.start ? DateTime.make(period.start) : Option.none(); const reset = period?.end ? DateTime.make(period.end) : Option.none(); + const completeKnownPeriod = + (kind === "weekly" || kind === "monthly") && + Option.isSome(start) && + Option.isSome(reset) && + DateTime.toEpochMillis(start.value) < DateTime.toEpochMillis(reset.value); + // Observed billing responses omit a zero percentage while retaining a + // complete subscription period; the Grok CLI shows that same period as 0%. + // An incomplete or unknown response remains unreported. + const usedPercent = response.config?.creditUsagePercent ?? (completeKnownPeriod ? 0 : undefined); + if (usedPercent === undefined || !Number.isFinite(usedPercent)) { + // Keep an incomplete successful response visible and retryable. Marking it + // unsupported would drop the account from the Limits view permanently. + return makeUsageLimits({ checkedAt, windows: [] }); + } const window: ServerProviderUsageWindow = { id: "subscription", kind, From 13ba965028be3e967d77f669422496704dbfa469 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 02:48:12 +0000 Subject: [PATCH 2/5] test(grok): specify zero-use billing period boundaries --- .../provider-grok/src/server/usage.test.ts | 131 +++++++++--------- 1 file changed, 68 insertions(+), 63 deletions(-) diff --git a/packages/provider-grok/src/server/usage.test.ts b/packages/provider-grok/src/server/usage.test.ts index c8787254786e9..03ba82cc9ce76 100644 --- a/packages/provider-grok/src/server/usage.test.ts +++ b/packages/provider-grok/src/server/usage.test.ts @@ -317,40 +317,71 @@ describe("parseGrokLine", () => { describe("Grok usage limits", () => { const checkedAt = "2026-09-16T00:00:00.000Z"; + const weeklyPeriod = { + type: "USAGE_PERIOD_TYPE_WEEKLY", + start: "2026-09-11T03:10:30.159171+00:00", + end: "2026-09-18T03:10:30.159171+00:00", + }; - it("treats an omitted percentage as zero only for a complete known billing period", () => { - expect( - grokUsageResponseToLimits( + it("shows zero usage for complete weekly and monthly periods with no percentage", () => { + for (const [currentPeriod, kind, label, resetsAt] of [ + [weeklyPeriod, "weekly", "Weekly", "2026-09-18T03:10:30.159Z"], + [ { - config: { - currentPeriod: { - type: "USAGE_PERIOD_TYPE_WEEKLY", - start: "2026-09-11T03:10:30.159171+00:00", - end: "2026-09-18T03:10:30.159171+00:00", - }, - }, + type: "USAGE_PERIOD_TYPE_MONTHLY", + start: "2026-09-01T00:00:00.000Z", + end: "2026-10-01T00:00:00.000Z", }, - checkedAt, - ).windows, - ).toEqual([ - { - id: "subscription", - kind: "weekly", - label: "Weekly", - usedPercent: 0, - resetsAt: "2026-09-18T03:10:30.159Z", - }, - ]); + "monthly", + "Monthly", + "2026-10-01T00:00:00.000Z", + ], + ] as const) { + const response = { config: { currentPeriod } }; + expect + .soft(grokUsageResponseToLimits(response, checkedAt).windows) + .toEqual([{ id: "subscription", kind, label, usedPercent: 0, resetsAt }]); + } + }); + + it("keeps incomplete, invalid, unordered, and unknown periods unreported", () => { + for (const currentPeriod of [ + undefined, + { ...weeklyPeriod, type: undefined }, + { ...weeklyPeriod, type: "USAGE_PERIOD_TYPE_DAILY" }, + { ...weeklyPeriod, start: undefined }, + { ...weeklyPeriod, end: undefined }, + { ...weeklyPeriod, start: "invalid" }, + { ...weeklyPeriod, end: "invalid" }, + { ...weeklyPeriod, start: weeklyPeriod.end }, + { ...weeklyPeriod, start: weeklyPeriod.end, end: weeklyPeriod.start }, + ]) { + const response = { config: { currentPeriod } }; + expect + .soft(grokUsageResponseToLimits(response, checkedAt).windows, JSON.stringify(response)) + .toEqual([]); + } + }); + it("rejects impossible calendar dates at either period boundary", () => { + for (const [start, end] of [ + ["2026-02-30T00:00:00.000Z", "2026-03-09T00:00:00.000Z"], + ["2026-02-23T00:00:00.000Z", "2026-02-30T00:00:00.000Z"], + ]) { + const response = { config: { currentPeriod: { ...weeklyPeriod, start, end } } }; + expect + .soft(grokUsageResponseToLimits(response, checkedAt).windows, JSON.stringify(response)) + .toEqual([]); + } + }); + + it("preserves explicit percentages without requiring a complete known period", () => { expect( grokUsageResponseToLimits( { config: { - currentPeriod: { - type: "USAGE_PERIOD_TYPE_MONTHLY", - start: "2026-09-01T00:00:00.000Z", - end: "2026-10-01T00:00:00.000Z", - }, + creditUsagePercent: 37.5, + currentPeriod: { type: weeklyPeriod.type, end: weeklyPeriod.end }, }, }, checkedAt, @@ -358,45 +389,19 @@ describe("Grok usage limits", () => { ).toEqual([ { id: "subscription", - kind: "monthly", - label: "Monthly", - usedPercent: 0, - resetsAt: "2026-10-01T00:00:00.000Z", + kind: "weekly", + label: "Weekly", + usedPercent: 37.5, + resetsAt: "2026-09-18T03:10:30.159Z", }, ]); - - for (const currentPeriod of [ - { type: "USAGE_PERIOD_TYPE_WEEKLY", end: "2026-09-18T03:10:30.159171+00:00" }, - { type: "USAGE_PERIOD_TYPE_WEEKLY", start: "2026-09-11T03:10:30.159171+00:00" }, - { - type: "USAGE_PERIOD_TYPE_WEEKLY", - start: "invalid", - end: "2026-09-18T03:10:30.159171+00:00", - }, - { - type: "USAGE_PERIOD_TYPE_WEEKLY", - start: "2026-09-18T03:10:30.159171+00:00", - end: "2026-09-11T03:10:30.159171+00:00", - }, - { - type: "USAGE_PERIOD_TYPE_WEEKLY", - start: "2026-09-11T03:10:30.159171+00:00", - end: "invalid", - }, - { - type: "USAGE_PERIOD_TYPE_WEEKLY", - start: "2026-09-11T03:10:30.159171+00:00", - end: "2026-09-11T03:10:30.159171+00:00", - }, - { - type: "USAGE_PERIOD_TYPE_DAILY", - start: "2026-09-11T03:10:30.159171+00:00", - end: "2026-09-18T03:10:30.159171+00:00", - }, - ]) { - expect(grokUsageResponseToLimits({ config: { currentPeriod } }, checkedAt).windows).toEqual( - [], - ); + for (const [creditUsagePercent, usedPercent] of [ + [0, 0], + [125, 100], + ] as const) { + expect( + grokUsageResponseToLimits({ config: { creditUsagePercent } }, checkedAt).windows, + ).toEqual([{ id: "subscription", kind: "other", label: "Subscription", usedPercent }]); } }); }); From 189e0dcf02087dfda546093125f941faff41f904 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 02:50:22 +0000 Subject: [PATCH 3/5] fix(grok): infer zero usage for valid billing periods --- .../provider-grok/src/server/usageLimits.ts | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/packages/provider-grok/src/server/usageLimits.ts b/packages/provider-grok/src/server/usageLimits.ts index 2d7a16fbb70ae..a3a82dc4d27df 100644 --- a/packages/provider-grok/src/server/usageLimits.ts +++ b/packages/provider-grok/src/server/usageLimits.ts @@ -31,6 +31,7 @@ const GrokUsageResponse = Schema.Struct({ currentPeriod: Schema.optional( Schema.Struct({ type: Schema.optional(Schema.String), + start: Schema.optional(Schema.String), end: Schema.optional(Schema.String), }), ), @@ -38,21 +39,46 @@ const GrokUsageResponse = Schema.Struct({ ), }); +function parsePeriodBoundary(value: string | undefined) { + if ( + !value || + value !== value.trim() || + !/^(?:\d{4}|[+-]\d{6})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?|24:00(?::00(?:\.0+)?)?)(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.test( + value, + ) + ) { + return Number.NaN; + } + // Date parsing can normalize impossible calendar dates instead of rejecting them. + const datePart = value.slice(0, value.indexOf("T")); + const date = DateTime.make(`${datePart}T00:00:00.000Z`); + if (Option.isNone(date)) return Number.NaN; + const parts = DateTime.toPartsUtc(date.value); + if (parts.month !== Number(datePart.slice(-5, -3)) || parts.day !== Number(datePart.slice(-2))) { + return Number.NaN; + } + return Date.parse(value); +} + export function grokUsageResponseToLimits( response: typeof GrokUsageResponse.Type, checkedAt: string, ) { - const usedPercent = response.config?.creditUsagePercent; - if (usedPercent === undefined || !Number.isFinite(usedPercent)) { - // A billing read that succeeded but carries no percentage is an account - // with nothing metered yet, not one that can never report: xAI omits the - // field entirely (rather than sending 0) until usage registers, then fills - // it in. - return makeUsageLimits({ checkedAt, windows: [] }); - } const period = response.config?.currentPeriod; const periodType = period?.type?.replace(/^USAGE_PERIOD_TYPE_/, ""); const kind = periodType === "WEEKLY" ? "weekly" : periodType === "MONTHLY" ? "monthly" : "other"; + let usedPercent = response.config?.creditUsagePercent; + if ( + usedPercent === undefined && + (kind === "weekly" || kind === "monthly") && + parsePeriodBoundary(period?.start) < parsePeriodBoundary(period?.end) + ) { + // Grok omits a zero percentage while retaining the complete subscription period. + usedPercent = 0; + } + if (usedPercent === undefined || !Number.isFinite(usedPercent)) { + return makeUsageLimits({ checkedAt, windows: [] }); + } const reset = period?.end ? DateTime.make(period.end) : Option.none(); const window: ServerProviderUsageWindow = { id: "subscription", From 0524a1517951e381313e11104c4d2334e389a1a7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 02:58:26 +0000 Subject: [PATCH 4/5] test(grok): cover malformed billing period starts --- apps/server/src/provider/GrokProvider.test.ts | 101 ++++++++++++++++++ .../provider-grok/src/server/usage.test.ts | 92 ---------------- 2 files changed, 101 insertions(+), 92 deletions(-) diff --git a/apps/server/src/provider/GrokProvider.test.ts b/apps/server/src/provider/GrokProvider.test.ts index 6f532f00bbb54..bbcb5db9f1ea8 100644 --- a/apps/server/src/provider/GrokProvider.test.ts +++ b/apps/server/src/provider/GrokProvider.test.ts @@ -552,6 +552,63 @@ it.layer(NodeServices.layer)("checkGrokProviderStatus", (it) => { describe("Grok usage limits", () => { const checkedAt = "2026-09-16T00:00:00.000Z"; + const weeklyPeriod = { + type: "USAGE_PERIOD_TYPE_WEEKLY", + start: "2026-09-11T03:10:30.159171+00:00", + end: "2026-09-18T03:10:30.159171+00:00", + }; + + it("shows zero usage for complete weekly and monthly periods with no percentage", () => { + for (const [currentPeriod, kind, label, resetsAt] of [ + [weeklyPeriod, "weekly", "Weekly", "2026-09-18T03:10:30.159Z"], + [ + { + type: "USAGE_PERIOD_TYPE_MONTHLY", + start: "2026-09-01T00:00:00.000Z", + end: "2026-10-01T00:00:00.000Z", + }, + "monthly", + "Monthly", + "2026-10-01T00:00:00.000Z", + ], + ] as const) { + const response = { config: { currentPeriod } }; + expect + .soft(grokUsageResponseToLimits(response, checkedAt).windows) + .toEqual([{ id: "subscription", kind, label, usedPercent: 0, resetsAt }]); + } + }); + + it("keeps incomplete, invalid, unordered, and unknown periods unreported", () => { + for (const currentPeriod of [ + undefined, + { ...weeklyPeriod, type: undefined }, + { ...weeklyPeriod, type: "USAGE_PERIOD_TYPE_DAILY" }, + { ...weeklyPeriod, start: undefined }, + { ...weeklyPeriod, end: undefined }, + { ...weeklyPeriod, start: "invalid" }, + { ...weeklyPeriod, end: "invalid" }, + { ...weeklyPeriod, start: weeklyPeriod.end }, + { ...weeklyPeriod, start: weeklyPeriod.end, end: weeklyPeriod.start }, + ]) { + const response = { config: { currentPeriod } }; + expect + .soft(grokUsageResponseToLimits(response, checkedAt).windows, JSON.stringify(response)) + .toEqual([]); + } + }); + + it("rejects impossible calendar dates at either period boundary", () => { + for (const [start, end] of [ + ["2026-02-30T00:00:00.000Z", "2026-03-09T00:00:00.000Z"], + ["2026-02-23T00:00:00.000Z", "2026-02-30T00:00:00.000Z"], + ]) { + const response = { config: { currentPeriod: { ...weeklyPeriod, start, end } } }; + expect + .soft(grokUsageResponseToLimits(response, checkedAt).windows, JSON.stringify(response)) + .toEqual([]); + } + }); it("uses the reported subscription percentage and weekly reset", () => { const limits = grokUsageResponseToLimits( @@ -665,6 +722,50 @@ it.layer(NodeServices.layer)("readGrokAccount", (it) => { ), ); + it.effect("ignores malformed period starts without inventing usage", () => + Effect.gen(function* () { + for (const start of [null, 42]) { + for (const creditUsagePercent of [37.5, undefined]) { + const response = { + config: { + creditUsagePercent, + currentPeriod: { + type: "USAGE_PERIOD_TYPE_WEEKLY", + start, + end: "2026-09-18T03:10:30.159171+00:00", + }, + }, + }; + const { usageLimits } = yield* readGrokAccount({ + HOME: "/definitely/not/a/grok-home", + GROK_AUTH: '{"https://accounts.x.ai/sign-in":{"key":"session-token"}}', + }).pipe( + Effect.provideService( + HttpClient.HttpClient, + HttpClient.make((request) => + Effect.succeed(HttpClientResponse.fromWeb(request, Response.json(response))), + ), + ), + ); + expect.soft(usageLimits.unavailable, JSON.stringify(response)).toBeUndefined(); + expect.soft(usageLimits.windows, JSON.stringify(response)).toEqual( + creditUsagePercent === undefined + ? [] + : [ + { + id: "subscription", + kind: "weekly", + label: "Weekly", + usedPercent: creditUsagePercent, + resetsAt: "2026-09-18T03:10:30.159Z", + }, + ], + ); + } + } + }), + ); + it.effect("does not use unrelated scopes, API keys, or custom auth deployments", () => Effect.gen(function* () { for (const environment of [ diff --git a/packages/provider-grok/src/server/usage.test.ts b/packages/provider-grok/src/server/usage.test.ts index 03ba82cc9ce76..fb73e837805b1 100644 --- a/packages/provider-grok/src/server/usage.test.ts +++ b/packages/provider-grok/src/server/usage.test.ts @@ -1,7 +1,6 @@ import { describe, expect, it } from "@effect/vitest"; import { GROK_COST_USD_TICKS_PER_DOLLAR, parseGrokLine } from "./usage.ts"; -import { grokUsageResponseToLimits } from "./usageLimits.ts"; describe("parseGrokLine", () => { function turnCompleted(overrides?: { @@ -314,94 +313,3 @@ describe("parseGrokLine", () => { expect(records[0]?.timestampMs).toBe(1_786_372_566_000); }); }); - -describe("Grok usage limits", () => { - const checkedAt = "2026-09-16T00:00:00.000Z"; - const weeklyPeriod = { - type: "USAGE_PERIOD_TYPE_WEEKLY", - start: "2026-09-11T03:10:30.159171+00:00", - end: "2026-09-18T03:10:30.159171+00:00", - }; - - it("shows zero usage for complete weekly and monthly periods with no percentage", () => { - for (const [currentPeriod, kind, label, resetsAt] of [ - [weeklyPeriod, "weekly", "Weekly", "2026-09-18T03:10:30.159Z"], - [ - { - type: "USAGE_PERIOD_TYPE_MONTHLY", - start: "2026-09-01T00:00:00.000Z", - end: "2026-10-01T00:00:00.000Z", - }, - "monthly", - "Monthly", - "2026-10-01T00:00:00.000Z", - ], - ] as const) { - const response = { config: { currentPeriod } }; - expect - .soft(grokUsageResponseToLimits(response, checkedAt).windows) - .toEqual([{ id: "subscription", kind, label, usedPercent: 0, resetsAt }]); - } - }); - - it("keeps incomplete, invalid, unordered, and unknown periods unreported", () => { - for (const currentPeriod of [ - undefined, - { ...weeklyPeriod, type: undefined }, - { ...weeklyPeriod, type: "USAGE_PERIOD_TYPE_DAILY" }, - { ...weeklyPeriod, start: undefined }, - { ...weeklyPeriod, end: undefined }, - { ...weeklyPeriod, start: "invalid" }, - { ...weeklyPeriod, end: "invalid" }, - { ...weeklyPeriod, start: weeklyPeriod.end }, - { ...weeklyPeriod, start: weeklyPeriod.end, end: weeklyPeriod.start }, - ]) { - const response = { config: { currentPeriod } }; - expect - .soft(grokUsageResponseToLimits(response, checkedAt).windows, JSON.stringify(response)) - .toEqual([]); - } - }); - - it("rejects impossible calendar dates at either period boundary", () => { - for (const [start, end] of [ - ["2026-02-30T00:00:00.000Z", "2026-03-09T00:00:00.000Z"], - ["2026-02-23T00:00:00.000Z", "2026-02-30T00:00:00.000Z"], - ]) { - const response = { config: { currentPeriod: { ...weeklyPeriod, start, end } } }; - expect - .soft(grokUsageResponseToLimits(response, checkedAt).windows, JSON.stringify(response)) - .toEqual([]); - } - }); - - it("preserves explicit percentages without requiring a complete known period", () => { - expect( - grokUsageResponseToLimits( - { - config: { - creditUsagePercent: 37.5, - currentPeriod: { type: weeklyPeriod.type, end: weeklyPeriod.end }, - }, - }, - checkedAt, - ).windows, - ).toEqual([ - { - id: "subscription", - kind: "weekly", - label: "Weekly", - usedPercent: 37.5, - resetsAt: "2026-09-18T03:10:30.159Z", - }, - ]); - for (const [creditUsagePercent, usedPercent] of [ - [0, 0], - [125, 100], - ] as const) { - expect( - grokUsageResponseToLimits({ config: { creditUsagePercent } }, checkedAt).windows, - ).toEqual([{ id: "subscription", kind: "other", label: "Subscription", usedPercent }]); - } - }); -}); From 589065fc7c130efa3c34338dc1c134d143b5adfd Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 19 Oct 2026 03:03:24 +0000 Subject: [PATCH 5/5] fix(grok): tolerate malformed billing period starts --- packages/provider-grok/src/server/usageLimits.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/provider-grok/src/server/usageLimits.ts b/packages/provider-grok/src/server/usageLimits.ts index a3a82dc4d27df..8036df0dd3e99 100644 --- a/packages/provider-grok/src/server/usageLimits.ts +++ b/packages/provider-grok/src/server/usageLimits.ts @@ -31,7 +31,7 @@ const GrokUsageResponse = Schema.Struct({ currentPeriod: Schema.optional( Schema.Struct({ type: Schema.optional(Schema.String), - start: Schema.optional(Schema.String), + start: Schema.optional(Schema.Unknown), end: Schema.optional(Schema.String), }), ), @@ -71,6 +71,7 @@ export function grokUsageResponseToLimits( if ( usedPercent === undefined && (kind === "weekly" || kind === "monthly") && + typeof period?.start === "string" && parsePeriodBoundary(period?.start) < parsePeriodBoundary(period?.end) ) { // Grok omits a zero percentage while retaining the complete subscription period.