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 23, 04:15 UTC
fix(usage): show Antigravity Gemini limits when one quota endpoint omits them (#20081)
pauliusiv123-rgb committed
Oct 18, 2026 at 22:14 UTC
340ee237bf6f691634b91e21c1211570377ba678
2 files changed
+82
-17
apps/server/src/provider/antigravityUsageLimits.test.ts
+56
-3
@@ -50,8 +50,12 @@ const summary = {
50
const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
51
options: {
52
summary?: unknown;
53
+ /** Per-host quota summaries; hosts not listed fall back to `summary`. */
54
+ summaryByHost?: Record<string, unknown>;
55
models?: unknown;
56
summaryStatus?: number;
57
+ /** Per-host summary statuses; hosts not listed fall back to `summaryStatus`. */
58
+ summaryStatusByHost?: Record<string, number>;
59
tokenStatus?: number;
60
refreshToken?: string;
61
userId?: string;
@@ -76,7 +80,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
80
);
81
if (!options.missingToken) yield* writeToken(options.refreshToken ?? "refresh-a");
82
const requests: Array<{ url: string; body: string }> = [];
79
- const http = HttpClient.make((request, _url, _signal, fiber) =>
83
+ const http = HttpClient.make((request, url, _signal, fiber) =>
84
Effect.sync(() => {
85
const init = Context.getOrUndefined(fiber.context, FetchHttpClient.RequestInit);
86
expect(init?.redirect).toBe("manual");
@@ -106,7 +110,9 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
110
return HttpClientResponse.fromWeb(
111
request,
112
request.url.endsWith(":retrieveUserQuotaSummary")
109
- ? Response.json(options.summary ?? summary, { status: options.summaryStatus ?? 200 })
113
+ ? Response.json(options.summaryByHost?.[url.host] ?? options.summary ?? summary, {
114
+ status: options.summaryStatusByHost?.[url.host] ?? options.summaryStatus ?? 200,
115
+ })
116
: Response.json(options.models ?? { models: {} }),
117
);
118
}),
@@ -140,9 +146,56 @@ describe("Antigravity subscription limits", () => {
146
expect(byId.get("3p-5h")?.usedPercent).toBeCloseTo(56);
147
yield* probe;
148
expect(requests.filter((request) => request.url.endsWith("/token"))).toHaveLength(1);
149
+ // Both quota endpoints are read on every probe.
150
expect(
151
requests.filter((request) => request.url.endsWith(":retrieveUserQuotaSummary")),
145
- ).toHaveLength(2);
152
+ ).toHaveLength(4);
153
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
154
+ );
155
+
156
+ it.effect("merges quota groups that only one endpoint reports", () =>
157
+ Effect.gen(function* () {
158
+ const { probe } = yield* fixture({
159
+ summaryByHost: {
160
+ // The daily endpoint has answered with only the Claude/GPT group; the
161
+ // other endpoint returns the full default summary.
162
+ "daily-cloudcode-pa.googleapis.com": {
163
+ groups: [
164
+ {
165
+ displayName: "Claude and GPT models",
166
+ buckets: [
167
+ { bucketId: "3p-weekly", window: "weekly", remainingFraction: 0.5 },
168
+ { bucketId: "3p-5h", window: "5h", remainingFraction: 0.3 },
169
+ ],
170
+ },
171
+ ],
172
+ },
173
+ },
174
+ });
175
+ const limits = yield* probe;
176
+ expect(limits.windows.map((window) => window.id).toSorted()).toEqual([
177
+ "3p-5h",
178
+ "3p-weekly",
179
+ "gemini-5h",
180
+ "gemini-weekly",
181
+ ]);
182
+ const byId = new Map(limits.windows.map((window) => [window.id, window]));
183
+ expect(byId.get("gemini-weekly")?.label).toBe("Gemini · Weekly");
184
+ // When endpoints disagree about a bucket, the most-used reading wins,
185
+ // whichever endpoint reported it.
186
+ expect(byId.get("3p-5h")?.usedPercent).toBeCloseTo(70);
187
+ expect(byId.get("3p-weekly")?.usedPercent).toBe(100);
188
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
189
+ );
190
+
191
+ it.effect("keeps one endpoint's quotas when the other fails", () =>
192
+ Effect.gen(function* () {
193
+ const { probe } = yield* fixture({
194
+ summaryStatusByHost: { "daily-cloudcode-pa.googleapis.com": 503 },
195
+ });
196
+ const limits = yield* probe;
197
+ expect(limits.unavailable).toBeUndefined();
198
+ expect(limits.windows).toHaveLength(4);
199
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
200
);
201
apps/server/src/provider/antigravityUsageLimits.ts
+26
-14
@@ -246,26 +246,38 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
246
accessToken = cached.accessToken;
247
account = cached.account;
248
}
249
+ // Endpoints can report different quota groups (the daily endpoint has
250
+ // returned the Claude/GPT group without Gemini), so merge every endpoint's
251
+ // windows. The most-used reading of a bucket wins, as in modelWindows.
252
const fetchWindows = Effect.fn("AntigravityUsageProbe.fetchWindows")(function* <E>(
253
operation: string,
254
parse: (response: unknown) => Effect.Effect<ServerProviderUsageWindow[], E>,
255
) {
253
- for (const endpoint of ENDPOINTS) {
254
- const windows = yield* request(
255
- HttpClientRequest.post(`${endpoint}/v1internal:${operation}`).pipe(
256
- HttpClientRequest.setHeaders({
257
- Authorization: `Bearer ${accessToken}`,
258
- "User-Agent": `antigravity/hub/1.0.0 (aidev_client; os_type=${platform}; arch=${architecture}; cl=963137146)`,
259
- }),
260
- HttpClientRequest.bodyJsonUnsafe(token.project_id ? { project: token.project_id } : {}),
256
+ const responses = yield* Effect.forEach(
257
+ ENDPOINTS,
258
+ (endpoint) =>
259
+ request(
260
+ HttpClientRequest.post(`${endpoint}/v1internal:${operation}`).pipe(
261
+ HttpClientRequest.setHeaders({
262
+ Authorization: `Bearer ${accessToken}`,
263
+ "User-Agent": `antigravity/hub/1.0.0 (aidev_client; os_type=${platform}; arch=${architecture}; cl=963137146)`,
264
+ }),
265
+ HttpClientRequest.bodyJsonUnsafe(
266
+ token.project_id ? { project: token.project_id } : {},
267
+ ),
268
+ ),
269
+ ).pipe(
270
+ Effect.flatMap(parse),
271
+ Effect.orElseSucceed(() => []),
272
),
262
- ).pipe(
263
- Effect.flatMap(parse),
264
- Effect.orElseSucceed(() => []),
265
- );
266
- if (windows.length > 0) return windows;
273
+ { concurrency: "unbounded" },
274
+ );
275
+ const windows = new Map<string, ServerProviderUsageWindow>();
276
+ for (const window of responses.flat()) {
277
+ const previous = windows.get(window.id);
278
+ if (!previous || window.usedPercent > previous.usedPercent) windows.set(window.id, window);
279
}
268
- return [];
280
+ return [...windows.values()];
281
});
282
const summary = yield* fetchWindows("retrieveUserQuotaSummary", (response) =>
283
decodeSummary(response).pipe(Effect.map(summaryWindows)),