Skip to content

Commit 6054f4a

Browse files
fix(server): read Antigravity quota from the endpoint the account is metered on
Usage limits queried both quota hosts and kept each bucket's most-used reading, so cloudcode-pa's stale exhausted Argon weekly bucket overrode the daily endpoint's real reading for personal sign-ins. Order the hosts by auth method (personal: daily-cloudcode-pa first; business: cloudcode-pa first). The primary host's reading of a bucket wins; the other host only fills buckets the primary did not report, or all of them when the primary fails. Both requests stay concurrent, and the fetchAvailableModels fallback uses the same merge. Fixes pingdotgg#32419 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 906aa5d commit 6054f4a

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

‎apps/server/src/provider/antigravityUsageLimits.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
6565
userId?: string;
6666
userInfoAt?: number;
6767
missingToken?: boolean;
68-
authMethod?: "oauth-personal" | "gemini-api-key";
68+
authMethod?: "oauth-personal" | "oauth-business" | "gemini-api-key";
6969
} = {},
7070
) {
7171
const fs = yield* FileSystem.FileSystem;
@@ -330,11 +330,12 @@ describe("Antigravity subscription limits", () => {
330330
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
331331
);
332332

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", () =>
335335
Effect.gen(function* () {
336336
yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-21T10:16:04Z")));
337337
const { probe } = yield* fixture({
338+
authMethod: "oauth-business",
338339
summaryByHost: {
339340
"daily-cloudcode-pa.googleapis.com": {
340341
buckets: [
@@ -383,9 +384,8 @@ describe("Antigravity subscription limits", () => {
383384
id: "3p-weekly",
384385
label: "Claude & GPT (shared) · Weekly",
385386
kind: "weekly",
386-
usedPercent: 50,
387+
usedPercent: 0,
387388
windowDurationMins: 10080,
388-
resetsAt: "2026-10-27T10:16:04.000Z",
389389
},
390390
]);
391391
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
@@ -474,7 +474,7 @@ describe("Antigravity subscription limits", () => {
474474
const byId = new Map(limits.windows.map((window) => [window.id, window]));
475475
expect(byId.get("gemini-weekly")?.label).toBe("Gemini · Weekly");
476476
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);
478478
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
479479
);
480480

‎apps/server/src/provider/antigravityUsageLimits.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ import {
1515
makeUsageLimits,
1616
} from "@t3tools/provider-core/server/usageLimits";
1717

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 sign-ins on the daily host and workspace sign-ins on prod.
21+
const ENDPOINTS = {
22+
"oauth-personal": [DAILY_ENDPOINT, PROD_ENDPOINT],
23+
"oauth-business": [PROD_ENDPOINT, DAILY_ENDPOINT],
24+
};
2225
const SUMMARY_WINDOW_MINS = new Map([
2326
["5h", 5 * 60],
2427
["weekly", 7 * 24 * 60],
@@ -269,7 +272,8 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
269272
accessToken = cached.accessToken;
270273
account = cached.account;
271274
}
272-
// Merge endpoints because quota groups differ; keep each bucket's most-used reading.
275+
const endpoints = ENDPOINTS[input.authMethod];
276+
// Merge endpoints because quota groups differ; the metered host's reading of a bucket wins.
273277
const fetchWindows = Effect.fn("AntigravityUsageProbe.fetchWindows")(function* <E>(
274278
operation: string,
275279
parse: (
@@ -278,7 +282,7 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
278282
) => Effect.Effect<ServerProviderUsageWindow[], E>,
279283
) {
280284
const responses = yield* Effect.forEach(
281-
ENDPOINTS,
285+
endpoints,
282286
(endpoint) =>
283287
Effect.gen(function* () {
284288
// Capture each request after auth, so refresh latency does not widen the tolerance.
@@ -302,8 +306,7 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")(
302306
);
303307
const windows = new Map<string, ServerProviderUsageWindow>();
304308
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);
309+
if (!windows.has(window.id)) windows.set(window.id, window);
307310
}
308311
return [...windows.values()];
309312
});

0 commit comments

Comments
 (0)