Skip to content

Commit e6eb974

Browse files
authored
Merge pull request lidge-jun#1891 from dbc-hbin/fix/antigravity-ua-parity
fix(antigravity): align User-Agent token order and auth_method with 2.5.5 decompilation
2 parents 920857d + 1c26d5c commit e6eb974

4 files changed

Lines changed: 36 additions & 18 deletions

File tree

‎src/adapters/client-fingerprint.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,19 @@ const ANTIGRAVITY_IDE_PLATFORM = "windows/amd64";
4949
export const ANTIGRAVITY_GOOG_API_CLIENT_UA = "google-api-nodejs-client/10.3.0";
5050

5151
/**
52-
* The real Antigravity IDE User-Agent, e.g.
53-
* `antigravity/ide/2.5.5 (aidev_client; os_type=windows; arch=amd64)`.
52+
* Real Antigravity IDE User-Agent format, decompiled from 2.5.5 Go LS (`setHeaders` @ `0x1018fbe00`):
53+
* `antigravity/ide/${version} (os_type=${osType}; arch=${arch}; aidev_client; auth_method=oauth)`
5454
*
55-
* Must be the IDE client family, NOT `antigravity/cli/...`: the Cloud Code Assist backend gates
55+
* Token ordering from decompiled binary: `os_type` -> `arch` -> `aidev_client` -> `auth_method=oauth`.
56+
*
57+
* Must be the IDE client family (`antigravity/ide/...`): Cloud Code Assist backend gates
5658
* newer agent models (e.g. `gemini-3.7-flash`) by User-Agent and answers 404 NOT_FOUND to
5759
* CLI-shaped UAs even with a valid OAuth token. Only `antigravity/ide/<ver>` unlocks them.
5860
* A `GOOGLE_ANTIGRAVITY_USER_AGENT` override (set by the caller) takes precedence upstream.
5961
*/
60-
export function antigravityUserAgent(version = ANTIGRAVITY_IDE_VERSION): string {
62+
export function antigravityUserAgent(version = ANTIGRAVITY_IDE_VERSION, authMethod = "oauth"): string {
63+
const ov = process.env.GOOGLE_ANTIGRAVITY_USER_AGENT?.trim();
64+
if (ov) return ov;
6165
const [osType, arch] = ANTIGRAVITY_IDE_PLATFORM.split("/");
62-
return `antigravity/ide/${version} (${ANTIGRAVITY_IDE_CLIENT_NAME}; os_type=${osType}; arch=${arch})`;
66+
return `antigravity/ide/${version} (os_type=${osType}; arch=${arch}; ${ANTIGRAVITY_IDE_CLIENT_NAME}; auth_method=${authMethod})`;
6367
}

‎src/adapters/google-antigravity-wire.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { antigravityUserAgent } from "./client-fingerprint";
99
* sends. The IDE client family is also required to unlock newer agent models (the backend 404s
1010
* CLI-shaped UAs for `gemini-3.7-*`). A `GOOGLE_ANTIGRAVITY_USER_AGENT` override still wins.
1111
*/
12-
export const ANTIGRAVITY_REQUEST_UA = process.env.GOOGLE_ANTIGRAVITY_USER_AGENT || antigravityUserAgent();
12+
export const ANTIGRAVITY_REQUEST_UA = antigravityUserAgent();
1313

1414
/**
1515
* Whether a stored `OcxToolCall.thoughtSignature` is a REAL upstream Gemini signature versus a

‎tests/client-fingerprint.test.ts‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,38 @@ function parsed(): OcxParsedRequest {
2121
describe("client fingerprint — helpers", () => {
2222
test("antigravity UA has the real IDE shape, never the literal giveaway", async () => {
2323
const ua = antigravityUserAgent();
24-
expect(ua).toBe(`antigravity/ide/${ANTIGRAVITY_IDE_VERSION} (aidev_client; os_type=windows; arch=amd64)`);
24+
expect(ua).toBe(`antigravity/ide/${ANTIGRAVITY_IDE_VERSION} (os_type=windows; arch=amd64; aidev_client; auth_method=oauth)`);
2525
expect(ua).not.toBe("antigravity");
2626
});
2727

28-
test("antigravity UA honors an explicit version override", async () => {
29-
expect(antigravityUserAgent("9.9.9")).toBe("antigravity/ide/9.9.9 (aidev_client; os_type=windows; arch=amd64)");
28+
test("antigravity UA honors explicit version and authMethod overrides", async () => {
29+
expect(antigravityUserAgent("9.9.9")).toBe("antigravity/ide/9.9.9 (os_type=windows; arch=amd64; aidev_client; auth_method=oauth)");
30+
expect(antigravityUserAgent(ANTIGRAVITY_IDE_VERSION, "api_key")).toBe(
31+
`antigravity/ide/${ANTIGRAVITY_IDE_VERSION} (os_type=windows; arch=amd64; aidev_client; auth_method=api_key)`,
32+
);
3033
});
3134

32-
test("GOOGLE_ANTIGRAVITY_USER_AGENT env override wins over the default UA", async () => {
33-
const prev = process.env.GOOGLE_ANTIGRAVITY_USER_AGENT;
34-
process.env.GOOGLE_ANTIGRAVITY_USER_AGENT = "custom-ua/1.2.3";
35+
test("GOOGLE_ANTIGRAVITY_USER_AGENT env override trims surrounding whitespace", async () => {
36+
const prevGoogle = process.env.GOOGLE_ANTIGRAVITY_USER_AGENT;
3537
try {
36-
// Fresh module instance so the env-driven constant is re-evaluated at import time.
37-
const mod = await import(`../src/adapters/google-antigravity-wire?override=${Date.now()}`);
38-
expect(mod.ANTIGRAVITY_REQUEST_UA).toBe("custom-ua/1.2.3");
38+
process.env.GOOGLE_ANTIGRAVITY_USER_AGENT = " custom-ua/1.2.3 ";
39+
expect(antigravityUserAgent()).toBe("custom-ua/1.2.3");
3940
} finally {
40-
if (prev === undefined) delete process.env.GOOGLE_ANTIGRAVITY_USER_AGENT;
41-
else process.env.GOOGLE_ANTIGRAVITY_USER_AGENT = prev;
41+
if (prevGoogle === undefined) delete process.env.GOOGLE_ANTIGRAVITY_USER_AGENT;
42+
else process.env.GOOGLE_ANTIGRAVITY_USER_AGENT = prevGoogle;
43+
}
44+
});
45+
46+
test("whitespace-only GOOGLE_ANTIGRAVITY_USER_AGENT falls back to default UA", async () => {
47+
const prevGoogle = process.env.GOOGLE_ANTIGRAVITY_USER_AGENT;
48+
try {
49+
process.env.GOOGLE_ANTIGRAVITY_USER_AGENT = " ";
50+
expect(antigravityUserAgent()).toBe(
51+
`antigravity/ide/${ANTIGRAVITY_IDE_VERSION} (os_type=windows; arch=amd64; aidev_client; auth_method=oauth)`,
52+
);
53+
} finally {
54+
if (prevGoogle === undefined) delete process.env.GOOGLE_ANTIGRAVITY_USER_AGENT;
55+
else process.env.GOOGLE_ANTIGRAVITY_USER_AGENT = prevGoogle;
4256
}
4357
});
4458

‎tests/google-antigravity-wire.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe("antigravity CCA envelope", () => {
5959
// The exact default must not drift: Google gates models by family AND version,
6060
// so any change to version/platform could silently re-lock gemini-3.7-flash.
6161
expect(req.headers["User-Agent"]).toBe(
62-
"antigravity/ide/2.5.5 (aidev_client; os_type=windows; arch=amd64)",
62+
"antigravity/ide/2.5.5 (os_type=windows; arch=amd64; aidev_client; auth_method=oauth)",
6363
);
6464
// The literal "antigravity" giveaway UA must no longer be sent.
6565
expect(req.headers["User-Agent"]).not.toBe("antigravity");

0 commit comments

Comments
 (0)