Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(plan-usage): keep a 5-hour model line from hiding that model's scoped weekly limit

AdityaUmalebd35f3e68b9e
diff --git a/server/plan-usage.test.ts b/server/plan-usage.test.ts
index 533c4a2bc6..ded301975f 100644
--- a/server/plan-usage.test.ts
+++ b/server/plan-usage.test.ts
@@ -178,6 +178,17 @@ describe("plan usage parsers", () => {
expect(parsed.extra).toEqual([expect.objectContaining({ label: "Fable", usedPercent: 94 })]);
});
+ it("still shows a model's weekly limit from the limits list when only its 5-hour window comes as a key", () => {
+ const parsed = parseClaudeUsage({
+ five_hour_fable: { utilization: 30 },
+ limits: [{ kind: "weekly_scoped", percent: 95, scope: { model: { display_name: "Fable" } } }],
+ });
+ expect(parsed.models).toEqual([
+ { name: "Fable", windows: [expect.objectContaining({ label: "Weekly", usedPercent: 95 })] },
+ ]);
+ expect(parsed.extra).toEqual([expect.objectContaining({ label: "Fable", usedPercent: 30 })]);
+ });
+
it("classifies Codex windows by duration and does not stuff a 30-day window into weekly", () => {
const parsed = parseCodexUsage({
plan_type: "plus",
diff --git a/server/plan-usage.ts b/server/plan-usage.ts
index 7882ff4ebd..3949ab2775 100644
--- a/server/plan-usage.ts
+++ b/server/plan-usage.ts
@@ -171,6 +171,7 @@ export function parseClaudeUsage(body: unknown): PlanWindows {
const extra: PlanExtra[] = [];
const models: PlanModelUsage[] = [];
if (root) {
+ const weeklyExtra: string[] = [];
for (const [key, value] of Object.entries(root)) {
if (key === "five_hour" || key === "seven_day" || key === "spend" || key === "extra_usage") continue;
if (!/^[a-z][a-z0-9_]{0,40}$/i.test(key)) continue;
@@ -178,9 +179,13 @@ export function parseClaudeUsage(body: unknown): PlanWindows {
if (!window) continue;
const model = claudeModelWindow(key);
if (model) addModelWindow(models, model.name, extraLine(model.window, window));
- else extra.push(extraLine(claudeExtraLabel(key), window));
+ else {
+ const label = claudeExtraLabel(key);
+ extra.push(extraLine(label, window));
+ if (key.startsWith("seven_day_")) weeklyExtra.push(label);
+ }
}
- const keyed = [...models.filter((model) => model.windows.some((line) => line.label === "Weekly")).map((model) => model.name), ...extra.map((line) => line.label)];
+ const keyed = [...models.filter((model) => model.windows.some((line) => line.label === "Weekly")).map((model) => model.name), ...weeklyExtra];
for (const limit of claudeScopedWeekly(root.limits, keyed)) addModelWindow(models, limit.name, extraLine("Weekly", openWindow(limit.usedPercent, isoOrNull(limit.resetsAt))));
}
sortModelWindows(models);