TypeScript
fix(usage): say resets momentarily in the final minute (#17869)
Exotic262532709011
diff --git a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx b/apps/mobile/src/features/usage/UsageLimitsPooled.tsxindex 1dc9fc70433..be9adb28348 100644--- a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx+++ b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx@@ -8,7 +8,6 @@ import {collectLimitPools,cursorUsageWindowDetails,displayLimitWindows,- formatDuration,formatResetsIn,remainingPercent,type LimitAccount,@@ -123,7 +122,9 @@ function PoolWindowCard({{nextRefill ? (<Text className="text-xs tabular-nums text-foreground-muted">↻ +{nextRefill.restoresPercent}%{" "}- {nextRefill.at <= now ? "now" : `in ${formatDuration(nextRefill.at - now)}`}+ {formatResetsIn(nextRefill.member.window, now)+ ?.replace("resets in ", "in ")+ .replace("resets now", "now")}</Text>) : null}<View className="flex-row gap-1">diff --git a/packages/shared/src/usageLimits.test.ts b/packages/shared/src/usageLimits.test.tsindex 3b74ffa3aa1..657b84fd731 100644--- a/packages/shared/src/usageLimits.test.ts+++ b/packages/shared/src/usageLimits.test.ts@@ -56,6 +56,20 @@ function provider(overrides: Partial<ServerProvider>): ServerProvider {}describe("pace", () => {+ it.each([+ ["2026-09-03T12:01:00.000Z", "resets in 1m"],+ ["2026-09-03T12:00:59.999Z", "Resets momentarily"],+ ["2026-09-03T12:00:00.001Z", "Resets momentarily"],+ ["2026-09-03T12:00:00.000Z", "resets now"],+ ["2026-09-03T11:59:59.999Z", "resets now"],+ ])("formats the reset boundary at %s", (resetsAt, label) => {+ expect(formatResetsIn({ ...window, resetsAt }, now)).toBe(label);+ });++ it("ignores invalid reset timestamps", () => {+ expect(formatResetsIn({ ...window, resetsAt: "invalid" }, now)).toBeNull();+ });+it("places the clock three fifths through a five-hour window with two hours left", () => {expect(elapsedShare(window, now)).toBeCloseTo(0.6);expect(paceOf(window, now)).toBe("under");diff --git a/packages/shared/src/usageLimits.ts b/packages/shared/src/usageLimits.tsindex 4a2f07f1df6..dd24b20c7e7 100644--- a/packages/shared/src/usageLimits.ts+++ b/packages/shared/src/usageLimits.ts@@ -607,7 +607,9 @@ export function formatDuration(ms: number): string {export function formatResetsIn(window: ServerProviderUsageWindow, now: number): string | null {const resetsAt = resetMillis(window);if (resetsAt === null) return null;- return resetsAt <= now ? "resets now" : `resets in ${formatDuration(resetsAt - now)}`;+ if (resetsAt <= now) return "resets now";+ if (resetsAt - now < MINUTE) return "Resets momentarily";+ return `resets in ${formatDuration(resetsAt - now)}`;}/** Limit commands are served by T3 from the same snapshots as Usage → Limits. */