Skip to content

Commit a24b5a9

Browse files
committed
fix(antigravity): avoid spawning process on probe and isolate temp directory
1 parent df7ccc8 commit a24b5a9

5 files changed

Lines changed: 162 additions & 22 deletions

File tree

‎apps/server/src/provider/Drivers/AntigravityDriver.test.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function shellQuote(value: string): string {
5858
}
5959

6060
const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
61-
options: { readonly config?: Partial<AntigravitySettings> } = {},
61+
options: { readonly config?: Partial<AntigravitySettings>; readonly enabled?: boolean } = {},
6262
) {
6363
const fs = yield* FileSystem.FileSystem;
6464
const path = yield* Path.Path;
@@ -129,6 +129,16 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
129129

130130
const installation = Layer.mock(AntigravityInstallation)({
131131
managedDirectory: root,
132+
resolve: (binaryPath, environment) =>
133+
Effect.gen(function* () {
134+
if (controls.failResolution) {
135+
return yield* new AntigravityInstallationError({
136+
operation: "resolve",
137+
detail: "Fixture resolution failed.",
138+
});
139+
}
140+
return controls.selected;
141+
}),
132142
acquire: (binaryPath, environment) =>
133143
Effect.gen(function* () {
134144
acquisitions.push({ binaryPath, path: environment?.PATH });
@@ -174,7 +184,7 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
174184
const instance = yield* AntigravityDriver.create({
175185
instanceId,
176186
displayName: "Google test account",
177-
enabled: false,
187+
enabled: options.enabled ?? false,
178188
config: { ...AntigravityDriver.defaultConfig(), ...options.config },
179189
environment: [
180190
{ name: "PATH", value: instancePath },
@@ -435,4 +445,15 @@ it.layer(testLayer)("AntigravityDriver", (it) => {
435445
yield* h.assertClosed;
436446
}).pipe(Effect.scoped),
437447
);
448+
449+
it.effect("probes through installation resolution without launching a process", () =>
450+
Effect.gen(function* () {
451+
const h = yield* makeHarness({ enabled: true });
452+
const snapshot = yield* h.instance.snapshot.refresh;
453+
expect(snapshot.installed).toBe(true);
454+
expect(snapshot.version).toBe(h.first.version);
455+
expect(h.launches).toEqual([]);
456+
expect(h.acquisitions).toEqual([]);
457+
}).pipe(Effect.scoped),
458+
);
438459
});

‎apps/server/src/provider/Drivers/AntigravityDriver.ts‎

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ import {
3838
} from "../acp/AntigravityAcpSupport.ts";
3939
import type { AcpSessionRuntime, AcpSessionRuntimeStartResult } from "../acp/AcpSessionRuntime.ts";
4040
import type { ServerProviderDraft } from "../providerSnapshot.ts";
41-
import { removeAntigravitySessionFiles } from "../acp/AntigravitySessionFiles.ts";
41+
import {
42+
cleanOrphanedAntigravityTempDirs,
43+
removeAntigravitySessionFiles,
44+
} from "../acp/AntigravitySessionFiles.ts";
4245
import { ProviderDriverError } from "../Errors.ts";
4346
import { makeAntigravityAdapter } from "../Layers/AntigravityAdapter.ts";
4447
import { makeAntigravityProvider } from "../Layers/AntigravityProvider.ts";
@@ -98,6 +101,11 @@ export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityD
98101
serverConfig.stateDir,
99102
instanceId,
100103
);
104+
yield* cleanOrphanedAntigravityTempDirs(profileDirectory).pipe(
105+
Effect.provideService(FileSystem.FileSystem, fileSystem),
106+
Effect.provideService(Path.Path, path),
107+
Effect.ignore,
108+
);
101109
const continuationIdentity = defaultProviderContinuationIdentity({
102110
driverKind: DRIVER,
103111
instanceId,
@@ -258,24 +266,47 @@ export const AntigravityDriver: ProviderDriver<AntigravitySettings, AntigravityD
258266
// Kick the TTL-gated manifest refresh alongside the health check, as
259267
// Codex and Claude do. Without it an environment that only runs
260268
// Antigravity would keep classifying against a stale disk cache.
269+
// Antigravity's binary is a PyInstaller single-file bundle. Spawning it
270+
// extracts ~860 MB of files to a temporary directory on every run.
271+
// The health probe only needs to verify that the executable and harness
272+
// exist on disk and resolve the installed version; actual ACP sessions
273+
// and explicit model refreshes spawn the runtime when needed.
261274
const probe = Effect.gen(function* () {
262275
yield* modelManifest.refreshInBackground;
263-
const processScope = yield* Scope.make();
264-
yield* Effect.addFinalizer((exit) => Scope.close(processScope, exit));
265-
return yield* authFlow
266-
.withProcess(
267-
Scope.close(processScope, Exit.void),
268-
Effect.gen(function* () {
269-
const runtime = yield* makeRuntime({
270-
cwd: serverConfig.stateDir,
271-
clientInfo: { name: "t3-code-provider-probe", version: "0.0.0" },
272-
mcpServers: [],
273-
});
274-
return yield* runtime.initialize();
275-
}),
276-
)
277-
.pipe(Effect.provideService(Scope.Scope, processScope));
278-
}).pipe(Effect.scoped);
276+
if (authConfigIssue !== null) {
277+
return yield* new ProviderSetupError({
278+
instanceId,
279+
operation: "configure",
280+
detail: authConfigIssue,
281+
});
282+
}
283+
const executable = yield* installation
284+
.resolve(settings.binaryPath, processEnvironment)
285+
.pipe(
286+
Effect.mapError(
287+
(cause) =>
288+
new ProviderSetupError({
289+
instanceId,
290+
operation: "resolve",
291+
detail: cause.detail,
292+
}),
293+
),
294+
);
295+
return {
296+
protocolVersion: 1,
297+
agentCapabilities: {
298+
loadSession: true,
299+
promptCapabilities: { image: true, audio: true, embeddedContext: true },
300+
sessionCapabilities: { list: {}, resume: {} },
301+
},
302+
authMethods: [{ id: "oauth-personal", name: "Log in with Google" }],
303+
agentInfo: {
304+
name: "antigravity-acp",
305+
title: "Google Antigravity",
306+
version: executable.version ?? "unknown",
307+
},
308+
};
309+
});
279310

280311
const provider = yield* makeAntigravityProvider(settings, {
281312
stampIdentity: classifyModels,

‎apps/server/src/provider/acp/AntigravitySessionFiles.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,64 @@ export const removeAntigravitySessionFiles = Effect.fn("removeAntigravitySession
3838
recursive: true,
3939
force: true,
4040
});
41+
42+
// Best-effort cleanup of any unlocked temporary unpack directories left by PyInstaller
43+
const tmpDirectory = path.join(acpDirectory, "tmp");
44+
if (yield* fs.exists(tmpDirectory)) {
45+
const entries = yield* fs.readDirectory(tmpDirectory).pipe(Effect.orElseSucceed(() => []));
46+
for (const entry of entries) {
47+
if (entry.startsWith("_MEI")) {
48+
yield* fs
49+
.remove(path.join(tmpDirectory, entry), { recursive: true, force: true })
50+
.pipe(Effect.ignore);
51+
}
52+
}
53+
}
4154
},
4255
Effect.catch(() => Effect.logWarning("Could not remove temporary Antigravity session files.")),
4356
);
57+
58+
/** Sweeps orphaned PyInstaller unpack directories from prior runs. */
59+
export const cleanOrphanedAntigravityTempDirs = Effect.fn("cleanOrphanedAntigravityTempDirs")(
60+
function* (profileDirectory?: string) {
61+
const fs = yield* FileSystem.FileSystem;
62+
const path = yield* Path.Path;
63+
64+
// 1. Clean profile-isolated tmp directory if provided
65+
if (profileDirectory) {
66+
const acpTmp = path.join(profileDirectory, "antigravity-acp", "tmp");
67+
if (yield* fs.exists(acpTmp)) {
68+
const entries = yield* fs.readDirectory(acpTmp).pipe(Effect.orElseSucceed(() => []));
69+
for (const entry of entries) {
70+
if (entry.startsWith("_MEI")) {
71+
yield* fs
72+
.remove(path.join(acpTmp, entry), { recursive: true, force: true })
73+
.pipe(Effect.ignore);
74+
}
75+
}
76+
}
77+
}
78+
79+
// 2. Clean orphaned _MEI folders in system temp directory left by previous Antigravity probes
80+
const systemTemp = process.env.TEMP || process.env.TMP;
81+
if (systemTemp && (yield* fs.exists(systemTemp))) {
82+
const entries = yield* fs.readDirectory(systemTemp).pipe(Effect.orElseSucceed(() => []));
83+
for (const entry of entries) {
84+
if (entry.startsWith("_MEI")) {
85+
const fullPath = path.join(systemTemp, entry);
86+
const hasGoogle3 = yield* fs
87+
.exists(path.join(fullPath, "google3"))
88+
.pipe(Effect.orElseSucceed(() => false));
89+
const hasGoogle =
90+
hasGoogle3 ||
91+
(yield* fs
92+
.exists(path.join(fullPath, "google"))
93+
.pipe(Effect.orElseSucceed(() => false)));
94+
if (hasGoogle) {
95+
yield* fs.remove(fullPath, { recursive: true, force: true }).pipe(Effect.ignore);
96+
}
97+
}
98+
}
99+
}
100+
},
101+
);

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,29 @@ describe("Antigravity process environment", () => {
187187
).toBeNull();
188188
});
189189

190+
it("isolates TEMP and TMP to the profile directory on Windows", () => {
191+
const windowsProfile: AntigravityProfile = {
192+
platform: "win32",
193+
geminiHome: "C:\\state\\providers\\antigravity\\profile",
194+
acpDirectory: "C:\\state\\providers\\antigravity\\profile\\antigravity-acp",
195+
tokenPath: "C:\\state\\providers\\antigravity\\profile\\antigravity-acp\\acp_token.json",
196+
browserCommand: "managed-browser-helper",
197+
};
198+
const spawn = buildAntigravityAcpSpawnInput({
199+
installation: {
200+
executablePath: "C:\\release\\agy_acp_server.exe",
201+
harnessPath: "C:\\release\\localharness_external.exe",
202+
},
203+
profile: windowsProfile,
204+
cwd: "C:\\project",
205+
baseEnv: { PATH: "C:\\Windows\\system32", TEMP: "C:\\Users\\user\\AppData\\Local\\Temp" },
206+
});
207+
expect(spawn.env?.TEMP).toBe(
208+
"C:\\state\\providers\\antigravity\\profile\\antigravity-acp\\tmp",
209+
);
210+
expect(spawn.env?.TMP).toBe("C:\\state\\providers\\antigravity\\profile\\antigravity-acp\\tmp");
211+
});
212+
190213
it("uses the registry launch arguments for each supported host platform", () => {
191214
for (const platform of ["linux", "darwin", "win32"] as const) {
192215
const spawn = buildAntigravityAcpSpawnInput({

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ function antigravityEnvironment(
214214
: auth.authMethod === "agent-platform" && auth.apiKey
215215
? { GOOGLE_API_KEY: auth.apiKey }
216216
: {};
217+
const tempDirectory = NodePath.join(profile.acpDirectory, "tmp");
217218
return {
218219
...environment,
219220
...credential,
@@ -222,6 +223,12 @@ function antigravityEnvironment(
222223
BROWSER: profile.browserCommand,
223224
PYTHONUNBUFFERED: "1",
224225
ELECTRON_RUN_AS_NODE: "1",
226+
...(profile.platform === "win32"
227+
? {
228+
TEMP: tempDirectory,
229+
TMP: tempDirectory,
230+
}
231+
: {}),
225232
};
226233
}
227234

@@ -301,8 +308,7 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(
301308
browserCommand.includes(platform === "win32" ? ";" : ":") ||
302309
helperExecutable.includes("\r") ||
303310
helperExecutable.includes("\n") ||
304-
helperExecutable.includes("\0") ||
305-
helperExecutable.includes("%s")
311+
helperExecutable.includes("\0")
306312
) {
307313
return yield* authSupportError(
308314
"The T3 runtime path cannot be used to suppress Antigravity browser launches.",
@@ -311,6 +317,7 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(
311317

312318
const geminiHome = path.resolve(input.profileDirectory);
313319
const acpDirectory = path.join(geminiHome, "antigravity-acp");
320+
const tempDirectory = path.join(acpDirectory, "tmp");
314321
const profile: AntigravityProfile = {
315322
platform,
316323
geminiHome,
@@ -358,7 +365,7 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(
358365
),
359366
);
360367

361-
for (const directory of [geminiHome, acpDirectory]) {
368+
for (const directory of [geminiHome, acpDirectory, tempDirectory]) {
362369
yield* fs
363370
.makeDirectory(directory, { recursive: true, mode: 0o700 })
364371
.pipe(

0 commit comments

Comments
 (0)