Skip to content
TypeScript

fix(server): Antigravity sign-in no longer blames the network while the runtime starts (#30079)

wenshen18643d075bed70f7b
diff --git a/apps/server/src/provider/AntigravityAuth.test.ts b/apps/server/src/provider/AntigravityAuth.test.ts
index 4664c299e8a..d7099ec2bfa 100644
--- a/apps/server/src/provider/AntigravityAuth.test.ts
+++ b/apps/server/src/provider/AntigravityAuth.test.ts
@@ -84,17 +84,21 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
yield* Deferred.succeed(closed, undefined);
}),
);
+ // Like AcpSessionRuntime, `start` reuses one memoized initialize handshake.
+ const initialize = yield* Effect.cached(
+ Effect.gen(function* () {
+ events.push("initialize");
+ yield* options.beforeInitialize ?? Effect.void;
+ return options.supportsLogout === false
+ ? { ...initialized, agentCapabilities: {} }
+ : initialized;
+ }),
+ );
return {
- initialize: () =>
- Effect.gen(function* () {
- events.push("initialize");
- yield* options.beforeInitialize ?? Effect.void;
- return options.supportsLogout === false
- ? { ...initialized, agentCapabilities: {} }
- : initialized;
- }),
+ initialize: () => initialize,
start: () =>
Effect.gen(function* () {
+ yield* initialize;
events.push("authenticate");
yield* Deferred.succeed(authenticateCalled, undefined);
if (options.interactive !== false && input.onAuthorizationUrl) {
@@ -280,6 +284,42 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("AntigravityAuth"
}),
);
+ it.effect("does not blame the network while the runtime is still starting", () =>
+ Effect.gen(function* () {
+ const initializing = yield* Deferred.make<void>();
+ const ready = yield* Deferred.make<void>();
+ const harness = yield* makeHarness({
+ interactive: false,
+ beforeInitialize: Deferred.succeed(initializing, undefined).pipe(
+ Effect.andThen(Deferred.await(ready)),
+ ),
+ });
+ const hasHint = harness.auth.controller.subscribe(owner).pipe(
+ Stream.runHead,
+ Effect.map((state) => Option.getOrThrow(state).message?.includes("Broken IPv6") === true),
+ );
+ yield* harness.auth.controller.start(owner);
+ yield* Deferred.await(initializing);
+
+ // A one-file runtime can take about a minute to unpack before it answers initialize.
+ yield* TestClock.adjust("60 seconds");
+ assert.isFalse(yield* hasHint);
+
+ yield* Deferred.succeed(ready, undefined);
+ yield* Deferred.await(harness.authenticateCalled);
+ yield* TestClock.adjust("29 seconds");
+ assert.isFalse(yield* hasHint);
+
+ yield* TestClock.adjust("1 second");
+ const stalled = yield* harness.auth.controller.subscribe(owner).pipe(
+ Stream.filter((state) => state.message?.includes("Broken IPv6") === true),
+ Stream.runHead,
+ Effect.map(Option.getOrThrow),
+ );
+ assert.equal(stalled.phase, "starting");
+ }),
+ );
+
it.effect("keeps the expired message once the Google link was shown", () =>
Effect.gen(function* () {
const harness = yield* makeHarness();
@@ -385,7 +425,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("AntigravityAuth"
assert.isTrue(Exit.isFailure(competing));
const resumed = yield* phase(harness.auth, "waiting");
assert.equal(resumed.flowId, first.flowId);
- assert.deepEqual(harness.events, ["process-open", "authenticate"]);
+ assert.deepEqual(harness.events, ["process-open", "initialize", "authenticate"]);
yield* harness.auth.controller.cancel(owner, first.flowId!);
}),
);
diff --git a/apps/server/src/provider/AntigravityAuth.ts b/apps/server/src/provider/AntigravityAuth.ts
index 7f19bd3a9b0..d1ebb7d5395 100644
--- a/apps/server/src/provider/AntigravityAuth.ts
+++ b/apps/server/src/provider/AntigravityAuth.ts
@@ -31,8 +31,10 @@ import {
import type { ProviderAuthController } from "./ProviderAuthService.ts";
const AUTH_TIMEOUT_MS = 300_000;
-// A healthy agent shows the Google link or finishes within seconds. Its bundled Python has no
-// IPv4 fallback race, so a host with broken IPv6 waits about two minutes per Google request.
+// Once initialized, a healthy agent shows the Google link or finishes within seconds. Its bundled
+// Python has no IPv4 fallback race, so a host with broken IPv6 waits about two minutes per Google
+// request. The hint is timed from initialize, not spawn: the one-file runtime unpacks itself on
+// every launch, which can take about a minute on Windows before it answers at all.
const NO_RESPONSE_HINT_MS = 30_000;
const NO_RESPONSE_MESSAGE =
"Antigravity has not reached Google after 30 seconds. Check this machine's network connection. Broken IPv6 is a common cause.";
@@ -271,6 +273,11 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
const runSignIn = Effect.fn("AntigravityAuth.runSignIn")(
function* (flow: AuthFlow, stopSessions: Effect.Effect<void, ProviderSetupError>) {
yield* stopSessions.pipe(Effect.ensuring(stopOwnedProcesses));
+ const runtime = yield* options.makeRuntime({
+ onAuthorizationUrl: (url) => receiveAuthorizationUrl(flow, url),
+ });
+ // `start` reuses this memoized handshake.
+ yield* runtime.initialize();
yield* Effect.sleep(NO_RESPONSE_HINT_MS).pipe(
Effect.andThen(
lock.withPermits(1)(
@@ -282,9 +289,6 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
),
Effect.forkScoped,
);
- const runtime = yield* options.makeRuntime({
- onAuthorizationUrl: (url) => receiveAuthorizationUrl(flow, url),
- });
const started = yield* runtime.start();
yield* lock.withPermits(1)(
Effect.gen(function* () {