Skip to content

Commit 8107844

Browse files
fix(antigravity): validate in a fixed temp root that the next run sweeps
Validation unpacked into a root named after its random profile, so a removal that failed (a scanner holding a handle after the kill) left about 1 GB nothing would reclaim. Use one short root per install directory, cleared before and after each run; installs run one at a time. Also update the sweep's comment now that Windows roots live in the system temp directory. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent b6a56a4 commit 8107844

4 files changed

Lines changed: 47 additions & 16 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,11 @@ it.layer(NodeServices.layer)("Antigravity installation", (it) => {
419419
});
420420
}),
421421
);
422+
const path = yield* Path.Path;
422423
const systemTemp = yield* fs.makeTempDirectoryScoped({ prefix: "t3-agy-validate-temp-" });
424+
// A previous validation whose cleanup failed left an unpacked runtime
425+
// in the fixed validation root; an unrelated T3 root must survive.
426+
const unrelated = path.join(systemTemp, "t3-agy", "0123456789ab");
423427
const { installation, stagingReleased } = yield* makeHarness({
424428
previous: true,
425429
useDefaultValidation: true,
@@ -430,6 +434,11 @@ it.layer(NodeServices.layer)("Antigravity installation", (it) => {
430434
// Windows unpacks outside the profile, so its removal is not implied.
431435
Effect.provideService(HostProcessTempDirectory, systemTemp),
432436
);
437+
const validationRoot = (yield* fs
438+
.readDirectory(path.join(systemTemp, "t3-agy"))
439+
.pipe(Effect.orElseSucceed(() => [] as Array<string>))).length;
440+
expect(validationRoot).toBe(0);
441+
yield* fs.makeDirectory(unrelated, { recursive: true });
433442
yield* installation.start;
434443
expect((yield* terminalState(installation)).phase).toBe(
435444
testCase.valid ? "succeeded" : "failed",
@@ -439,9 +448,20 @@ it.layer(NodeServices.layer)("Antigravity installation", (it) => {
439448
expect(closedRuntimes).toBe(1);
440449
expect(profiles.size).toBe(1);
441450
expect(runtimeTempDirectories.size).toBe(1);
451+
const [runtimeTemp] = runtimeTempDirectories;
452+
// Validation unpacks under a fixed, short root the next run can sweep.
453+
expect(path.dirname(runtimeTemp!)).toBe(path.join(systemTemp, "t3-agy"));
442454
for (const directory of [...profiles, ...runtimeTempDirectories]) {
443455
expect(yield* fs.exists(directory)).toBe(false);
444456
}
457+
expect(yield* fs.exists(unrelated)).toBe(true);
458+
459+
// A run whose cleanup failed is reclaimed before the next validation.
460+
yield* fs.makeDirectory(path.join(runtimeTemp!, "_MEI000012ab2"), { recursive: true });
461+
yield* installation.start;
462+
yield* terminalState(installation);
463+
expect(yield* fs.exists(path.join(runtimeTemp!, "_MEI000012ab2"))).toBe(false);
464+
expect([...runtimeTempDirectories]).toEqual([runtimeTemp]);
445465
if (testCase.valid) {
446466
expect((yield* installation.resolve()).version).toBe("fixture-new");
447467
} else {

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
HostProcessArchitecture,
66
HostProcessEnvironment,
77
HostProcessPlatform,
8+
HostProcessTempDirectory,
89
} from "@t3tools/shared/hostProcess";
910
import { resolveNodeExecutable, nodeRuntimeUnavailableMessage } from "@t3tools/shared/nodeRuntime";
1011
import * as Clock from "effect/Clock";
@@ -287,6 +288,12 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
287288
`${platform}-${arch}`,
288289
);
289290
const versionsDirectory = path.join(managedDirectory, "versions");
291+
const systemTempDirectory = yield* HostProcessTempDirectory;
292+
// Servers with different homes validate in parallel without sharing a root.
293+
const validationTempName = `validate-${NodeCrypto.createHash("sha256")
294+
.update(managedDirectory)
295+
.digest("hex")
296+
.slice(0, 12)}`;
290297
const activePath = path.join(managedDirectory, "active.json");
291298
const gate = yield* Semaphore.make(1);
292299
const leases = new Map<string, number>();
@@ -472,16 +479,20 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
472479
const profileDirectory = yield* fs.makeTempDirectoryScoped({
473480
prefix: "t3-antigravity-validate-",
474481
});
482+
// Short enough for Windows' path limit, and fixed per install root so
483+
// a removal that fails here is swept by the next validation.
484+
const tempDirectory = path.join(systemTempDirectory, "t3-agy", validationTempName);
485+
const removeTemp = fs
486+
.remove(tempDirectory, { recursive: true, force: true })
487+
.pipe(Effect.ignore);
488+
yield* removeTemp;
489+
yield* Effect.addFinalizer(() => removeTemp);
475490
const profile = yield* prepareAntigravityProfile({
476491
profileDirectory,
477492
platform,
478493
baseEnv: environment,
494+
tempDirectory,
479495
});
480-
// Windows keeps runtime temp outside the profile. Remove it after the
481-
// process exits; this profile, and so its temp directory, is unique.
482-
yield* Effect.addFinalizer(() =>
483-
fs.remove(profile.tempDirectory, { recursive: true, force: true }).pipe(Effect.ignore),
484-
);
485496
const runtime = yield* makeAntigravityAcpRuntime({
486497
spawn: buildAntigravityAcpSpawnInput({
487498
installation: executable,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ export const removeAntigravitySessionFiles = Effect.fn("removeAntigravitySession
4343
);
4444

4545
/**
46-
* Removes every per-process runtime temp directory under the profile. Call
47-
* once when the driver starts, before it launches any process, so a previous
48-
* server that was killed mid-session cannot leave unpacked runtimes behind.
49-
* Only the profile-owned directory is touched. The system temp directory
50-
* belongs to other programs and Windows does not lock data files, so sweeping
51-
* it could gut a live extraction.
46+
* Removes an instance's runtime temp root and every per-process directory in
47+
* it. Call once when the driver starts, before it launches any process, so a
48+
* previous server that was killed mid-session cannot leave unpacked runtimes
49+
* behind. Only T3-owned roots are passed here. Other programs' entries in the
50+
* system temp directory are never listed, since Windows does not lock data
51+
* files and sweeping them could gut a live extraction.
5252
*/
5353
export const removeAntigravityRuntimeTempDirs = Effect.fn("removeAntigravityRuntimeTempDirs")(
5454
function* (tempDirectory: string) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(
312312
readonly auth?: AntigravityAuthConfig;
313313
/** Home the agent expands `~` against. Defaults to the launch environment's. */
314314
readonly userHome?: string;
315+
/** Parent of per-process temp directories. Defaults to the instance's root. */
316+
readonly tempDirectory?: string;
315317
}) {
316318
const auth = input.auth ?? ANTIGRAVITY_PERSONAL_AUTH;
317319
const fs = yield* FileSystem.FileSystem;
@@ -349,11 +351,9 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(
349351

350352
const geminiHome = path.resolve(input.profileDirectory);
351353
const acpDirectory = path.join(geminiHome, "antigravity-acp");
352-
const tempDirectory = resolveAntigravityRuntimeTempDirectory(
353-
geminiHome,
354-
platform,
355-
yield* HostProcessTempDirectory,
356-
);
354+
const tempDirectory =
355+
input.tempDirectory ??
356+
resolveAntigravityRuntimeTempDirectory(geminiHome, platform, yield* HostProcessTempDirectory);
357357
const profile: AntigravityProfile = {
358358
platform,
359359
geminiHome,

0 commit comments

Comments
 (0)