Skip to content

Commit 6e8851c

Browse files
fix(server): Antigravity sign-in no longer blames the network when the runtime never starts (pingdotgg#29057)
1 parent 85f0419 commit 6e8851c

2 files changed

Lines changed: 61 additions & 18 deletions

File tree

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,35 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("AntigravityAuth"
320320
}),
321321
);
322322

323+
it.effect("does not blame the network when the runtime never answers initialize", () =>
324+
Effect.gen(function* () {
325+
const initializing = yield* Deferred.make<void>();
326+
const harness = yield* makeHarness({
327+
beforeInitialize: Deferred.succeed(initializing, undefined).pipe(
328+
Effect.andThen(Effect.never),
329+
),
330+
});
331+
yield* harness.auth.controller.start(owner);
332+
yield* Deferred.await(initializing);
333+
const blamesNetwork = /reach(ed)? Google|network|ipv6/i;
334+
335+
yield* TestClock.adjust("90 seconds");
336+
const stalled = yield* harness.auth.controller.subscribe(owner).pipe(
337+
Stream.filter((state) => state.message !== "Starting Google sign-in."),
338+
Stream.runHead,
339+
Effect.map(Option.getOrThrow),
340+
);
341+
assert.equal(stalled.phase, "starting");
342+
assert.notMatch(stalled.message ?? "", blamesNetwork);
343+
assert.match(stalled.message ?? "", /not started|stuck/i);
344+
345+
yield* TestClock.adjust("210 seconds");
346+
const failed = yield* phase(harness.auth, "failed");
347+
assert.notMatch(failed.message ?? "", blamesNetwork);
348+
assert.match(failed.message ?? "", /not respond|may not run/i);
349+
}),
350+
);
351+
323352
it.effect("keeps the expired message once the Google link was shown", () =>
324353
Effect.gen(function* () {
325354
const harness = yield* makeHarness();

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ import {
3131
import type { ProviderAuthController } from "./ProviderAuthService.ts";
3232

3333
const AUTH_TIMEOUT_MS = 300_000;
34-
// Once initialized, a healthy agent shows the Google link or finishes within seconds. Its bundled
35-
// Python has no IPv4 fallback race, so a host with broken IPv6 waits about two minutes per Google
36-
// request. The hint is timed from initialize, not spawn: the one-file runtime unpacks itself on
37-
// every launch, which can take about a minute on Windows before it answers at all.
34+
// Once initialized, a healthy agent shows the Google link within seconds; its bundled Python has no
35+
// IPv4 fallback, so broken IPv6 stalls each Google request. Startup is timed separately: the
36+
// one-file runtime unpacks on every launch (about a minute on Windows) before it answers initialize.
3837
const NO_RESPONSE_HINT_MS = 30_000;
38+
const STARTUP_HINT_MS = 90_000;
39+
const NOT_STARTED_MESSAGE =
40+
"Antigravity has not started after 90 seconds. Its runtime may be stuck starting on this machine.";
41+
const NOT_RESPONDING_MESSAGE =
42+
"Antigravity did not respond. Its runtime may not run on this machine.";
3943
const NO_RESPONSE_MESSAGE =
4044
"Antigravity has not reached Google after 30 seconds. Check this machine's network connection. Broken IPv6 is a common cause.";
4145
const UNREACHABLE_MESSAGE =
@@ -55,6 +59,7 @@ interface AuthFlow {
5559
readonly expiresAtMillis: number;
5660
state: ProviderAuthState;
5761
pending: AntigravityAuthorizationUrl | undefined;
62+
initialized: boolean;
5863
callbackSent: boolean;
5964
fiber: Fiber.Fiber<void> | undefined;
6065
forwarding: Fiber.Fiber<void, ProviderSetupError> | undefined;
@@ -270,25 +275,31 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
270275
),
271276
);
272277

278+
const publishStartingHint = (flow: AuthFlow, delayMs: number, message: string) =>
279+
Effect.sleep(delayMs).pipe(
280+
Effect.andThen(
281+
lock.withPermits(1)(
282+
Effect.gen(function* () {
283+
if (activeFlow !== flow || flow.state.phase !== "starting") return;
284+
yield* publishFlow(flow, { ...flow.state, message });
285+
}),
286+
),
287+
),
288+
Effect.forkScoped,
289+
);
290+
273291
const runSignIn = Effect.fn("AntigravityAuth.runSignIn")(
274292
function* (flow: AuthFlow, stopSessions: Effect.Effect<void, ProviderSetupError>) {
275293
yield* stopSessions.pipe(Effect.ensuring(stopOwnedProcesses));
276294
const runtime = yield* options.makeRuntime({
277295
onAuthorizationUrl: (url) => receiveAuthorizationUrl(flow, url),
278296
});
297+
const startupHint = yield* publishStartingHint(flow, STARTUP_HINT_MS, NOT_STARTED_MESSAGE);
279298
// `start` reuses this memoized handshake.
280299
yield* runtime.initialize();
281-
yield* Effect.sleep(NO_RESPONSE_HINT_MS).pipe(
282-
Effect.andThen(
283-
lock.withPermits(1)(
284-
Effect.gen(function* () {
285-
if (activeFlow !== flow || flow.state.phase !== "starting") return;
286-
yield* publishFlow(flow, { ...flow.state, message: NO_RESPONSE_MESSAGE });
287-
}),
288-
),
289-
),
290-
Effect.forkScoped,
291-
);
300+
flow.initialized = true;
301+
yield* Fiber.interrupt(startupHint);
302+
yield* publishStartingHint(flow, NO_RESPONSE_HINT_MS, NO_RESPONSE_MESSAGE);
292303
const started = yield* runtime.start();
293304
yield* lock.withPermits(1)(
294305
Effect.gen(function* () {
@@ -313,9 +324,11 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
313324
Effect.fail(
314325
setupError(
315326
"start",
316-
flow.state.phase === "starting"
317-
? UNREACHABLE_MESSAGE
318-
: "Google sign-in expired. Start sign-in again.",
327+
flow.state.phase !== "starting"
328+
? "Google sign-in expired. Start sign-in again."
329+
: flow.initialized
330+
? UNREACHABLE_MESSAGE
331+
: NOT_RESPONDING_MESSAGE,
319332
),
320333
),
321334
}),
@@ -402,6 +415,7 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
402415
expiresAtMillis,
403416
state,
404417
pending: undefined,
418+
initialized: false,
405419
callbackSent: false,
406420
fiber: undefined,
407421
forwarding: undefined,

0 commit comments

Comments
 (0)