@devries-cameron20 / t3code-1 / commits / 5b72385065
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

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

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Chambers committed Oct 19, 2026 at 07:36 UTC 5b723850652ae3628683de48e60ef3ba1ebbdcad
5 files changed +185 -21
apps/mobile/src/features/usage/UsageLimitsPooled.tsx
+10 -8
@@ -43,11 +43,11 @@ function accountName(account: LimitAccount) {
43 function AccountSegment({
44 remaining,
45 color,
46 - pending,
46 + refillPercent,
47 }: {
48 readonly remaining: number;
49 readonly color: string;
50 - readonly pending: boolean;
50 + readonly refillPercent: number;
51 }) {
52 const patternId = useId().replace(/:/g, "");
53 const [size, setSize] = useState({ width: 0, height: 0 });
@@ -70,10 +70,10 @@ function AccountSegment({
70 <Path d="M-1 1L1 -1M0 6L6 0M5 7L7 5" stroke={color} strokeWidth={1} opacity={0.22} />
71 </Pattern>
72 </Defs>
73 - {pending ? (
73 + {refillPercent > 0 ? (
74 <Rect
75 - x={`${remaining}%`}
76 - width={`${100 - remaining}%`}
75 + x={`${100 - Math.min(100 - remaining, refillPercent)}%`}
76 + width={`${Math.min(100 - remaining, refillPercent)}%`}
77 height="100%"
78 fill={`url(#${patternId})`}
79 />
@@ -142,8 +142,10 @@ function PoolWindowCard({
142 </Text>
143 ) : null}
144 <View className="flex-row gap-1">
145 - {pool.columns.map(({ account, window }, index) => {
146 - if (!window) return <View key={account.key} className="h-7 min-w-0 flex-1" />;
145 + {pool.columns.map((member, index) => {
146 + if (!member.window)
147 + return <View key={member.account.key} className="h-7 min-w-0 flex-1" />;
148 + const { account, window } = member;
149 return (
150 <Pressable
151 key={account.key}
@@ -156,7 +158,7 @@ function PoolWindowCard({
158 <AccountSegment
159 remaining={remainingPercent(window)}
160 color={color}
159 - pending={Boolean(window.resetsAt)}
161 + refillPercent={window.resetsAt ? member.refillPercent : 0}
162 />
163 <View pointerEvents="none" className="absolute inset-0 items-center justify-center">
164 <Text className="text-xs font-t3-medium tabular-nums text-foreground">
apps/web/src/components/usage/UsageLimitsPooled.tsx
+5 -2
@@ -209,6 +209,7 @@ function PoolSegment({
209 account,
210 window,
211 reset,
212 + refillPercent,
213 color,
214 now,
215 index,
@@ -217,6 +218,7 @@ function PoolSegment({
218 readonly account: LimitAccount;
219 readonly window: LimitPoolMember["window"];
220 readonly reset: LimitPoolWindow["resets"][number] | undefined;
221 + readonly refillPercent: number;
222 readonly color: string;
223 readonly now: number;
224 readonly index: number;
@@ -244,12 +246,12 @@ function PoolSegment({
246 className="absolute inset-y-0 left-0 rounded-md opacity-35"
247 style={{ width: `${remaining}%`, backgroundColor: color }}
248 />
247 - {remaining < 100 && reset ? (
249 + {remaining < 100 && reset && refillPercent > 0 ? (
250 <div
251 aria-hidden
252 className="absolute inset-y-0 right-0 opacity-20"
253 style={{
252 - width: `${100 - remaining}%`,
254 + width: `${Math.min(100 - remaining, refillPercent)}%`,
255 backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
256 }}
257 />
@@ -440,6 +442,7 @@ function PoolBar({
442 account={member.account}
443 window={member.window}
444 reset={restores.get(member.account.key)}
445 + refillPercent={member.refillPercent}
446 color={color}
447 now={now}
448 index={position + 1}
docs/user/usage.md
+9 -2
@@ -81,8 +81,9 @@ the dialog.
81 **Usage → Limits** pools every subscription account it can see per provider, so with several Codex
82 or Claude accounts across your environments and hubs you read one number per window rather than a
83 list. Each window card shows how much of the pool is left and a bar with one segment per account,
84 -kept in the same column across windows. Accounts are ordered by their 5-hour reset, soonest
85 -first, or by the first available window when no account reports a 5-hour limit. A gap means the
84 +kept in the same column across windows. Accounts are ordered by their next 5-hour refill, soonest
85 +first. For an account with no weekly quota left, this is when its session becomes usable again.
86 +The first available window is used when no account reports a 5-hour limit. A gap means the
87 account does not report that window. When the provider reports reset times, the card also says
88 when the next reset lands and how much it hands back. The hatched
89 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
96 The same account signed in on more than one environment, or reported by a hub as well, counts once.
97 Filter with the environment dropdown to see what a single machine has.
98
99 +When a Claude or Codex account has no overall weekly quota left, its pooled session contribution
100 +shows 0% left. The next refill depends on both reset times: an exhausted session must also reset,
101 +and a partly spent session may only regain its unused portion when the week resets. Missing or
102 +stale reset times have no refill estimate; refresh Limits for a new reading. Claude's
103 +model-specific weekly allowances keep their reported values.
104 +
105 Opening Limits checks the selected connected environments automatically. Each client waits at
106 least five minutes between automatic checks of an environment, including after a failed check.
107 If a window still looks stale, refresh Limits to re-check every provider and hub.
packages/shared/src/usageLimits.test.ts
+103
@@ -862,6 +862,63 @@ describe("pooled account columns", () => {
862 row.columns.map((member) => (member.window ? member.account.key : null)),
863 );
864
865 + it.each([
866 + ["claudeAgent", "13:00", 40, "14:00", 100],
867 + ["codex", "14:00", 100, "14:00", 100],
868 + ["claudeAgent", "15:00", 100, "15:00", 100],
869 + ["codex", "15:00", 40, "14:00", 60],
870 + ] as const)(
871 + "%s session resetting at %s with %i percent spent becomes usable at %s with %i percent restored",
872 + (driver, sessionReset, usedPercent, usableAt, restoresPercent) => {
873 + const at = (time: string) => `2026-09-03T${time}:00.000Z`;
874 + const a = {
875 + ...account("a", [
876 + {
877 + ...window,
878 + id: driver === "codex" ? "primary" : window.id,
879 + usedPercent,
880 + resetsAt: at(sessionReset),
881 + },
882 + {
883 + ...weekly,
884 + id: driver === "codex" ? "secondary" : weekly.id,
885 + usedPercent: 100,
886 + resetsAt: at("14:00"),
887 + },
888 + ]),
889 + driver: ProviderDriverKind.make(driver),
890 + };
891 + const [session] = collectLimitPools([a], now)[0]!.windows;
892 + expect.soft(session?.remainingPercent).toBe(0);
893 + expect(session?.resets[0]).toMatchObject({
894 + at: Date.parse(at(usableAt)),
895 + restoresPercent,
896 + });
897 + },
898 + );
899 +
900 + it("excludes weekly-blocked sessions from the pool without changing snapshots or model allowances", () => {
901 + const blocked = account("blocked", [
902 + window,
903 + { ...weekly, usedPercent: 100 },
904 + { ...weekly, id: "seven_day_fable", usedPercent: 20 },
905 + ]);
906 + const accounts = [
907 + blocked,
908 + account("available", [
909 + { ...window, usedPercent: 20 },
910 + { ...weekly, usedPercent: 99 },
911 + { ...weekly, id: "seven_day_fable", usedPercent: 40 },
912 + ]),
913 + { ...blocked, key: "cursor", driver: ProviderDriverKind.make("cursor") },
914 + ];
915 + const snapshot = structuredClone(accounts);
916 + const [claude, cursor] = collectLimitPools(accounts, now);
917 + expect.soft(claude?.windows.map((row) => row.remainingPercent)).toEqual([40, 1, 70]);
918 + expect.soft(cursor?.windows.map((row) => row.remainingPercent)).toEqual([60, 0, 80]);
919 + expect(accounts).toEqual(snapshot);
920 + });
921 +
922 it("keeps session columns across rows with opposite reset and usage orders", () => {
923 const accounts = [
924 account("a", [
@@ -884,6 +941,52 @@ describe("pooled account columns", () => {
941 expect(keys(collectLimitPools(accounts.toReversed(), now)[0]!)).toEqual(keys(pool!));
942 });
943
944 + it.each([undefined, "invalid", "2026-09-03T11:30:00.000Z"])(
945 + "keeps blocked sessions empty without predicting a refill from a missing or stale clock (%s)",
946 + (resetsAt) => {
947 + const [pool] = collectLimitPools(
948 + [
949 + account("session-clock", [
950 + { ...window, resetsAt },
951 + { ...weekly, usedPercent: 100 },
952 + ]),
953 + account("weekly-clock", [window, { ...weekly, usedPercent: 100, resetsAt }]),
954 + ],
955 + now,
956 + );
957 + expect(pool!.windows[0]).toMatchObject({ remainingPercent: 0, pace: null, resets: [] });
958 + expect(pool!.windows[0]!.columns.map((column) => column.window?.resetsAt)).toEqual([
959 + undefined,
960 + undefined,
961 + ]);
962 + },
963 + );
964 +
965 + it("orders by usable session refill and clears suppression after a fresh weekly reading", () => {
966 + const blocked = account("blocked", [
967 + { ...window, resetsAt: "2026-09-03T13:00:00.000Z" },
968 + { ...weekly, usedPercent: 100, resetsAt: "2026-09-03T15:00:00.000Z" },
969 + ]);
970 + const available = account("available", [window]);
971 + const [before] = collectLimitPools([blocked, available], now);
972 + expect(before!.accounts.map((account) => account.key)).toEqual(["available", "blocked"]);
973 + expect(before!.windows[0]!.remainingPercent).toBe(30);
974 + const refreshed = {
975 + ...blocked,
976 + limits: {
977 + checkedAt: "2026-09-03T12:00:00.000Z",
978 + windows: [blocked.limits.windows[0]!, { ...weekly, usedPercent: 10 }],
979 + },
980 + };
981 + const [after] = collectLimitPools([refreshed, available], now);
982 + expect(after!.accounts.map((account) => account.key)).toEqual(["blocked", "available"]);
983 + expect(after!.windows[0]!.remainingPercent).toBe(60);
984 + expect(after!.windows[0]!.resets[0]).toMatchObject({
985 + at: Date.parse("2026-09-03T13:00:00.000Z"),
986 + restoresPercent: 20,
987 + });
988 + });
989 +
990 it("preserves gaps without counting missing windows toward pooled quota", () => {
991 const [pool] = collectLimitPools(
992 [
packages/shared/src/usageLimits.ts
+58 -9
@@ -313,6 +313,7 @@ export function collectLimitNotices(presentations: LimitPresentations): readonly
313 export interface LimitPoolMember {
314 readonly account: LimitAccount;
315 readonly window: ServerProviderUsageWindow;
316 + readonly refillPercent: number;
317 }
318
319 export interface LimitPoolWindow {
@@ -320,10 +321,9 @@ export interface LimitPoolWindow {
321 readonly kind: ServerProviderUsageWindow["kind"];
322 readonly label: string;
323 readonly members: readonly LimitPoolMember[];
323 - readonly columns: ReadonlyArray<{
324 - readonly account: LimitAccount;
325 - readonly window: ServerProviderUsageWindow | null;
326 - }>;
324 + readonly columns: ReadonlyArray<
325 + LimitPoolMember | { readonly account: LimitAccount; readonly window: null }
326 + >;
327 readonly remainingPercent: number;
328 readonly usedPercent: number;
329 readonly pace: LimitPace | null;
@@ -385,7 +385,10 @@ export function collectLimitPools(
385 const window = account.limits.windows.find(
386 (window) => orderWindow && poolKey(driver, window) === poolKey(driver, orderWindow),
387 );
388 - return (window ? resetMillis(window) : null) ?? Number.POSITIVE_INFINITY;
388 + return (
389 + (window ? resetMillis(poolMember(account, window, now).window) : null) ??
390 + Number.POSITIVE_INFINITY
391 + );
392 };
393 const sorted = [...members].sort(
394 (left, right) =>
@@ -410,17 +413,63 @@ function poolKey(driver: ServerProvider["driver"], window: ServerProviderUsageWi
413 return driver === "codex" ? window.kind : `${window.kind}:${window.id}`;
414 }
415
416 +function poolMember(account: LimitAccount, reported: ServerProviderUsageWindow, now: number) {
417 + const spentWeekly =
418 + reported.kind === "session"
419 + ? account.limits.windows.find(
420 + (window) =>
421 + window.usedPercent >= 100 &&
422 + (account.driver === "claudeAgent"
423 + ? window.id === "seven_day"
424 + : account.driver === "codex" && window.kind === "weekly"),
425 + )
426 + : undefined;
427 + if (!spentWeekly) return { account, window: reported, refillPercent: reported.usedPercent };
428 +
429 + const weeklyReset = resetMillis(spentWeekly);
430 + const sessionReset = resetMillis(reported);
431 + const cutoff = Math.max(now, Date.parse(account.limits.checkedAt));
432 + let resetsAt: string | undefined;
433 + let refillPercent = 0;
434 + // A stale or missing clock cannot tell us when blocked quota becomes usable.
435 + if (
436 + weeklyReset !== null &&
437 + sessionReset !== null &&
438 + weeklyReset > cutoff &&
439 + sessionReset > cutoff
440 + ) {
441 + if (sessionReset <= weeklyReset) {
442 + resetsAt = spentWeekly.resetsAt;
443 + refillPercent = 100;
444 + } else if (reported.usedPercent >= 100) {
445 + resetsAt = reported.resetsAt;
446 + refillPercent = 100;
447 + } else {
448 + resetsAt = spentWeekly.resetsAt;
449 + refillPercent = 100 - Math.max(0, Math.min(100, reported.usedPercent));
450 + }
451 + }
452 + return {
453 + account,
454 + // Suppression is not session spending, so it has no session pace clock.
455 + window: { ...reported, usedPercent: 100, resetsAt, windowDurationMins: undefined },
456 + refillPercent,
457 + };
458 +}
459 +
460 function poolWindows(accounts: readonly LimitAccount[], now: number): readonly LimitPoolWindow[] {
461 const byKey = new Map<string, LimitPoolMember[]>();
462 for (const account of accounts) {
416 - for (const window of account.limits.windows) {
463 + for (const reported of account.limits.windows) {
464 + const member = poolMember(account, reported, now);
465 + const { window } = member;
466 const pooled = poolKey(account.driver, window);
467 const key = byKey.get(pooled)?.some((member) => member.account === account)
468 ? `${window.kind}:${window.id}`
469 : pooled;
470 const list = byKey.get(key);
422 - if (list) list.push({ account, window });
423 - else byKey.set(key, [{ account, window }]);
471 + if (list) list.push(member);
472 + else byKey.set(key, [member]);
473 }
474 }
475 const pools = [...byKey].map(([key, members]): LimitPoolWindow => {
@@ -447,7 +496,7 @@ function poolWindows(accounts: readonly LimitAccount[], now: number): readonly L
496 {
497 member,
498 at,
450 - restoresPercent: Math.round(member.window.usedPercent / members.length),
499 + restoresPercent: Math.round(member.refillPercent / members.length),
500 },
501 ];
502 })