The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): subscription widget no longer expires on a window that already reset (#22993)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 01:32 UTC
0d36f2b48e88676d27ebef8c380ec64f3e8e1c37
2 files changed
+70
-2
apps/mobile/src/widgets/subscriptionUsageSnapshot.test.ts
+59
@@ -135,6 +135,65 @@ describe("subscription widget snapshots", () => {
135
});
136
});
137
138
+describe("subscription widget expiry", () => {
139
+ const maxAgeDeadline = now + 15 * 60_000;
140
+ function single(resetsAt: string) {
141
+ return buildSubscriptionUsageSnapshot(
142
+ presentations([provider({ usageLimits: { checkedAt, windows: [{ ...window, resetsAt }] } })]),
143
+ deepLink,
144
+ ).providers[0];
145
+ }
146
+
147
+ it.each(["2026-09-05T11:50:00.000Z", checkedAt])(
148
+ "keeps usage whose reset at %s already happened when observed",
149
+ (resetsAt) => {
150
+ expect(single(resetsAt)).toMatchObject({
151
+ detail: "Subscription remaining",
152
+ expiresAt: maxAgeDeadline,
153
+ windows: [{ remaining: 60, reset: expect.stringMatching(/^Reset /) }],
154
+ });
155
+ },
156
+ );
157
+
158
+ it.each([
159
+ { resetAccount: 1, expiresAt: maxAgeDeadline, label: /^Reset / },
160
+ { resetAccount: 0, expiresAt: now + 2 * 60_000, label: /^Next reset / },
161
+ ])(
162
+ "compares a pooled reset with its own account's observation (account $resetAccount)",
163
+ ({ resetAccount, expiresAt, label }) => {
164
+ // Account 0 was observed at 12:00, account 1 at 12:05; the pooled reset is at 12:02.
165
+ const snapshot = buildSubscriptionUsageSnapshot(
166
+ presentations(
167
+ [checkedAt, "2026-09-05T12:05:00.000Z"].map((accountCheckedAt, index) =>
168
+ provider({
169
+ instanceId: ProviderInstanceId.make(`codex-${index}`),
170
+ auth: { status: "authenticated", email: `account-${index}@example.com` },
171
+ usageLimits: {
172
+ checkedAt: accountCheckedAt,
173
+ windows: [
174
+ {
175
+ ...window,
176
+ resetsAt:
177
+ index === resetAccount
178
+ ? "2026-09-05T12:02:00.000Z"
179
+ : "2026-09-05T13:00:00.000Z",
180
+ },
181
+ ],
182
+ },
183
+ }),
184
+ ),
185
+ ),
186
+ deepLink,
187
+ );
188
+ expect(snapshot.providers[0]).toMatchObject({
189
+ detail: "2 accounts · pooled",
190
+ expiresAt,
191
+ windows: [{ remaining: 60, reset: expect.stringMatching(label) }],
192
+ });
193
+ },
194
+ );
195
+});
196
+
197
describe("widget refresh probes", () => {
198
it("does not overlap a slow probe even after the refresh interval", async () => {
199
let finish!: () => void;
apps/mobile/src/widgets/subscriptionUsageSnapshot.ts
+11
-2
@@ -2,6 +2,7 @@ import {
2
collectLimitAccounts,
3
collectLimitPools,
4
type LimitAccount,
5
+ type LimitPoolWindow,
6
type LimitPresentations,
7
} from "@t3tools/shared/usageLimits";
8
@@ -44,6 +45,10 @@ export function createWidgetRefresher<Id>(refresh: (id: Id) => Promise<unknown>)
45
};
46
}
47
48
+// A reset at or before its account's observation already happened, so it cannot expire the snapshot.
49
+const isUpcoming = (reset: LimitPoolWindow["resets"][number]) =>
50
+ reset.at > Date.parse(reset.member.account.limits.checkedAt);
51
+
52
function subscriptionUsageProps(
53
accounts: readonly LimitAccount[],
54
now: number,
@@ -75,7 +80,9 @@ function subscriptionUsageProps(
80
const checkedAt = Math.min(...pool.accounts.map((a) => Date.parse(a.limits.checkedAt)));
81
const expiresAt = Math.min(
82
checkedAt + SNAPSHOT_MAX_AGE,
78
- ...pool.windows.flatMap((window) => window.resets.map((reset) => reset.at)),
83
+ ...pool.windows.flatMap((window) =>
84
+ window.resets.filter(isUpcoming).map((reset) => reset.at),
85
+ ),
86
);
87
const fresh = Number.isFinite(expiresAt) && expiresAt > now;
88
const sortedWindows = [...pool.windows].sort(
@@ -106,7 +113,9 @@ function subscriptionUsageProps(
113
label: window.label,
114
remaining: Math.round(window.remainingPercent),
115
reset: window.resets[0]
109
- ? `Next reset ${new Date(window.resets[0].at).toLocaleString(undefined, {
116
+ ? `${isUpcoming(window.resets[0]) ? "Next reset" : "Reset"} ${new Date(
117
+ window.resets[0].at,
118
+ ).toLocaleString(undefined, {
119
month: "short",
120
day: "numeric",
121
hour: "numeric",