Skip to content

Commit 49f54b0

Browse files
committed
fix(usage): show empty sessions when weekly quota is exhausted
1 parent cfafb4b commit 49f54b0

3 files changed

Lines changed: 85 additions & 1 deletion

File tree

‎docs/user/usage.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ the bar show each account's quota, countdown, and credits. Tap a row to open its
9595
The same account signed in on more than one environment, or reported by a hub as well, counts once.
9696
Filter with the environment dropdown to see what a single machine has.
9797

98+
When a Claude or Codex account has no weekly quota left, its session also shows 0% left and the
99+
weekly reset time. Claude's model-specific weekly rows do the same.
100+
98101
Opening Limits checks the selected connected environments automatically. Each client waits at
99102
least five minutes between automatic checks of an environment, including after a failed check.
100103
If a window still looks stale, refresh Limits to re-check every provider and hub.

‎packages/shared/src/usageLimits.test.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,68 @@ describe("pooled account columns", () => {
851851
row.columns.map((member) => (member.window ? member.account.key : null)),
852852
);
853853

854+
it("counts an exhausted weekly as empty in session and model rows with the same reset", () => {
855+
const accounts = (
856+
[
857+
[90, 0, 96],
858+
[100, 1, 70],
859+
[100, 1, 70],
860+
[90, 50, 88],
861+
] as const
862+
).map(([session, week, model], index) =>
863+
account(String(index), [
864+
{ ...window, usedPercent: 100 - session },
865+
{ ...weekly, usedPercent: 100 - week, resetsAt: "2026-09-06T12:00:00.000Z" },
866+
{ ...weekly, id: "seven_day_fable", usedPercent: 100 - model },
867+
]),
868+
);
869+
const rows = collectLimitPools(accounts, now)[0]!.windows;
870+
expect(rows.map((row) => row.remainingPercent)).toEqual([73, 13, 57]);
871+
for (const row of rows) {
872+
expect(row.columns[0]?.window).toMatchObject({
873+
usedPercent: 100,
874+
resetsAt: "2026-09-06T12:00:00.000Z",
875+
windowDurationMins: weekly.windowDurationMins,
876+
});
877+
expect(row.resets.find((reset) => reset.member.account.key === "0")).toMatchObject({
878+
at: Date.parse("2026-09-06T12:00:00.000Z"),
879+
restoresPercent: 25,
880+
});
881+
}
882+
expect(accounts[0]?.limits.windows[0]?.usedPercent).toBe(10);
883+
const refreshed = accounts.map((a) => ({
884+
...a,
885+
limits: { ...a.limits, windows: a.limits.windows.map((w) => ({ ...w, usedPercent: 0 })) },
886+
}));
887+
expect(collectLimitPools(refreshed, now)[0]?.windows[0]?.remainingPercent).toBe(100);
888+
});
889+
890+
it.each([
891+
["codex", "secondary", 100, 0],
892+
["claudeAgent", "seven_day", 99, 60],
893+
["claudeAgent", "seven_day_fable", 100, 60],
894+
["cursor", "seven_day", 100, 60],
895+
])("uses only the exhausted covering weekly for %s (%s, %i used)", (driver, id, used, left) => {
896+
const a = account("a", [window, { ...weekly, id, usedPercent: used }]);
897+
const [session] = collectLimitPools(
898+
[{ ...a, driver: ProviderDriverKind.make(driver) }],
899+
now,
900+
)[0]!.windows;
901+
expect(session?.remainingPercent).toBe(left);
902+
});
903+
904+
it.each([undefined, "invalid"])(
905+
"does not invent a reset when the weekly reports %s",
906+
(resetsAt) => {
907+
const [session] = collectLimitPools(
908+
[account("a", [window, { ...weekly, usedPercent: 100, resetsAt }])],
909+
now,
910+
)[0]!.windows;
911+
expect(session?.remainingPercent).toBe(0);
912+
expect(session?.resets).toEqual([]);
913+
},
914+
);
915+
854916
it("keeps session columns across rows with opposite reset and usage orders", () => {
855917
const accounts = [
856918
account("a", [

‎packages/shared/src/usageLimits.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,26 @@ function poolKey(driver: ServerProvider["driver"], window: ServerProviderUsageWi
413413
function poolWindows(accounts: readonly LimitAccount[], now: number): readonly LimitPoolWindow[] {
414414
const byKey = new Map<string, LimitPoolMember[]>();
415415
for (const account of accounts) {
416-
for (const window of account.limits.windows) {
416+
const spentWeekly = account.limits.windows.find(
417+
(window) =>
418+
window.usedPercent >= 100 &&
419+
(account.driver === "claudeAgent"
420+
? window.id === "seven_day"
421+
: account.driver === "codex" && window.kind === "weekly"),
422+
);
423+
for (const reported of account.limits.windows) {
424+
// These allowances cannot be used until the account's weekly limit resets.
425+
const window =
426+
spentWeekly &&
427+
(reported.kind === "session" ||
428+
(account.driver === "claudeAgent" && reported.id.startsWith("seven_day_")))
429+
? {
430+
...reported,
431+
usedPercent: 100,
432+
resetsAt: spentWeekly.resetsAt,
433+
windowDurationMins: spentWeekly.windowDurationMins,
434+
}
435+
: reported;
417436
const pooled = poolKey(account.driver, window);
418437
const key = byKey.get(pooled)?.some((member) => member.account === account)
419438
? `${window.kind}:${window.id}`

0 commit comments

Comments
 (0)