From 9e549fca294fb5f14d82fd88b627b207f6a393df Mon Sep 17 00:00:00 2001 From: collissimo <148455189+collissimo@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:23:03 +0100 Subject: [PATCH] fix(antigravity): read limits from agy 1.5 token file agy 1.5 stores its Google sign-in as `antigravity-oauth-token` without client credentials instead of `acp_token.json`. The usage probe only knew the old file and showed "Sign in with Google to see Antigravity limits" for a signed-in account. It now reads the new file first and refreshes it with agy's installed-app OAuth client; the legacy file still works. Verified: vp test antigravityUsageLimits (new test fails before, passes after); live probe with the real agy 1.5.12 token returned 5 quota windows; lint/format/typecheck clean Co-Authored-By: Claude Opus 5.5 --- .../provider/antigravityUsageLimits.test.ts | 30 +++++++++++++++-- .../src/provider/antigravityUsageLimits.ts | 33 +++++++++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/apps/server/src/provider/antigravityUsageLimits.test.ts b/apps/server/src/provider/antigravityUsageLimits.test.ts index 9defd9df90dce..c14f656466e87 100644 --- a/apps/server/src/provider/antigravityUsageLimits.test.ts +++ b/apps/server/src/provider/antigravityUsageLimits.test.ts @@ -65,6 +65,8 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( userId?: string; userInfoAt?: number; missingToken?: boolean; + /** Writes the token file of agy 1.5+ instead of the legacy `acp_token.json`. */ + agyToken?: boolean; authMethod?: "oauth-personal" | "oauth-business" | "gemini-api-key"; } = {}, ) { @@ -83,7 +85,15 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( project_id: "project-id", }), ); - if (!options.missingToken) yield* writeToken(options.refreshToken ?? "refresh-a"); + if (options.agyToken) { + yield* fs.writeFileString( + path.join(profileDirectory, "antigravity-acp", "antigravity-oauth-token"), + JSON.stringify({ + token: { access_token: "stale", refresh_token: options.refreshToken ?? "refresh-agy" }, + auth_method: "consumer", + }), + ); + } else if (!options.missingToken) yield* writeToken(options.refreshToken ?? "refresh-a"); const requests: Array<{ url: string; body: string }> = []; const http = HttpClient.make((request, url, _signal, fiber) => Effect.sync(() => { @@ -111,7 +121,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( : Response.json({}, { status: 403 }), ); } - expect(JSON.parse(body)).toEqual({ project: "project-id" }); + expect(JSON.parse(body)).toEqual(options.agyToken ? {} : { project: "project-id" }); expect(request.headers["user-agent"]).toMatch(/^antigravity\/hub\/2\.24\.0 /); return HttpClientResponse.fromWeb( request, @@ -137,6 +147,22 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( }); describe("Antigravity subscription limits", () => { + // Regression: agy 1.5 writes `antigravity-oauth-token` without client credentials, and the + // probe reported "Sign in with Google" for a signed-in account. + it.effect("reads limits from the agy 1.5 token file with agy's OAuth client", () => + Effect.gen(function* () { + const { probe, requests } = yield* fixture({ agyToken: true }); + const limits = yield* probe; + expect(limits.unavailable).toBeUndefined(); + expect(limits.windows.map((window) => window.id)).toContain("gemini-5h"); + const refresh = new URLSearchParams( + requests.find((request) => request.url.endsWith("/token"))?.body, + ); + expect(refresh.get("refresh_token")).toBe("refresh-agy"); + expect(refresh.get("client_id")).toMatch(/^1071006060591-/); + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), + ); + // Oracle: the 10:16 UTC payload and its narrow Workaround rule. it.effect("omits rolling resets for untouched summary buckets and keeps used Gemini resets", () => Effect.gen(function* () { diff --git a/apps/server/src/provider/antigravityUsageLimits.ts b/apps/server/src/provider/antigravityUsageLimits.ts index ede0e5c47d20e..1b5fb42730280 100644 --- a/apps/server/src/provider/antigravityUsageLimits.ts +++ b/apps/server/src/provider/antigravityUsageLimits.ts @@ -38,6 +38,15 @@ const TokenFile = Schema.Struct({ refresh_token: Schema.NonEmptyString, project_id: Schema.optional(Schema.String), }); +// agy 1.5+ stores its Google sign-in without client credentials; it refreshes the token with +// its own installed-app OAuth client, which ships in every agy binary and is public by design. +const AGY_OAUTH_CLIENT = { + client_id: "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com", + client_secret: "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", +}; +const AgyTokenFile = Schema.Struct({ + token: Schema.Struct({ refresh_token: Schema.NonEmptyString }), +}); const TokenResponse = Schema.Struct({ access_token: Schema.NonEmptyString, expires_in: Schema.Number.check(Schema.isGreaterThan(0)), @@ -78,6 +87,7 @@ const Models = Schema.Struct({ }); const decodeTokenFile = Schema.decodeEffect(Schema.fromJsonString(TokenFile)); +const decodeAgyTokenFile = Schema.decodeEffect(Schema.fromJsonString(AgyTokenFile)); const decodeTokenResponse = Schema.decodeUnknownEffect(TokenResponse); const decodeUserInfo = Schema.decodeUnknownEffect(UserInfo); const decodeSummary = Schema.decodeUnknownEffect(Summary); @@ -217,7 +227,24 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")( const crypto = yield* Digest.Digest; const platform = yield* HostProcess.Platform; const architecture = yield* HostProcess.Architecture; - const tokenPath = path.join(input.profileDirectory, "antigravity-acp", "acp_token.json"); + const acpDirectory = path.join(input.profileDirectory, "antigravity-acp"); + const agyTokenPath = path.join(acpDirectory, "antigravity-oauth-token"); + const legacyTokenPath = path.join(acpDirectory, "acp_token.json"); + // Prefer agy's current token file; a legacy one may linger from an older agy with a revoked token. + const readToken = Effect.gen(function* () { + if (yield* fs.exists(agyTokenPath)) { + const file = yield* fs.readFileString(agyTokenPath).pipe(Effect.flatMap(decodeAgyTokenFile)); + const token: typeof TokenFile.Type = { + ...AGY_OAUTH_CLIENT, + refresh_token: file.token.refresh_token, + }; + return token; + } + if (yield* fs.exists(legacyTokenPath)) { + return yield* fs.readFileString(legacyTokenPath).pipe(Effect.flatMap(decodeTokenFile)); + } + return undefined; + }); let cached: | { fingerprint: string; account: string; accessToken: string; expiresAt: number } | undefined; @@ -236,7 +263,8 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")( if (input.authMethod !== "oauth-personal" && input.authMethod !== "oauth-business") { return makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" }); } - if (!(yield* fs.exists(tokenPath))) { + const token = yield* readToken; + if (token === undefined) { cached = undefined; return makeUnavailableUsageLimits({ checkedAt, @@ -244,7 +272,6 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")( message: "Sign in with Google to see Antigravity limits.", }); } - const token = yield* fs.readFileString(tokenPath).pipe(Effect.flatMap(decodeTokenFile)); const fingerprint = yield* sha256( `${token.client_id}\0${token.refresh_token}\0${token.project_id ?? ""}`, );