Skip to content
TypeScript

fix(usage): show empty sessions when weekly quota is exhausted (#20349)

Alex Chambers5b723850652a
diff --git a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx
index 04969f71410..4aabf050014 100644
--- a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx
+++ b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx
@@ -43,11 +43,11 @@ function accountName(account: LimitAccount) {
function AccountSegment({
remaining,
color,
- pending,
+ refillPercent,
}: {
readonly remaining: number;
readonly color: string;
- readonly pending: boolean;
+ readonly refillPercent: number;
}) {
const patternId = useId().replace(/:/g, "");
const [size, setSize] = useState({ width: 0, height: 0 });
@@ -70,10 +70,10 @@ function AccountSegment({
<Path d="M-1 1L1 -1M0 6L6 0M5 7L7 5" stroke={color} strokeWidth={1} opacity={0.22} />
</Pattern>
</Defs>
- {pending ? (
+ {refillPercent > 0 ? (
<Rect
- x={`${remaining}%`}
- width={`${100 - remaining}%`}
+ x={`${100 - Math.min(100 - remaining, refillPercent)}%`}
+ width={`${Math.min(100 - remaining, refillPercent)}%`}
height="100%"
fill={`url(#${patternId})`}
/>
@@ -142,8 +142,10 @@ function PoolWindowCard({
</Text>
) : null}
<View className="flex-row gap-1">
- {pool.columns.map(({ account, window }, index) => {
- if (!window) return <View key={account.key} className="h-7 min-w-0 flex-1" />;
+ {pool.columns.map((member, index) => {
+ if (!member.window)
+ return <View key={member.account.key} className="h-7 min-w-0 flex-1" />;
+ const { account, window } = member;
return (
<Pressable
key={account.key}
@@ -156,7 +158,7 @@ function PoolWindowCard({
<AccountSegment
remaining={remainingPercent(window)}
color={color}
- pending={Boolean(window.resetsAt)}
+ refillPercent={window.resetsAt ? member.refillPercent : 0}
/>
<View pointerEvents="none" className="absolute inset-0 items-center justify-center">
<Text className="text-xs font-t3-medium tabular-nums text-foreground">
diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx
index a50628c4745..379c6f9d102 100644
--- a/apps/web/src/components/usage/UsageLimitsPooled.tsx
+++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx
@@ -209,6 +209,7 @@ function PoolSegment({
account,
window,
reset,
+ refillPercent,
color,
now,
index,
@@ -217,6 +218,7 @@ function PoolSegment({
readonly account: LimitAccount;
readonly window: LimitPoolMember["window"];
readonly reset: LimitPoolWindow["resets"][number] | undefined;
+ readonly refillPercent: number;
readonly color: string;
readonly now: number;
readonly index: number;
@@ -244,12 +246,12 @@ function PoolSegment({
className="absolute inset-y-0 left-0 rounded-md opacity-35"
style={{ width: `${remaining}%`, backgroundColor: color }}
/>
- {remaining < 100 && reset ? (
+ {remaining < 100 && reset && refillPercent > 0 ? (
<div
aria-hidden
className="absolute inset-y-0 right-0 opacity-20"
style={{
- width: `${100 - remaining}%`,
+ width: `${Math.min(100 - remaining, refillPercent)}%`,
backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
}}
/>
@@ -440,6 +442,7 @@ function PoolBar({
account={member.account}
window={member.window}
reset={restores.get(member.account.key)}
+ refillPercent={member.refillPercent}
color={color}
now={now}
index={position + 1}
diff --git a/docs/user/usage.md b/docs/user/usage.md
index ed1dd19ce1a..8c647e6caf5 100644
--- a/docs/user/usage.md
+++ b/docs/user/usage.md
@@ -81,8 +81,9 @@ the dialog.
**Usage → Limits** pools every subscription account it can see per provider, so with several Codex
or Claude accounts across your environments and hubs you read one number per window rather than a
list. Each window card shows how much of the pool is left and a bar with one segment per account,
-kept in the same column across windows. Accounts are ordered by their 5-hour reset, soonest
-first, or by the first available window when no account reports a 5-hour limit. A gap means the
+kept in the same column across windows. Accounts are ordered by their next 5-hour refill, soonest
+first. For an account with no weekly quota left, this is when its session becomes usable again.
+The first available window is used when no account reports a 5-hour limit. A gap means the
account does not report that window. When the provider reports reset times, the card also says
when the next reset lands and how much it hands back. The hatched
part of a segment is what that reset restores. Tap a segment or account row for the account's plan,
@@ -95,6 +96,12 @@ the bar show each account's quota, countdown, and credits. Tap a row to open its
The same account signed in on more than one environment, or reported by a hub as well, counts once.
Filter with the environment dropdown to see what a single machine has.
+When a Claude or Codex account has no overall weekly quota left, its pooled session contribution
+shows 0% left. The next refill depends on both reset times: an exhausted session must also reset,
+and a partly spent session may only regain its unused portion when the week resets. Missing or
+stale reset times have no refill estimate; refresh Limits for a new reading. Claude's
+model-specific weekly allowances keep their reported values.
+
Opening Limits checks the selected connected environments automatically. Each client waits at
least five minutes between automatic checks of an environment, including after a failed check.
If a window still looks stale, refresh Limits to re-check every provider and hub.
diff --git a/packages/shared/src/usageLimits.test.ts b/packages/shared/src/usageLimits.test.ts
index d8e16dc45d8..50c0d3080c4 100644
--- a/packages/shared/src/usageLimits.test.ts
+++ b/packages/shared/src/usageLimits.test.ts
@@ -862,6 +862,63 @@ describe("pooled account columns", () => {
row.columns.map((member) => (member.window ? member.account.key : null)),
);
+ it.each([
+ ["claudeAgent", "13:00", 40, "14:00", 100],
+ ["codex", "14:00", 100, "14:00", 100],
+ ["claudeAgent", "15:00", 100, "15:00", 100],
+ ["codex", "15:00", 40, "14:00", 60],
+ ] as const)(
+ "%s session resetting at %s with %i percent spent becomes usable at %s with %i percent restored",
+ (driver, sessionReset, usedPercent, usableAt, restoresPercent) => {
+ const at = (time: string) => `2026-09-03T${time}:00.000Z`;
+ const a = {
+ ...account("a", [
+ {
+ ...window,
+ id: driver === "codex" ? "primary" : window.id,
+ usedPercent,
+ resetsAt: at(sessionReset),
+ },
+ {
+ ...weekly,
+ id: driver === "codex" ? "secondary" : weekly.id,
+ usedPercent: 100,
+ resetsAt: at("14:00"),
+ },
+ ]),
+ driver: ProviderDriverKind.make(driver),
+ };
+ const [session] = collectLimitPools([a], now)[0]!.windows;
+ expect.soft(session?.remainingPercent).toBe(0);
+ expect(session?.resets[0]).toMatchObject({
+ at: Date.parse(at(usableAt)),
+ restoresPercent,
+ });
+ },
+ );
+
+ it("excludes weekly-blocked sessions from the pool without changing snapshots or model allowances", () => {
+ const blocked = account("blocked", [
+ window,
+ { ...weekly, usedPercent: 100 },
+ { ...weekly, id: "seven_day_fable", usedPercent: 20 },
+ ]);
+ const accounts = [
+ blocked,
+ account("available", [
+ { ...window, usedPercent: 20 },
+ { ...weekly, usedPercent: 99 },
+ { ...weekly, id: "seven_day_fable", usedPercent: 40 },
+ ]),
+ { ...blocked, key: "cursor", driver: ProviderDriverKind.make("cursor") },
+ ];
+ const snapshot = structuredClone(accounts);
+ const [claude, cursor] = collectLimitPools(accounts, now);
+ expect.soft(claude?.windows.map((row) => row.remainingPercent)).toEqual([40, 1, 70]);
+ expect.soft(cursor?.windows.map((row) => row.remainingPercent)).toEqual([60, 0, 80]);
+ expect(accounts).toEqual(snapshot);
+ });
+
it("keeps session columns across rows with opposite reset and usage orders", () => {
const accounts = [
account("a", [
@@ -884,6 +941,52 @@ describe("pooled account columns", () => {
expect(keys(collectLimitPools(accounts.toReversed(), now)[0]!)).toEqual(keys(pool!));
});
+ it.each([undefined, "invalid", "2026-09-03T11:30:00.000Z"])(
+ "keeps blocked sessions empty without predicting a refill from a missing or stale clock (%s)",
+ (resetsAt) => {
+ const [pool] = collectLimitPools(
+ [
+ account("session-clock", [
+ { ...window, resetsAt },
+ { ...weekly, usedPercent: 100 },
+ ]),
+ account("weekly-clock", [window, { ...weekly, usedPercent: 100, resetsAt }]),
+ ],
+ now,
+ );
+ expect(pool!.windows[0]).toMatchObject({ remainingPercent: 0, pace: null, resets: [] });
+ expect(pool!.windows[0]!.columns.map((column) => column.window?.resetsAt)).toEqual([
+ undefined,
+ undefined,
+ ]);
+ },
+ );
+
+ it("orders by usable session refill and clears suppression after a fresh weekly reading", () => {
+ const blocked = account("blocked", [
+ { ...window, resetsAt: "2026-09-03T13:00:00.000Z" },
+ { ...weekly, usedPercent: 100, resetsAt: "2026-09-03T15:00:00.000Z" },
+ ]);
+ const available = account("available", [window]);
+ const [before] = collectLimitPools([blocked, available], now);
+ expect(before!.accounts.map((account) => account.key)).toEqual(["available", "blocked"]);
+ expect(before!.windows[0]!.remainingPercent).toBe(30);
+ const refreshed = {
+ ...blocked,
+ limits: {
+ checkedAt: "2026-09-03T12:00:00.000Z",
+ windows: [blocked.limits.windows[0]!, { ...weekly, usedPercent: 10 }],
+ },
+ };
+ const [after] = collectLimitPools([refreshed, available], now);
+ expect(after!.accounts.map((account) => account.key)).toEqual(["blocked", "available"]);
+ expect(after!.windows[0]!.remainingPercent).toBe(60);
+ expect(after!.windows[0]!.resets[0]).toMatchObject({
+ at: Date.parse("2026-09-03T13:00:00.000Z"),
+ restoresPercent: 20,
+ });
+ });
+
it("preserves gaps without counting missing windows toward pooled quota", () => {
const [pool] = collectLimitPools(
[
diff --git a/packages/shared/src/usageLimits.ts b/packages/shared/src/usageLimits.ts
index 4e618c6d244..5e124174ddb 100644
--- a/packages/shared/src/usageLimits.ts
+++ b/packages/shared/src/usageLimits.ts
@@ -313,6 +313,7 @@ export function collectLimitNotices(presentations: LimitPresentations): readonly
export interface LimitPoolMember {
readonly account: LimitAccount;
readonly window: ServerProviderUsageWindow;
+ readonly refillPercent: number;
}
export interface LimitPoolWindow {
@@ -320,10 +321,9 @@ export interface LimitPoolWindow {
readonly kind: ServerProviderUsageWindow["kind"];
readonly label: string;
readonly members: readonly LimitPoolMember[];
- readonly columns: ReadonlyArray<{
- readonly account: LimitAccount;
- readonly window: ServerProviderUsageWindow | null;
- }>;
+ readonly columns: ReadonlyArray<
+ LimitPoolMember | { readonly account: LimitAccount; readonly window: null }
+ >;
readonly remainingPercent: number;
readonly usedPercent: number;
readonly pace: LimitPace | null;
@@ -385,7 +385,10 @@ export function collectLimitPools(
const window = account.limits.windows.find(
(window) => orderWindow && poolKey(driver, window) === poolKey(driver, orderWindow),
);
- return (window ? resetMillis(window) : null) ?? Number.POSITIVE_INFINITY;
+ return (
+ (window ? resetMillis(poolMember(account, window, now).window) : null) ??
+ Number.POSITIVE_INFINITY
+ );
};
const sorted = [...members].sort(
(left, right) =>
@@ -410,17 +413,63 @@ function poolKey(driver: ServerProvider["driver"], window: ServerProviderUsageWi
return driver === "codex" ? window.kind : `${window.kind}:${window.id}`;
}
+function poolMember(account: LimitAccount, reported: ServerProviderUsageWindow, now: number) {
+ const spentWeekly =
+ reported.kind === "session"
+ ? account.limits.windows.find(
+ (window) =>
+ window.usedPercent >= 100 &&
+ (account.driver === "claudeAgent"
+ ? window.id === "seven_day"
+ : account.driver === "codex" && window.kind === "weekly"),
+ )
+ : undefined;
+ if (!spentWeekly) return { account, window: reported, refillPercent: reported.usedPercent };
+
+ const weeklyReset = resetMillis(spentWeekly);
+ const sessionReset = resetMillis(reported);
+ const cutoff = Math.max(now, Date.parse(account.limits.checkedAt));
+ let resetsAt: string | undefined;
+ let refillPercent = 0;
+ // A stale or missing clock cannot tell us when blocked quota becomes usable.
+ if (
+ weeklyReset !== null &&
+ sessionReset !== null &&
+ weeklyReset > cutoff &&
+ sessionReset > cutoff
+ ) {
+ if (sessionReset <= weeklyReset) {
+ resetsAt = spentWeekly.resetsAt;
+ refillPercent = 100;
+ } else if (reported.usedPercent >= 100) {
+ resetsAt = reported.resetsAt;
+ refillPercent = 100;
+ } else {
+ resetsAt = spentWeekly.resetsAt;
+ refillPercent = 100 - Math.max(0, Math.min(100, reported.usedPercent));
+ }
+ }
+ return {
+ account,
+ // Suppression is not session spending, so it has no session pace clock.
+ window: { ...reported, usedPercent: 100, resetsAt, windowDurationMins: undefined },
+ refillPercent,
+ };
+}
+
function poolWindows(accounts: readonly LimitAccount[], now: number): readonly LimitPoolWindow[] {
const byKey = new Map<string, LimitPoolMember[]>();
for (const account of accounts) {
- for (const window of account.limits.windows) {
+ for (const reported of account.limits.windows) {
+ const member = poolMember(account, reported, now);
+ const { window } = member;
const pooled = poolKey(account.driver, window);
const key = byKey.get(pooled)?.some((member) => member.account === account)
? `${window.kind}:${window.id}`
: pooled;
const list = byKey.get(key);
- if (list) list.push({ account, window });
- else byKey.set(key, [{ account, window }]);
+ if (list) list.push(member);
+ else byKey.set(key, [member]);
}
}
const pools = [...byKey].map(([key, members]): LimitPoolWindow => {
@@ -447,7 +496,7 @@ function poolWindows(accounts: readonly LimitAccount[], now: number): readonly L
{
member,
at,
- restoresPercent: Math.round(member.window.usedPercent / members.length),
+ restoresPercent: Math.round(member.refillPercent / members.length),
},
];
})