TypeScript
fix(server): preserve antigravity ipv6 startup diagnostics (#15629)
maria9f01c5846cda
diff --git a/apps/server/src/provider/AntigravityInstallation.test.ts b/apps/server/src/provider/AntigravityInstallation.test.tsindex 2817b215942..efab762da7c 100644--- a/apps/server/src/provider/AntigravityInstallation.test.ts+++ b/apps/server/src/provider/AntigravityInstallation.test.ts@@ -18,6 +18,7 @@ import * as Sink from "effect/Sink";import * as Stream from "effect/Stream";import * as TestClock from "effect/testing/TestClock";import { HttpClient, HttpClientResponse } from "effect/http";+import * as ChildProcess from "effect/process/ChildProcess";import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";import * as AntigravityInstallation from "./AntigravityInstallation.ts";@@ -553,6 +554,53 @@ it.layer(NodeServices.layer)("Antigravity installation", (it) => {}),);+ it.effect.each([+ {+ name: "IPv6 startup failure",+ stderr:+ "enforce_kernel_ipv6_support.cc:70] Check failed: AddressFamilySupported(AF_INET6, &loopback6_ok)",+ message:+ "Antigravity requires IPv6 socket support. Enable IPv6 in this environment. On WSL, remove ipv6.disable=1 from .wslconfig and run wsl --shutdown.",+ },+ {+ name: "other startup failure",+ stderr: "Private startup diagnostics: internal runtime failure",+ message: "The downloaded Antigravity runtime could not start in this environment.",+ },+ ])(+ "reports a fixed diagnostic for $name and preserves the previous release after SIGABRT",+ (testCase) =>+ Effect.gen(function* () {+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;+ const { installation, stagingReleased } = yield* makeHarness({+ previous: true,+ useDefaultValidation: true,+ }).pipe(+ Effect.provideService(+ ChildProcessSpawner.ChildProcessSpawner,+ ChildProcessSpawner.make((command) =>+ spawner.spawn(+ command._tag === "StandardCommand" && command.command.endsWith(executableName)+ ? ChildProcess.make(process.execPath, [+ "-e",+ `process.stderr.write(${encodeJsonString(testCase.stderr)}, () => process.kill(process.pid, 'SIGABRT'));`,+ ])+ : command,+ ),+ ),+ ),+ );+ yield* installation.start;+ expect(yield* terminalState(installation)).toMatchObject({+ phase: "failed",+ message: testCase.message,+ });+ yield* Deferred.await(stagingReleased);+ yield* expectPreviousRelease(installation);+ }),+ { skip: hostPlatform === "win32" },+ );+it.effect("accepts an encoded Content-Length when the body is compressed", () =>Effect.gen(function* () {// dl.google.com gzips the archive and reports the encoded size. The decodeddiff --git a/apps/server/src/provider/AntigravityInstallation.ts b/apps/server/src/provider/AntigravityInstallation.tsindex b73d26a9065..3b7cb6f1e18 100644--- a/apps/server/src/provider/AntigravityInstallation.ts+++ b/apps/server/src/provider/AntigravityInstallation.ts@@ -24,6 +24,7 @@ import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";import * as NodeCrypto from "node:crypto";import * as NodeFSP from "node:fs/promises";+import * as EffectAcpErrors from "effect-acp/errors";import * as ServerConfig from "../config.ts";import { openZipArchive } from "../zipArchive.ts";@@ -69,6 +70,7 @@ export class AntigravityInstallationError extends Schema.TaggedError<Antigravity}}const isInstallationError = Schema.is(AntigravityInstallationError);+const isAcpProcessExitedError = Schema.is(EffectAcpErrors.AcpProcessExitedError);export interface AntigravityExecutable {readonly executablePath: string;@@ -423,12 +425,15 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.maEffect.provideService(Path.Path, path),Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),Effect.provideService(Crypto.Crypto, crypto),- Effect.mapError(- wrapFailure(- "verify",- "The downloaded Antigravity runtime could not start in this environment.",- ),- ),+ Effect.mapError((cause) => {+ if (isInstallationError(cause)) return cause;+ const detail =+ isAcpProcessExitedError(cause) &&+ /\b(?:AF_INET6|enforce_kernel_ipv6_support)\b/.test(cause.stderr ?? "")+ ? "Antigravity requires IPv6 socket support. Enable IPv6 in this environment. On WSL, remove ipv6.disable=1 from .wslconfig and run wsl --shutdown."+ : "The downloaded Antigravity runtime could not start in this environment.";+ return installationError("verify", detail, cause);+ }),);const install = Effect.fn("AntigravityInstallation.install")(diff --git a/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts b/apps/server/src/provider/acp/AcpJsonRpcConnection.test.tsindex 4d1de51cc1b..11fb306a904 100644--- a/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts+++ b/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts@@ -5,7 +5,8 @@ import * as NodeURL from "node:url";import * as NodeFS from "node:fs";import * as NodeServices from "@effect/platform-node/NodeServices";-import { it } from "@effect/vitest";+import { assert, it } from "@effect/vitest";+import * as HostProcess from "@t3tools/shared/HostProcess";import * as Deferred from "effect/Deferred";import * as Effect from "effect/Effect";import * as Exit from "effect/Exit";@@ -376,7 +377,19 @@ describe("AcpSessionRuntime", () => {}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),);- it.effect("attaches child stderr when the ACP process exits before initialize", () =>+ it.effect.each([+ { name: "exit code", terminate: "process.exit(1)", code: 1, signal: undefined },+ ...(HostProcess.Platform.defaultValue() === "win32"+ ? []+ : [+ {+ name: "signal",+ terminate: "process.kill(process.pid, 'SIGTERM')",+ code: undefined,+ signal: "SIGTERM",+ },+ ]),+ ])("retains the $name and sanitized stderr when ACP exits before initialize", (testCase) =>Effect.gen(function* () {const runtime = yield* AcpSessionRuntime.make({...mockRuntimeOptions,@@ -384,15 +397,31 @@ describe("AcpSessionRuntime", () => {command: process.execPath,args: ["-e",- "process.stderr.write(\"Invalid project config at /tmp/project/.cursor/cli.json: schema validation failed. Unrecognized key(s): 'approvalMode', 'sandbox'\\n\"); process.exit(1);",+ `process.stderr.write("Invalid project config: Unrecognized key in cli.json\\nAuthorization: Bearer secret-token-value\\n", () => { ${testCase.terminate}; });`,],},});const error = yield* runtime.start().pipe(Effect.flip);- expect(error._tag).toBe("AcpProcessExitedError");- expect(error.message).toContain("cli.json");- expect(error.message).toContain("Unrecognized key");- expect(error.message).not.toContain("ACP process exited with code 1\nACP process exited");+ assert.instanceOf(error, EffectAcpErrors.AcpProcessExitedError);+ expect(error.code).toBe(testCase.code);+ expect(error.signal).toBe(testCase.signal);+ expect(error).toMatchObject({+ pid: expect.any(Number),+ stderr:+ "Invalid project config: Unrecognized key in cli.json\nAuthorization: Bearer [redacted]",+ });+ expect(error.message).toBe(+ `${testCase.signal ? "ACP process exited after signal SIGTERM" : "ACP process exited with code 1"}\nInvalid project config: Unrecognized key in cli.json\nAuthorization: Bearer [redacted]`,+ );+ if (testCase.signal) {+ expect(error.cause).toMatchObject({+ reason: {+ module: "ChildProcess",+ method: "exitCode",+ cause: new Error("Process interrupted due to receipt of signal: 'SIGTERM'"),+ },+ });+ }}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),);diff --git a/packages/effect-acp/src/_internal/stdio.ts b/packages/effect-acp/src/_internal/stdio.tsindex c04f27b97c4..ca445517923 100644--- a/packages/effect-acp/src/_internal/stdio.ts+++ b/packages/effect-acp/src/_internal/stdio.ts@@ -53,11 +53,23 @@ export const makeTerminationError = (handle: ChildProcessTerminationHandle,): Effect.Effect<AcpError.AcpError> =>Effect.match(handle.exitCode, {- onFailure: (cause) =>- new AcpError.AcpTransportError({- operation: "read-process-exit-status",- pid: handle.pid,- cause,- }),+ onFailure: (cause) => {+ // The Node spawner reports signal exits as a platform error rather than an exit code.+ const signal =+ cause.reason.module === "ChildProcess" &&+ cause.reason.method === "exitCode" &&+ cause.reason.cause instanceof Error+ ? /^Process interrupted due to receipt of signal: '(SIG[A-Z0-9]+)'$/.exec(+ cause.reason.cause.message,+ )?.[1]+ : undefined;+ return signal === undefined+ ? new AcpError.AcpTransportError({+ operation: "read-process-exit-status",+ pid: handle.pid,+ cause,+ })+ : new AcpError.AcpProcessExitedError({ signal, pid: handle.pid, cause });+ },onSuccess: (code) => new AcpError.AcpProcessExitedError({ code, pid: handle.pid }),});diff --git a/packages/effect-acp/src/errors.ts b/packages/effect-acp/src/errors.tsindex 506dced5e52..ef1c38d9267 100644--- a/packages/effect-acp/src/errors.ts+++ b/packages/effect-acp/src/errors.ts@@ -159,6 +159,7 @@ export class AcpProcessExitedError extends Schema.TaggedError<AcpProcessExitedEr"AcpProcessExitedError",{code: Schema.optional(Schema.Number),+ signal: Schema.optionalKey(Schema.String),pid: Schema.optionalKey(Schema.Int),stderr: Schema.optionalKey(Schema.String),cause: Schema.optional(Schema.Defect()),@@ -166,7 +167,11 @@ export class AcpProcessExitedError extends Schema.TaggedError<AcpProcessExitedEr) {override get message() {const base =- this.code === undefined ? "ACP process exited" : `ACP process exited with code ${this.code}`;+ this.signal !== undefined+ ? `ACP process exited after signal ${this.signal}`+ : this.code === undefined+ ? "ACP process exited"+ : `ACP process exited with code ${this.code}`;const excerpt = this.stderr?.trim();return excerpt && excerpt.length > 0 ? `${base}\n${excerpt}` : base;}diff --git a/packages/provider-acp/src/server/AcpSessionRuntime.ts b/packages/provider-acp/src/server/AcpSessionRuntime.tsindex 34201a35dbe..8914173a227 100644--- a/packages/provider-acp/src/server/AcpSessionRuntime.ts+++ b/packages/provider-acp/src/server/AcpSessionRuntime.ts@@ -1331,6 +1331,7 @@ export const make = Effect.fn("AcpSessionRuntime.make")(function* (? error: new EffectAcpErrors.AcpProcessExitedError({...(error.code !== undefined ? { code: error.code } : {}),+ ...(error.signal !== undefined ? { signal: error.signal } : {}),...(error.pid !== undefined ? { pid: error.pid } : {}),stderr,...(error.cause !== undefined ? { cause: error.cause } : {}),diff --git a/packages/provider-acp/src/server/stderr.test.ts b/packages/provider-acp/src/server/stderr.test.tsindex 5e5c42b63cd..1229a36c145 100644--- a/packages/provider-acp/src/server/stderr.test.ts+++ b/packages/provider-acp/src/server/stderr.test.ts@@ -17,6 +17,7 @@ describe("AcpStderr", () => {["Invalid project config at /Users/ada/.cursor/cli.json","Authorization: Bearer secret-token-value",+ "Sign in: https://accounts.google.com/o/oauth2/v2/auth?state=oauth-state-value","Visit http://localhost:5733/pair#token=ABCDEF for pairing","key=sk-abcdefghijklmnopqrstuv",].join("\n"),@@ -30,6 +31,8 @@ describe("AcpStderr", () => {expect(excerpt).toContain("[redacted]");expect(excerpt).not.toContain("secret-token-value");expect(excerpt).not.toContain("ABCDEF");+ expect(excerpt).toContain("[sign-in-url]");+ expect(excerpt).not.toContain("oauth-state-value");expect(excerpt).not.toContain("sk-abcdefghijklmnopqrstuv");});diff --git a/packages/provider-acp/src/server/stderr.ts b/packages/provider-acp/src/server/stderr.tsindex 5a3d486b2b8..ab11c12666a 100644--- a/packages/provider-acp/src/server/stderr.ts+++ b/packages/provider-acp/src/server/stderr.ts@@ -1,6 +1,7 @@export const ACP_STDERR_TAIL_MAX_CHARS = 4_096;const PAIRING_URL_PATTERN = /https?:\/\/[^\s]*\/pair#[^\s]*/gi;+const SIGN_IN_URL_PATTERN = /https?:\/\/accounts\.google\.com[^\s]*/gi;const BEARER_TOKEN_PATTERN = /\bBearer\s+[A-Za-z0-9._\-+=/]+/gi;const BASIC_AUTH_PATTERN = /\bAuthorization:\s*Basic\s+\S+/gi;const API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;@@ -26,6 +27,7 @@ export function sanitizeAcpStderrExcerpt(}result = result.replace(PAIRING_URL_PATTERN, "[pairing-url]")+ .replace(SIGN_IN_URL_PATTERN, "[sign-in-url]").replace(BEARER_TOKEN_PATTERN, "Bearer [redacted]").replace(BASIC_AUTH_PATTERN, "Authorization: Basic [redacted]").replace(API_KEY_HEADER_PATTERN, "x-api-key: [redacted]")