Skip to content
TypeScript

fix(antigravity): forward Google sign-in URLs from browser helper (#9425)

WellyngtonFe01c153c18a9
diff --git a/apps/server/src/provider/AntigravityAuth.test.ts b/apps/server/src/provider/AntigravityAuth.test.ts
index acad458e967..8a27ade0e6b 100644
--- a/apps/server/src/provider/AntigravityAuth.test.ts
+++ b/apps/server/src/provider/AntigravityAuth.test.ts
@@ -54,6 +54,7 @@ const phase = (auth: AntigravityAuth, value: ProviderAuthState["phase"], session
const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
options: {
readonly interactive?: boolean;
+ readonly authorizationUrls?: ReadonlyArray<string>;
readonly supportsLogout?: boolean;
readonly forwardCallback?: Effect.Effect<void, ProviderSetupError>;
} = {},
@@ -62,12 +63,16 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
const discovered = yield* Deferred.make<void>();
const closed = yield* Deferred.make<void>();
const events: string[] = [];
+ let receiveAuthorizationUrl:
+ | ((url: string) => Effect.Effect<void, AcpErrors.AcpError>)
+ | undefined;
let forwarded = 0;
let catalog = ["previous-account-model"];
const auth = yield* makeAntigravityAuth({
instanceId,
makeRuntime: (input) =>
Effect.gen(function* () {
+ receiveAuthorizationUrl = input.onAuthorizationUrl;
events.push("process-open");
yield* Effect.addFinalizer(() =>
Effect.gen(function* () {
@@ -87,7 +92,9 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
Effect.gen(function* () {
events.push("authenticate");
if (options.interactive !== false && input.onAuthorizationUrl) {
- yield* input.onAuthorizationUrl(authorizationUrl);
+ for (const url of options.authorizationUrls ?? [authorizationUrl]) {
+ yield* input.onAuthorizationUrl(url);
+ }
}
yield* Deferred.await(authenticated);
events.push("session-new");
@@ -124,10 +131,62 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
events,
catalog: () => catalog,
forwarded: () => forwarded,
+ receiveAuthorizationUrl: (url: string) =>
+ Effect.suspend(() =>
+ receiveAuthorizationUrl
+ ? receiveAuthorizationUrl(url)
+ : Effect.die("Authorization URL receiver is not ready."),
+ ),
};
});
it.layer(NodeServices.layer)("AntigravityAuth", (it) => {
+ it.effect("accepts the same authorization URL from stderr and stdout", () =>
+ Effect.gen(function* () {
+ const harness = yield* makeHarness({
+ authorizationUrls: [authorizationUrl, authorizationUrl],
+ });
+ yield* harness.auth.controller.start(owner);
+ const waiting = yield* phase(harness.auth, "waiting");
+ assert.equal(waiting.authorizationUrl, authorizationUrl);
+
+ yield* Deferred.succeed(harness.authenticated, undefined);
+ yield* Deferred.succeed(harness.discovered, undefined);
+ yield* phase(harness.auth, "succeeded");
+ }),
+ );
+
+ it.effect("accepts a delayed duplicate after callback completion starts", () =>
+ Effect.gen(function* () {
+ const harness = yield* makeHarness();
+ const state = yield* harness.auth.controller.start(owner);
+ yield* phase(harness.auth, "waiting");
+ yield* harness.auth.controller.complete(owner, {
+ flowId: state.flowId!,
+ callbackUrl,
+ });
+
+ yield* harness.receiveAuthorizationUrl(authorizationUrl);
+
+ yield* Deferred.succeed(harness.authenticated, undefined);
+ yield* Deferred.succeed(harness.discovered, undefined);
+ yield* phase(harness.auth, "succeeded");
+ }),
+ );
+
+ it.effect("rejects a different second authorization URL", () =>
+ Effect.gen(function* () {
+ const harness = yield* makeHarness({
+ authorizationUrls: [authorizationUrl, `${authorizationUrl}&scope=another-request`],
+ });
+ yield* harness.auth.controller.start(owner);
+
+ const failed = yield* phase(harness.auth, "failed");
+ assert.isNull(failed.authorizationUrl);
+ assert.deepEqual(harness.catalog(), ["previous-account-model"]);
+ }),
+ );
+
it.effect("keeps a remote flow private and waits for native auth and catalog discovery", () =>
Effect.gen(function* () {
const harness = yield* makeHarness();
diff --git a/apps/server/src/provider/AntigravityAuth.ts b/apps/server/src/provider/AntigravityAuth.ts
index 8f5ba71f9ea..500bca120eb 100644
--- a/apps/server/src/provider/AntigravityAuth.ts
+++ b/apps/server/src/provider/AntigravityAuth.ts
@@ -20,11 +20,13 @@ import * as SubscriptionRef from "effect/SubscriptionRef";
import * as AcpErrors from "effect-acp/errors";
import type { AcpSessionRuntime, AcpSessionRuntimeStartResult } from "./acp/AcpSessionRuntime.ts";
-import { parseAntigravityAuthorizationUrl } from "./antigravityAuthSupport.ts";
+import {
+ parseAntigravityAuthorizationUrl,
+ type AntigravityAuthorizationUrl,
+} from "./antigravityAuthSupport.ts";
import {
forwardAntigravityCallback,
validateAntigravityCallbackUrl,
- type AntigravityPendingCallback,
} from "./antigravityCallback.ts";
import type { ProviderAuthController } from "./Services/ProviderAuthService.ts";
@@ -43,7 +45,7 @@ interface AuthFlow {
readonly ownerSessionId: string;
readonly expiresAtMillis: number;
state: ProviderAuthState;
- pending: AntigravityPendingCallback | undefined;
+ pending: AntigravityAuthorizationUrl | undefined;
callbackSent: boolean;
fiber: Fiber.Fiber<void> | undefined;
forwarding: Fiber.Fiber<void, ProviderSetupError> | undefined;
@@ -239,6 +241,7 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
Effect.gen(function* () {
if (activeFlow !== flow || operation !== "auth") return;
if (flow.pending) {
+ if (flow.pending.authorizationUrl === authorization.authorizationUrl) return;
return yield* new AcpErrors.AcpTransportError({
detail: "Antigravity started more than one Google sign-in request.",
cause: undefined,
diff --git a/apps/server/src/provider/Layers/AntigravityProvider.test.ts b/apps/server/src/provider/Layers/AntigravityProvider.test.ts
index 639d3d11c79..d4a16265d55 100644
--- a/apps/server/src/provider/Layers/AntigravityProvider.test.ts
+++ b/apps/server/src/provider/Layers/AntigravityProvider.test.ts
@@ -13,6 +13,7 @@ import * as Layer from "effect/Layer";
import * as Ref from "effect/Ref";
import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
+import * as TestClock from "effect/testing/TestClock";
import * as EffectAcpErrors from "effect-acp/errors";
import type * as EffectAcpSchema from "effect-acp/schema";
@@ -411,6 +412,27 @@ it.layer(testLayer)("Antigravity provider snapshots", (it) => {
),
);
+ it.effect("allows a slow packaged runtime health check to finish", () =>
+ Effect.scoped(
+ Effect.gen(function* () {
+ const harness = yield* makeHarness();
+ yield* harness.initialize;
+ yield* Ref.set(harness.probe, Effect.sleep("20 seconds").pipe(Effect.as(initializeResult)));
+
+ const refresh = yield* harness.provider.snapshot.refresh.pipe(Effect.forkChild);
+ yield* Effect.yieldNow;
+ yield* TestClock.adjust("20 seconds");
+ const snapshot = yield* Fiber.join(refresh);
+
+ expect(snapshot).toMatchObject({
+ installed: true,
+ status: "warning",
+ auth: { status: "unknown" },
+ });
+ }),
+ ),
+ );
+
it.effect("distinguishes missing executables from a failed installed executable", () =>
Effect.scoped(
Effect.gen(function* () {
diff --git a/apps/server/src/provider/Layers/AntigravityProvider.ts b/apps/server/src/provider/Layers/AntigravityProvider.ts
index c8614a118d3..c10a6ad5af2 100644
--- a/apps/server/src/provider/Layers/AntigravityProvider.ts
+++ b/apps/server/src/provider/Layers/AntigravityProvider.ts
@@ -32,6 +32,7 @@ import {
const EMPTY_MODEL_CAPABILITIES = createModelCapabilities({ optionDescriptors: [] });
const MAX_WORKSPACE_SNAPSHOTS = 32;
+const HEALTH_CHECK_TIMEOUT = "45 seconds";
const SIGN_IN_MESSAGE = "Sign in with Google to use Antigravity.";
const AUTH_UNCHECKED_MESSAGE =
"Antigravity is installed. Google account access is not checked yet.";
@@ -166,7 +167,10 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
const checkProvider = Effect.fn("checkAntigravityProvider")(function* () {
if (!settings.enabled) return yield* getSnapshot;
const before = yield* SubscriptionRef.get(metadata);
- const result = yield* options.probe.pipe(Effect.timeoutOption("15 seconds"), Effect.result);
+ const result = yield* options.probe.pipe(
+ Effect.timeoutOption(HEALTH_CHECK_TIMEOUT),
+ Effect.result,
+ );
const initialized =
Result.isSuccess(result) && Option.isSome(result.success) ? result.success.value : undefined;
const failure = Result.isFailure(result) ? result.failure : undefined;
@@ -180,7 +184,7 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
? "Antigravity is not installed or its executable could not be found."
: failure
? "Antigravity could not complete its local health check."
- : "Antigravity did not respond to its local health check within 15 seconds.";
+ : `Antigravity did not respond to its local health check within ${HEALTH_CHECK_TIMEOUT}.`;
const supportsTextGeneration =
initialized !== undefined ? yield* options.supportsTextGeneration : false;
const updatedAt = DateTime.formatIso(yield* DateTime.now);
diff --git a/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts b/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts
index 7db8ff514ec..02693ff1ebc 100644
--- a/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts
+++ b/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts
@@ -327,7 +327,7 @@ describe("AcpSessionRuntime", () => {
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);
- it.effect("drains large stderr output and bounds optional logging chunks", () =>
+ it.effect("drains large stderr output and keeps auth-sized logging chunks", () =>
Effect.gen(function* () {
const lengths: Array<number> = [];
for (const logStderr of [false, true]) {
@@ -348,7 +348,8 @@ describe("AcpSessionRuntime", () => {
}).pipe(Effect.scoped);
}
expect(lengths.length).toBeGreaterThan(0);
- expect(Math.max(...lengths)).toBeLessThanOrEqual(8_192);
+ expect(Math.max(...lengths)).toBeGreaterThanOrEqual(16_384);
+ expect(Math.max(...lengths)).toBeLessThanOrEqual(32_768);
}).pipe(Effect.provide(NodeServices.layer)),
);
diff --git a/apps/server/src/provider/acp/AcpSessionRuntime.ts b/apps/server/src/provider/acp/AcpSessionRuntime.ts
index 6538a47cbcb..1d894d18d8c 100644
--- a/apps/server/src/provider/acp/AcpSessionRuntime.ts
+++ b/apps/server/src/provider/acp/AcpSessionRuntime.ts
@@ -66,7 +66,8 @@ const defaultSessionLoadTimeout = Duration.seconds(90);
const defaultSessionLoadReplayIdleGap = Duration.seconds(2);
const defaultCancelTimeout = Duration.seconds(15);
const maxStartupMetadataUpdates = 32;
-const maxStderrChunkLength = 8_192;
+// Antigravity can emit an accepted 16 KiB Google authorization URL on stderr.
+const maxStderrChunkLength = 32_768;
export interface AcpSpawnInput {
readonly command: string;
diff --git a/apps/server/src/provider/acp/AntigravityAcpSupport.ts b/apps/server/src/provider/acp/AntigravityAcpSupport.ts
index c05994c62c9..d89aa421073 100644
--- a/apps/server/src/provider/acp/AntigravityAcpSupport.ts
+++ b/apps/server/src/provider/acp/AntigravityAcpSupport.ts
@@ -19,7 +19,7 @@ import type * as EffectAcpSchema from "effect-acp/schema";
import { resolveAttachmentPath } from "../../attachmentStore.ts";
import {
- drainAntigravityStderr,
+ makeAntigravityStderrHandler,
makeAntigravityStdoutTransform,
} from "../antigravityAuthSupport.ts";
import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
@@ -73,7 +73,13 @@ export const makeAntigravityAcpRuntime = Effect.fn("makeAntigravityAcpRuntime")(
transformStdout: makeAntigravityStdoutTransform(
input.onAuthorizationUrl ? { onAuthorizationUrl: input.onAuthorizationUrl } : {},
),
- onStderr: drainAntigravityStderr,
+ ...(input.onAuthorizationUrl
+ ? {
+ onStderr: makeAntigravityStderrHandler({
+ onAuthorizationUrl: input.onAuthorizationUrl,
+ }),
+ }
+ : {}),
transformSessionUpdate: normalizeAntigravitySessionUpdate,
}).pipe(
Layer.provide(
diff --git a/apps/server/src/provider/antigravityAuthSupport.test.ts b/apps/server/src/provider/antigravityAuthSupport.test.ts
index 0e3470c7238..5bac0847986 100644
--- a/apps/server/src/provider/antigravityAuthSupport.test.ts
+++ b/apps/server/src/provider/antigravityAuthSupport.test.ts
@@ -17,6 +17,7 @@ import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawne
import * as AcpErrors from "effect-acp/errors";
import {
+ ANTIGRAVITY_AUTH_BROWSER_MARKER,
ANTIGRAVITY_AUTH_STDOUT_PREFIX,
ANTIGRAVITY_PERSONAL_AUTH,
ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE,
@@ -26,6 +27,7 @@ import {
antigravityProfileSettings,
buildAntigravityAcpSpawnInput,
isAntigravitySignInRequiredError,
+ makeAntigravityStderrHandler,
makeAntigravityStdoutTransform,
parseAntigravityAuthorizationUrl,
prepareAntigravityProfile,
@@ -388,6 +390,60 @@ describe("Antigravity stdout compatibility", () => {
);
});
+describe("Antigravity stderr compatibility", () => {
+ it.effect("forwards an accepted browser-helper URL larger than 8 KiB", () =>
+ Effect.gen(function* () {
+ const urls: string[] = [];
+ const longAuthorizationUrl = `${authorizationUrl}&scope=${"a".repeat(9_000)}`;
+ const handleStderr = makeAntigravityStderrHandler({
+ onAuthorizationUrl: (url) => Effect.sync(() => void urls.push(url)),
+ });
+
+ expect(longAuthorizationUrl.length).toBeGreaterThan(8_192);
+ yield* handleStderr(
+ `${ANTIGRAVITY_AUTH_BROWSER_MARKER}${encodeUnknownJson(longAuthorizationUrl)}\n`,
+ );
+
+ expect(urls).toEqual([longAuthorizationUrl]);
+ }),
+ );
+
+ it.effect("forwards a fragmented browser-helper URL without exposing other stderr", () =>
+ Effect.gen(function* () {
+ const urls: string[] = [];
+ const markerLine = `${ANTIGRAVITY_AUTH_BROWSER_MARKER}${encodeUnknownJson(authorizationUrl)}\n`;
+ const handleStderr = makeAntigravityStderrHandler({
+ onAuthorizationUrl: (url) => Effect.sync(() => void urls.push(url)),
+ });
+
+ yield* handleStderr(`native log\n${markerLine.slice(0, 12)}`);
+ yield* handleStderr(markerLine.slice(12, 70));
+ yield* handleStderr(`${markerLine.slice(70)}another native log\n`);
+
+ expect(urls).toEqual([authorizationUrl]);
+ }),
+ );
+
+ it.effect("ignores malformed and similar browser-helper messages", () =>
+ Effect.gen(function* () {
+ const urls: string[] = [];
+ const handleStderr = makeAntigravityStderrHandler({
+ onAuthorizationUrl: (url) => Effect.sync(() => void urls.push(url)),
+ });
+
+ yield* handleStderr(
+ ` ${ANTIGRAVITY_AUTH_BROWSER_MARKER}${encodeUnknownJson(authorizationUrl)}\n`,
+ );
+ yield* handleStderr(`${ANTIGRAVITY_AUTH_BROWSER_MARKER}${authorizationUrl}\n`);
+ yield* handleStderr(
+ `${ANTIGRAVITY_AUTH_BROWSER_MARKER}${encodeUnknownJson("https://example.com")}\n`,
+ );
+
+ expect(urls).toEqual([]);
+ }),
+ );
+});
+
it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => {
it.effect("preflights the no-browser helper and creates private directories only", () =>
Effect.gen(function* () {
diff --git a/apps/server/src/provider/antigravityAuthSupport.ts b/apps/server/src/provider/antigravityAuthSupport.ts
index bc1baf9085b..80116120e6a 100644
--- a/apps/server/src/provider/antigravityAuthSupport.ts
+++ b/apps/server/src/provider/antigravityAuthSupport.ts
@@ -24,9 +24,12 @@ export const ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE =
"Sign in to Antigravity in Settings before you continue.";
const maxAuthorizationUrlLength = 16_384;
+const maxBrowserHelperLineLength =
+ ANTIGRAVITY_AUTH_BROWSER_MARKER.length + maxAuthorizationUrlLength + 2;
const maxStdoutLineBytes = 16 * 1024 * 1024;
const authPrefixBytes = new TextEncoder().encode(ANTIGRAVITY_AUTH_STDOUT_PREFIX);
const decodeUrl = Schema.decodeUnknownEffect(Schema.URLFromString);
+const decodeBrowserHelperUrl = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.String));
const ProfileSettingsFile = Schema.Struct({
auth: Schema.Struct({ type: Schema.String }),
gcp: Schema.optional(
@@ -455,5 +458,32 @@ export function makeAntigravityStdoutTransform(
});
}
-/** Upstream stderr can contain OAuth URLs, states, and redirect codes. */
-export const drainAntigravityStderr = (_text: string): Effect.Effect<void> => Effect.void;
+/** Receives the URL emitted by T3's no-browser helper on stderr. */
+export function makeAntigravityStderrHandler(input: {
+ readonly onAuthorizationUrl: (
+ authorizationUrl: string,
+ ) => Effect.Effect<void, AcpErrors.AcpError>;
+}) {
+ let pending = "";
+ const handleLine = (line: string) => {
+ const message = line.endsWith("\r") ? line.slice(0, -1) : line;
+ if (
+ message.length > maxBrowserHelperLineLength ||
+ !message.startsWith(ANTIGRAVITY_AUTH_BROWSER_MARKER)
+ ) {
+ return Effect.void;
+ }
+ return decodeBrowserHelperUrl(message.slice(ANTIGRAVITY_AUTH_BROWSER_MARKER.length)).pipe(
+ Effect.flatMap(parseAntigravityAuthorizationUrl),
+ Effect.flatMap((request) => input.onAuthorizationUrl(request.authorizationUrl)),
+ Effect.ignore,
+ );
+ };
+
+ return Effect.fn("antigravityAuthSupport.handleStderr")(function* (text: string) {
+ const lines = `${pending}${text}`.split("\n");
+ pending = lines.pop() ?? "";
+ if (pending.length > maxBrowserHelperLineLength) pending = "";
+ yield* Effect.forEach(lines, handleLine, { discard: true });
+ });
+}