The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 10:45 UTC
fix(server): hide rolling resets for untouched Antigravity quotas (#23558)
Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
Fuksss committed
Oct 31, 2026 at 03:12 UTC
1da04920a554f643414be68a6866dd54c1c33ece
2 files changed
+339
-20
apps/server/src/provider/antigravityUsageLimits.test.ts
+292
-1
@@ -1,9 +1,11 @@
1
import * as NodeServices from "@effect/platform-node/NodeServices";
2
import { describe, expect, it } from "@effect/vitest";
3
import * as Context from "effect/Context";
4
+import * as DateTime from "effect/DateTime";
5
import * as Effect from "effect/Effect";
6
import * as FileSystem from "effect/FileSystem";
7
import * as Path from "effect/Path";
8
+import * as TestClock from "effect/testing/TestClock";
9
import { FetchHttpClient, HttpClient, HttpClientResponse } from "effect/http";
10
11
import { makeAntigravityUsageProbe } from "./antigravityUsageLimits.ts";
@@ -59,6 +61,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
61
tokenStatus?: number;
62
refreshToken?: string;
63
userId?: string;
64
+ userInfoAt?: number;
65
missingToken?: boolean;
66
authMethod?: "oauth-personal" | "gemini-api-key";
67
} = {},
@@ -115,7 +118,13 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
118
})
119
: Response.json(options.models ?? { models: {} }),
120
);
118
- }),
121
+ }).pipe(
122
+ Effect.tap(() =>
123
+ request.url.endsWith("/userinfo") && options.userInfoAt !== undefined
124
+ ? TestClock.setTime(options.userInfoAt)
125
+ : Effect.void,
126
+ ),
127
+ ),
128
);
129
const usage = yield* makeAntigravityUsageProbe({
130
profileDirectory,
@@ -125,6 +134,288 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
134
});
135
136
describe("Antigravity subscription limits", () => {
137
+ // Oracle: the 10:16 UTC payload and its narrow Workaround rule.
138
+ it.effect("omits rolling resets for untouched summary buckets and keeps used Gemini resets", () =>
139
+ Effect.gen(function* () {
140
+ yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
141
+ const { probe } = yield* fixture({
142
+ summary: {
143
+ groups: [
144
+ {
145
+ buckets: [
146
+ {
147
+ bucketId: "3p-5h",
148
+ window: "5h",
149
+ remainingFraction: 1,
150
+ resetTime: "2026-10-21T15:16:05Z",
151
+ },
152
+ {
153
+ bucketId: "3p-weekly",
154
+ window: "weekly",
155
+ remainingFraction: 1,
156
+ resetTime: "2026-10-28T10:16:05Z",
157
+ },
158
+ {
159
+ bucketId: "gemini-5h",
160
+ window: "5h",
161
+ remainingFraction: 0.848104,
162
+ resetTime: "2026-10-21T13:29:53Z",
163
+ description:
164
+ "You have used some of your 5-hour limit, it will fully refresh in 3 hours, 13 minutes.",
165
+ },
166
+ {
167
+ bucketId: "gemini-weekly",
168
+ window: "weekly",
169
+ remainingFraction: 0.9620177,
170
+ resetTime: "2026-10-28T08:29:53Z",
171
+ description:
172
+ "You have used some of your weekly limit, it will fully refresh in 6 days, 22 hours.",
173
+ },
174
+ ],
175
+ },
176
+ ],
177
+ },
178
+ });
179
+ const limits = yield* probe;
180
+ const byId = new Map(limits.windows.map((window) => [window.id, window]));
181
+ expect(byId.get("3p-5h")).toEqual({
182
+ id: "3p-5h",
183
+ label: "Claude & GPT (shared) · 5-hour",
184
+ kind: "session",
185
+ usedPercent: 0,
186
+ windowDurationMins: 300,
187
+ });
188
+ expect(byId.get("3p-weekly")).toEqual({
189
+ id: "3p-weekly",
190
+ label: "Claude & GPT (shared) · Weekly",
191
+ kind: "weekly",
192
+ usedPercent: 0,
193
+ windowDurationMins: 10080,
194
+ });
195
+ expect(byId.get("gemini-5h")?.resetsAt).toBe("2026-10-21T13:29:53.000Z");
196
+ expect(byId.get("gemini-weekly")?.resetsAt).toBe("2026-10-28T08:29:53.000Z");
197
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
198
+ );
199
+
200
+ // Oracle: measure the tolerance from the summary request, after auth.
201
+ it.effect("uses summary request time after authentication for the reset tolerance", () =>
202
+ Effect.gen(function* () {
203
+ yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:02Z")));
204
+ const { probe } = yield* fixture({
205
+ userInfoAt: DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")),
206
+ summary: {
207
+ buckets: [
208
+ {
209
+ bucketId: "3p-5h",
210
+ window: "5h",
211
+ remainingFraction: 1,
212
+ resetTime: "2026-10-21T15:17:03Z",
213
+ },
214
+ ],
215
+ },
216
+ });
217
+ expect((yield* probe).windows[0]?.resetsAt).toBeUndefined();
218
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
219
+ );
220
+
221
+ // Oracle: keep descriptions, measured resets, and spent buckets.
222
+ it.effect("keeps summary resets with a description, a distant reset, or no quota left", () =>
223
+ Effect.gen(function* () {
224
+ yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
225
+ const { probe } = yield* fixture({
226
+ summary: {
227
+ buckets: [
228
+ {
229
+ bucketId: "described",
230
+ window: "5h",
231
+ remainingFraction: 1,
232
+ description: "Reported reset",
233
+ resetTime: "2026-10-21T15:16:04Z",
234
+ },
235
+ {
236
+ bucketId: "distant",
237
+ window: "weekly",
238
+ remainingFraction: 1,
239
+ resetTime: "2026-10-28T12:16:04Z",
240
+ },
241
+ {
242
+ bucketId: "spent",
243
+ window: "5h",
244
+ remainingFraction: 0,
245
+ resetTime: "2026-10-21T15:16:04Z",
246
+ },
247
+ {
248
+ bucketId: "overfull",
249
+ window: "5h",
250
+ remainingFraction: 1.01,
251
+ resetTime: "2026-10-21T15:16:04Z",
252
+ },
253
+ {
254
+ bucketId: "empty-description",
255
+ window: "5h",
256
+ remainingFraction: 1,
257
+ description: "",
258
+ resetTime: "2026-10-21T15:16:04Z",
259
+ },
260
+ ],
261
+ },
262
+ });
263
+ expect((yield* probe).windows.map(({ id, resetsAt }) => ({ id, resetsAt }))).toEqual([
264
+ { id: "described", resetsAt: "2026-10-21T15:16:04.000Z" },
265
+ { id: "empty-description", resetsAt: "2026-10-21T15:16:04.000Z" },
266
+ { id: "overfull", resetsAt: "2026-10-21T15:16:04.000Z" },
267
+ { id: "spent", resetsAt: "2026-10-21T15:16:04.000Z" },
268
+ { id: "distant", resetsAt: "2026-10-28T12:16:04.000Z" },
269
+ ]);
270
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
271
+ );
272
+
273
+ // Oracle: the 60-second tolerance applies to both known window lengths.
274
+ it.effect("omits summary resets 59 seconds away but keeps resets 61 seconds away", () =>
275
+ Effect.gen(function* () {
276
+ yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
277
+ const { probe } = yield* fixture({
278
+ summary: {
279
+ buckets: [
280
+ {
281
+ bucketId: "5h-before",
282
+ window: "5h",
283
+ remainingFraction: 1,
284
+ resetTime: "2026-10-21T15:15:05Z",
285
+ },
286
+ {
287
+ bucketId: "5h-after",
288
+ window: "5h",
289
+ remainingFraction: 1,
290
+ resetTime: "2026-10-21T15:17:05Z",
291
+ },
292
+ {
293
+ bucketId: "5h-edge",
294
+ window: "5h",
295
+ remainingFraction: 1,
296
+ resetTime: "2026-10-21T15:17:04Z",
297
+ },
298
+ {
299
+ bucketId: "weekly-after",
300
+ window: "weekly",
301
+ remainingFraction: 1,
302
+ resetTime: "2026-10-28T10:17:03Z",
303
+ },
304
+ {
305
+ bucketId: "weekly-before",
306
+ window: "weekly",
307
+ remainingFraction: 1,
308
+ resetTime: "2026-10-28T10:15:03Z",
309
+ },
310
+ {
311
+ bucketId: "weekly-edge",
312
+ window: "weekly",
313
+ remainingFraction: 1,
314
+ resetTime: "2026-10-28T10:15:04Z",
315
+ },
316
+ ],
317
+ },
318
+ });
319
+ expect((yield* probe).windows.map(({ id, resetsAt }) => ({ id, resetsAt }))).toEqual([
320
+ { id: "5h-after", resetsAt: "2026-10-21T15:17:05.000Z" },
321
+ { id: "5h-before", resetsAt: undefined },
322
+ { id: "5h-edge", resetsAt: undefined },
323
+ { id: "weekly-after", resetsAt: undefined },
324
+ { id: "weekly-before", resetsAt: "2026-10-28T10:15:03.000Z" },
325
+ { id: "weekly-edge", resetsAt: undefined },
326
+ ]);
327
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
328
+ );
329
+
330
+ // Oracle: the existing endpoint merge keeps the most-used reading.
331
+ it.effect("keeps the used endpoint reading and its reset over an untouched reading", () =>
332
+ Effect.gen(function* () {
333
+ yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
334
+ const { probe } = yield* fixture({
335
+ summaryByHost: {
336
+ "daily-cloudcode-pa.googleapis.com": {
337
+ buckets: [
338
+ {
339
+ bucketId: "3p-5h",
340
+ window: "5h",
341
+ remainingFraction: 1,
342
+ resetTime: "2026-10-21T15:16:04Z",
343
+ },
344
+ {
345
+ bucketId: "3p-weekly",
346
+ window: "weekly",
347
+ remainingFraction: 0.5,
348
+ resetTime: "2026-10-27T10:16:04Z",
349
+ },
350
+ ],
351
+ },
352
+ "cloudcode-pa.googleapis.com": {
353
+ buckets: [
354
+ {
355
+ bucketId: "3p-5h",
356
+ window: "5h",
357
+ remainingFraction: 0.5,
358
+ resetTime: "2026-10-21T13:16:04Z",
359
+ },
360
+ {
361
+ bucketId: "3p-weekly",
362
+ window: "weekly",
363
+ remainingFraction: 1,
364
+ resetTime: "2026-10-28T10:16:04Z",
365
+ },
366
+ ],
367
+ },
368
+ },
369
+ });
370
+ expect((yield* probe).windows).toEqual([
371
+ {
372
+ id: "3p-5h",
373
+ label: "Claude & GPT (shared) · 5-hour",
374
+ kind: "session",
375
+ usedPercent: 50,
376
+ windowDurationMins: 300,
377
+ resetsAt: "2026-10-21T13:16:04.000Z",
378
+ },
379
+ {
380
+ id: "3p-weekly",
381
+ label: "Claude & GPT (shared) · Weekly",
382
+ kind: "weekly",
383
+ usedPercent: 50,
384
+ windowDurationMins: 10080,
385
+ resetsAt: "2026-10-27T10:16:04.000Z",
386
+ },
387
+ ]);
388
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
389
+ );
390
+
391
+ // Oracle: model quotas have no evidence for the summary-only rule.
392
+ it.effect("keeps full model fallback resets even at a full window from the request", () =>
393
+ Effect.gen(function* () {
394
+ yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
395
+ const { probe } = yield* fixture({
396
+ summaryStatus: 404,
397
+ models: {
398
+ models: {
399
+ "gemini-a": {
400
+ quotaInfo: { remainingFraction: 1, resetTime: "2026-10-21T15:16:04Z" },
401
+ weeklyQuotaInfo: { remainingFraction: 1, resetTime: "2026-10-28T10:16:04Z" },
402
+ },
403
+ },
404
+ },
405
+ });
406
+ expect(
407
+ (yield* probe).windows.map(({ id, resetsAt, windowDurationMins }) => ({
408
+ id,
409
+ resetsAt,
410
+ windowDurationMins,
411
+ })),
412
+ ).toEqual([
413
+ { id: "gemini-weekly", resetsAt: "2026-10-28T10:16:04.000Z", windowDurationMins: 10080 },
414
+ { id: "gemini-quota", resetsAt: "2026-10-21T15:16:04.000Z", windowDurationMins: undefined },
415
+ ]);
416
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
417
+ );
418
+
419
it.effect("reports separate Gemini and shared Claude/GPT five-hour and weekly limits", () =>
420
Effect.gen(function* () {
421
const { probe, requests } = yield* fixture();
apps/server/src/provider/antigravityUsageLimits.ts
+47
-19
@@ -19,6 +19,10 @@ const ENDPOINTS = [
19
"https://daily-cloudcode-pa.googleapis.com",
20
"https://cloudcode-pa.googleapis.com",
21
];
22
+const SUMMARY_WINDOW_MINS = new Map([
23
+ ["5h", 5 * 60],
24
+ ["weekly", 7 * 24 * 60],
25
+]);
26
const MANUAL_REDIRECT: RequestInit = { redirect: "manual" };
27
const TokenFile = Schema.Struct({
28
client_id: Schema.NonEmptyString,
@@ -40,6 +44,7 @@ const Bucket = Schema.Struct({
44
bucketId: Schema.NonEmptyString,
45
window: Schema.optional(Schema.String),
46
displayName: Schema.optional(Schema.String),
47
+ description: Schema.optional(Schema.String),
48
disabled: Schema.optional(Schema.Boolean),
49
});
50
const Summary = Schema.Struct({
@@ -96,7 +101,22 @@ function quotaWindow(
101
};
102
}
103
99
-function summaryWindows(summary: typeof Summary.Type) {
104
+function summaryResetTime(
105
+ bucket: typeof Bucket.Type,
106
+ windowDurationMins: number | undefined,
107
+ requestedAt: number,
108
+): string | undefined {
109
+ // Untouched summary buckets report a rolling full-window reset.
110
+ const untouched =
111
+ bucket.remainingFraction === 1 &&
112
+ bucket.description === undefined &&
113
+ windowDurationMins !== undefined &&
114
+ Math.abs(Date.parse(bucket.resetTime ?? "") - requestedAt - windowDurationMins * 60_000) <=
115
+ 60_000;
116
+ return untouched ? undefined : bucket.resetTime;
117
+}
118
+
119
+function summaryWindows(summary: typeof Summary.Type, requestedAt: number) {
120
const windows = new Map<string, ServerProviderUsageWindow>();
121
const groups = summary.groups?.some((group) => group.buckets?.length)
122
? summary.groups
@@ -111,12 +131,13 @@ function summaryWindows(summary: typeof Summary.Type) {
131
: group.displayName?.trim() || bucket.bucketId;
132
const weekly = bucket.window === "weekly";
133
const session = bucket.window === "5h";
134
+ const windowDurationMins = SUMMARY_WINDOW_MINS.get(bucket.window ?? "");
135
const window = quotaWindow(
136
bucket.bucketId,
137
`${family} · ${weekly ? "Weekly" : session ? "5-hour" : bucket.displayName?.trim() || "Quota"}`,
117
- bucket,
138
+ { ...bucket, resetTime: summaryResetTime(bucket, windowDurationMins, requestedAt) },
139
weekly ? "weekly" : session ? "session" : "other",
119
- weekly ? 7 * 24 * 60 : session ? 5 * 60 : undefined,
140
+ windowDurationMins,
141
);
142
if (window) windows.set(window.id, window);
143
}
@@ -248,25 +269,32 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
269
// Merge endpoints because quota groups differ; keep each bucket's most-used reading.
270
const fetchWindows = Effect.fn("AntigravityUsageProbe.fetchWindows")(function* <E>(
271
operation: string,
251
- parse: (response: unknown) => Effect.Effect<ServerProviderUsageWindow[], E>,
272
+ parse: (
273
+ response: unknown,
274
+ requestedAt: number,
275
+ ) => Effect.Effect<ServerProviderUsageWindow[], E>,
276
) {
277
const responses = yield* Effect.forEach(
278
ENDPOINTS,
279
(endpoint) =>
256
- request(
257
- HttpClientRequest.post(`${endpoint}/v1internal:${operation}`).pipe(
258
- HttpClientRequest.setHeaders({
259
- Authorization: `Bearer ${accessToken}`,
260
- "User-Agent": `antigravity/hub/1.0.0 (aidev_client; os_type=${platform}; arch=${architecture}; cl=963137146)`,
261
- }),
262
- HttpClientRequest.bodyJsonUnsafe(
263
- token.project_id ? { project: token.project_id } : {},
280
+ Effect.gen(function* () {
281
+ // Capture each request after auth, so refresh latency does not widen the tolerance.
282
+ const requestedAt = yield* Clock.currentTimeMillis;
283
+ return yield* request(
284
+ HttpClientRequest.post(`${endpoint}/v1internal:${operation}`).pipe(
285
+ HttpClientRequest.setHeaders({
286
+ Authorization: `Bearer ${accessToken}`,
287
+ "User-Agent": `antigravity/hub/1.0.0 (aidev_client; os_type=${platform}; arch=${architecture}; cl=963137146)`,
288
+ }),
289
+ HttpClientRequest.bodyJsonUnsafe(
290
+ token.project_id ? { project: token.project_id } : {},
291
+ ),
292
),
265
- ),
266
- ).pipe(
267
- Effect.flatMap(parse),
268
- Effect.orElseSucceed(() => []),
269
- ),
293
+ ).pipe(
294
+ Effect.flatMap((response) => parse(response, requestedAt)),
295
+ Effect.orElseSucceed(() => []),
296
+ );
297
+ }),
298
{ concurrency: "unbounded" },
299
);
300
const windows = new Map<string, ServerProviderUsageWindow>();
@@ -276,8 +304,8 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
304
}
305
return [...windows.values()];
306
});
279
- const summary = yield* fetchWindows("retrieveUserQuotaSummary", (response) =>
280
- decodeSummary(response).pipe(Effect.map(summaryWindows)),
307
+ const summary = yield* fetchWindows("retrieveUserQuotaSummary", (response, requestedAt) =>
308
+ decodeSummary(response).pipe(Effect.map((summary) => summaryWindows(summary, requestedAt))),
309
);
310
const windows = summary.length
311
? summary