From e16d051d9fb41f5cb3307eed3d49e9572dc2d077 Mon Sep 17 00:00:00 2001 From: Sid Date: Sat, 28 Feb 2026 09:23:01 +0800 Subject: [PATCH] fix: label Codex weekly usage window as "Week" instead of "Day" (#26267) The secondary window label logic treated any window >= 24h as "Day", but Codex plans can have a weekly (604800s / 168h) quota window. The reset timer showed "resets 2d 4h" while the label said "Day", which was confusing. Now windows >= 168h are labeled "Week", >= 24h remain "Day", and shorter windows show the hour count. Closes #25812 Co-authored-by: Cursor --- src/infra/provider-usage.fetch.codex.test.ts | 25 ++++++++++++++++++++ src/infra/provider-usage.fetch.codex.ts | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/infra/provider-usage.fetch.codex.test.ts b/src/infra/provider-usage.fetch.codex.test.ts index cbbfbd4db..6078e2a9b 100644 --- a/src/infra/provider-usage.fetch.codex.test.ts +++ b/src/infra/provider-usage.fetch.codex.test.ts @@ -54,4 +54,29 @@ describe("fetchCodexUsage", () => { { label: "Day", usedPercent: 75, resetAt: 1_700_050_000_000 }, ]); }); + + it("labels weekly secondary window as Week", async () => { + const mockFetch = createProviderUsageFetch(async () => + makeResponse(200, { + rate_limit: { + primary_window: { + limit_window_seconds: 10_800, + used_percent: 7, + reset_at: 1_700_000_000, + }, + secondary_window: { + limit_window_seconds: 604_800, + used_percent: 10, + reset_at: 1_700_500_000, + }, + }, + }), + ); + + const result = await fetchCodexUsage("token", undefined, 5000, mockFetch); + expect(result.windows).toEqual([ + { label: "3h", usedPercent: 7, resetAt: 1_700_000_000_000 }, + { label: "Week", usedPercent: 10, resetAt: 1_700_500_000_000 }, + ]); + }); }); diff --git a/src/infra/provider-usage.fetch.codex.ts b/src/infra/provider-usage.fetch.codex.ts index 4d4cfc7fd..28d155a6b 100644 --- a/src/infra/provider-usage.fetch.codex.ts +++ b/src/infra/provider-usage.fetch.codex.ts @@ -65,7 +65,7 @@ export async function fetchCodexUsage( if (data.rate_limit?.secondary_window) { const sw = data.rate_limit.secondary_window; const windowHours = Math.round((sw.limit_window_seconds || 86400) / 3600); - const label = windowHours >= 24 ? "Day" : `${windowHours}h`; + const label = windowHours >= 168 ? "Week" : windowHours >= 24 ? "Day" : `${windowHours}h`; windows.push({ label, usedPercent: clampPercent(sw.used_percent || 0),