@devries-cameron20 / t3code Mirror · read-only / commits / 047d492736
Fork 0

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, 00:45 UTC

fix(server): Antigravity limits read the quota host the account is metered on (#32425)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 10, 2026 at 08:16 UTC 047d492736ef7ad6c46250b52afafbd0b731f32f
2 files changed +54 -14
apps/server/src/provider/antigravityUsageLimits.test.ts
+42 -6
@@ -65,7 +65,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
65 userId?: string;
66 userInfoAt?: number;
67 missingToken?: boolean;
68 - authMethod?: "oauth-personal" | "gemini-api-key";
68 + authMethod?: "oauth-personal" | "oauth-business" | "gemini-api-key";
69 } = {},
70 ) {
71 const fs = yield* FileSystem.FileSystem;
@@ -330,11 +330,12 @@ describe("Antigravity subscription limits", () => {
330 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
331 );
332
333 - // Oracle: the existing endpoint merge keeps the most-used reading.
334 - it.effect("keeps the used endpoint reading and its reset over an untouched reading", () =>
333 + // Oracle: workspace sign-ins are metered on cloudcode-pa, so its reading wins even when less used.
334 + it.effect("reports a business account's quota from the endpoint it is metered on", () =>
335 Effect.gen(function* () {
336 yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
337 const { probe } = yield* fixture({
338 + authMethod: "oauth-business",
339 summaryByHost: {
340 "daily-cloudcode-pa.googleapis.com": {
341 buckets: [
@@ -383,9 +384,8 @@ describe("Antigravity subscription limits", () => {
384 id: "3p-weekly",
385 label: "Claude & GPT (shared) · Weekly",
386 kind: "weekly",
386 - usedPercent: 50,
387 + usedPercent: 0,
388 windowDurationMins: 10080,
388 - resetsAt: "2026-10-27T10:16:04.000Z",
389 },
390 ]);
391 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
@@ -474,7 +474,43 @@ describe("Antigravity subscription limits", () => {
474 const byId = new Map(limits.windows.map((window) => [window.id, window]));
475 expect(byId.get("gemini-weekly")?.label).toBe("Gemini · Weekly");
476 expect(byId.get("3p-5h")?.usedPercent).toBeCloseTo(70);
477 - expect(byId.get("3p-weekly")?.usedPercent).toBe(100);
477 + expect(byId.get("3p-weekly")?.usedPercent).toBe(50);
478 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
479 + );
480 +
481 + // Oracle: reported payloads for a personal sign-in, whose runtime meters on the daily endpoint.
482 + it.effect("reports a personal account's quota from the daily endpoint it is metered on", () =>
483 + Effect.gen(function* () {
484 + yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-11-07T12:00:00Z")));
485 + const argon = (remainingFraction: number, resetTime: string) => ({
486 + groups: [
487 + {
488 + displayName: "Gemini 4 Argon",
489 + buckets: [
490 + {
491 + bucketId: "gemini-argon-wtu-weekly",
492 + window: "weekly",
493 + remainingFraction,
494 + resetTime,
495 + },
496 + ],
497 + },
498 + ],
499 + });
500 + const { probe } = yield* fixture({
501 + authMethod: "oauth-personal",
502 + summaryByHost: {
503 + "daily-cloudcode-pa.googleapis.com": argon(0.8623059, "2026-11-14T08:41:35Z"),
504 + "cloudcode-pa.googleapis.com": argon(0, "2026-11-08T18:27:14Z"),
505 + },
506 + });
507 + expect((yield* probe).windows).toEqual([
508 + expect.objectContaining({
509 + id: "gemini-argon-wtu-weekly",
510 + usedPercent: expect.closeTo(13.77, 2),
511 + resetsAt: "2026-11-14T08:41:35.000Z",
512 + }),
513 + ]);
514 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
515 );
516
apps/server/src/provider/antigravityUsageLimits.ts
+12 -8
@@ -15,10 +15,14 @@ import {
15 makeUsageLimits,
16 } from "@t3tools/provider-core/server/usageLimits";
17
18 -const ENDPOINTS = [
19 - "https://daily-cloudcode-pa.googleapis.com",
20 - "https://cloudcode-pa.googleapis.com",
21 -];
18 +const DAILY_ENDPOINT = "https://daily-cloudcode-pa.googleapis.com";
19 +const PROD_ENDPOINT = "https://cloudcode-pa.googleapis.com";
20 +// The ACP runtime meters consumer tiers on the daily host and GCP-terms tiers on prod.
21 +// The sign-in method stands in for the tier.
22 +const ENDPOINTS = {
23 + "oauth-personal": [DAILY_ENDPOINT, PROD_ENDPOINT],
24 + "oauth-business": [PROD_ENDPOINT, DAILY_ENDPOINT],
25 +};
26 const SUMMARY_WINDOW_MINS = new Map([
27 ["5h", 5 * 60],
28 ["weekly", 7 * 24 * 60],
@@ -269,7 +273,8 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
273 accessToken = cached.accessToken;
274 account = cached.account;
275 }
272 - // Merge endpoints because quota groups differ; keep each bucket's most-used reading.
276 + const endpoints = ENDPOINTS[input.authMethod];
277 + // Merge endpoints because quota groups differ; the metered host's reading of a bucket wins.
278 const fetchWindows = Effect.fn("AntigravityUsageProbe.fetchWindows")(function* <E>(
279 operation: string,
280 parse: (
@@ -278,7 +283,7 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
283 ) => Effect.Effect<ServerProviderUsageWindow[], E>,
284 ) {
285 const responses = yield* Effect.forEach(
281 - ENDPOINTS,
286 + endpoints,
287 (endpoint) =>
288 Effect.gen(function* () {
289 // Capture each request after auth, so refresh latency does not widen the tolerance.
@@ -302,8 +307,7 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
307 );
308 const windows = new Map<string, ServerProviderUsageWindow>();
309 for (const window of responses.flat()) {
305 - const previous = windows.get(window.id);
306 - if (!previous || window.usedPercent > previous.usedPercent) windows.set(window.id, window);
310 + if (!windows.has(window.id)) windows.set(window.id, window);
311 }
312 return [...windows.values()];
313 });