TypeScript
fix(antigravity): say when sign-in cannot reach Google (#24652)
Theo Browne288785552866
diff --git a/apps/server/src/provider/AntigravityAuth.test.ts b/apps/server/src/provider/AntigravityAuth.test.tsindex dfcfb2fecdc..af156a61663 100644--- a/apps/server/src/provider/AntigravityAuth.test.ts+++ b/apps/server/src/provider/AntigravityAuth.test.ts@@ -8,6 +8,7 @@ import * as Fiber from "effect/Fiber";import * as Option from "effect/Option";import * as Scope from "effect/Scope";import * as Stream from "effect/Stream";+import * as TestClock from "effect/testing/TestClock";import * as AcpErrors from "effect-acp/errors";import type * as AcpSchema from "effect-acp/compat";@@ -62,6 +63,7 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (const authenticated = yield* Deferred.make<void, AcpErrors.AcpError>();const discovered = yield* Deferred.make<void, AcpErrors.AcpError>();const closed = yield* Deferred.make<void>();+ const authenticateCalled = yield* Deferred.make<void>();const events: string[] = [];let receiveAuthorizationUrl:| ((url: string) => Effect.Effect<void, AcpErrors.AcpError>)@@ -92,6 +94,7 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (start: () =>Effect.gen(function* () {events.push("authenticate");+ yield* Deferred.succeed(authenticateCalled, undefined);if (options.interactive !== false && input.onAuthorizationUrl) {for (const url of options.authorizationUrls ?? [authorizationUrl]) {yield* input.onAuthorizationUrl(url);@@ -129,6 +132,7 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (authenticated,discovered,closed,+ authenticateCalled,events,catalog: () => catalog,forwarded: () => forwarded,@@ -254,6 +258,38 @@ it.layer(NodeServices.layer)("AntigravityAuth", (it) => {}),);+ it.effect("tells the user when the agent cannot reach Google", () =>+ Effect.gen(function* () {+ const harness = yield* makeHarness({ interactive: false });+ yield* harness.auth.controller.start(owner);+ yield* Deferred.await(harness.authenticateCalled);++ yield* TestClock.adjust("30 seconds");+ 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");++ yield* TestClock.adjust("270 seconds");+ const failed = yield* phase(harness.auth, "failed");+ assert.include(failed.message ?? "", "could not reach Google");+ }),+ );++ it.effect("keeps the expired message once the Google link was shown", () =>+ Effect.gen(function* () {+ const harness = yield* makeHarness();+ yield* harness.auth.controller.start(owner);+ yield* phase(harness.auth, "waiting");++ yield* TestClock.adjust("300 seconds");+ const failed = yield* phase(harness.auth, "failed");+ assert.equal(failed.message, "Google sign-in expired. Start sign-in again.");+ }),+ );+it.effect("accepts direct local or cached completion without a callback RPC", () =>Effect.gen(function* () {const harness = yield* makeHarness({ interactive: false });diff --git a/apps/server/src/provider/AntigravityAuth.ts b/apps/server/src/provider/AntigravityAuth.tsindex c97aa949aab..a2026faa78d 100644--- a/apps/server/src/provider/AntigravityAuth.ts+++ b/apps/server/src/provider/AntigravityAuth.ts@@ -31,6 +31,13 @@ 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.+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.";+const UNREACHABLE_MESSAGE =+ "Antigravity could not reach Google. Check this machine's network connection, then start sign-in again.";const FORWARDING_FAILED_MESSAGE = "Could not deliver the sign-in response. Start sign-in again.";const isSetupError = Schema.is(ProviderSetupError);const isAcpRequestError = Schema.is(AcpErrors.AcpRequestError);@@ -264,6 +271,17 @@ 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));+ yield* Effect.sleep(NO_RESPONSE_HINT_MS).pipe(+ Effect.andThen(+ lock.withPermits(1)(+ Effect.gen(function* () {+ if (activeFlow !== flow || flow.state.phase !== "starting") return;+ yield* publishFlow(flow, { ...flow.state, message: NO_RESPONSE_MESSAGE });+ }),+ ),+ ),+ Effect.forkScoped,+ );const runtime = yield* options.makeRuntime({onAuthorizationUrl: (url) => receiveAuthorizationUrl(flow, url),});@@ -288,7 +306,14 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <Effect.timeoutOrElse({duration: AUTH_TIMEOUT_MS,orElse: () =>- Effect.fail(setupError("start", "Google sign-in expired. Start sign-in again.")),+ Effect.fail(+ setupError(+ "start",+ flow.state.phase === "starting"+ ? UNREACHABLE_MESSAGE+ : "Google sign-in expired. Start sign-in again.",+ ),+ ),}),Effect.exit,Effect.flatMap((result) => finishFlow(flow, result)),diff --git a/apps/web/src/components/settings/ProviderAuthenticationSection.tsx b/apps/web/src/components/settings/ProviderAuthenticationSection.tsxindex 9e3037c79a4..2d6c9625034 100644--- a/apps/web/src/components/settings/ProviderAuthenticationSection.tsx+++ b/apps/web/src/components/settings/ProviderAuthenticationSection.tsx@@ -75,7 +75,7 @@ export function ProviderAuthenticationSection({(provider.driver === "acpRegistry" && auth?.methods?.length === 0));const accountDescription = active? auth?.phase === "starting"- ? "Starting sign-in…"+ ? (auth.message ?? "Starting sign-in…"): auth?.phase === "verifying"? "Checking your account…": interaction?.type === "terminal"