The best way to control Claude Code, Codex and more from any computer or phone
fix(server): ACP Registry Antigravity no longer leaves unpacked temp folders (#39028)
Julius Marminge committed
Nov 19, 2026 at 02:39 UTC
67692a75491618c2282d431b93d40f2e72b6b6b9
2 files changed
+131
-2
packages/provider-acp-registry/src/server/AcpRegistrySupport.test.ts
+49
@@ -792,6 +792,55 @@ describe("AcpRegistrySupport", () => {
792
);
793
});
794
795
+ it.effect("gives Antigravity a T3-owned temp directory that is removed with the process", () => {
796
+ const agent = {
797
+ ...makeAgent({ binary: { "linux-x86_64": { archive: archiveUrl, cmd: "./agy" } } }),
798
+ id: "antigravity-acp",
799
+ };
800
+ return Effect.gen(function* () {
801
+ const fileSystem = yield* FileSystem.FileSystem;
802
+ const cacheDir = yield* fileSystem.makeTempDirectoryScoped({
803
+ prefix: "t3-acp-registry-runtime-temp-",
804
+ });
805
+ const runtimeTempDir = `${cacheDir}/antigravity-tmp/acp-registry`;
806
+ yield* fileSystem.makeDirectory(`${runtimeTempDir}/run-killed/_MEI123`, { recursive: true });
807
+ const resolver = yield* AcpRegistrySupport.makeAcpRegistryCatalog({
808
+ cacheDir,
809
+ toolsDir: `${cacheDir}/tools`,
810
+ runtimeTempDir,
811
+ registryUrl,
812
+ });
813
+ expect(yield* fileSystem.exists(`${runtimeTempDir}/run-killed`)).toBe(false);
814
+
815
+ const temp = yield* Effect.scoped(
816
+ Effect.gen(function* () {
817
+ const resolved = yield* resolver.resolve(
818
+ settings({ agentId: "antigravity-acp" }),
819
+ "/workspace",
820
+ { TMPDIR: "/tmp" },
821
+ );
822
+ const directory = resolved.spawn.env?.TMPDIR ?? "";
823
+ expect(directory.startsWith(`${runtimeTempDir}/run-`)).toBe(true);
824
+ expect(yield* fileSystem.exists(directory)).toBe(true);
825
+ return directory;
826
+ }),
827
+ );
828
+ expect(yield* fileSystem.exists(temp)).toBe(false);
829
+ }).pipe(
830
+ Effect.scoped,
831
+ Effect.provide(
832
+ layerResolver((request) =>
833
+ Effect.succeed(
834
+ HttpClientResponse.fromWeb(
835
+ request,
836
+ new Response(request.url === registryUrl ? makeRegistry(agent) : "#!/bin/sh\n"),
837
+ ),
838
+ ),
839
+ ),
840
+ ),
841
+ );
842
+ });
843
+
844
it.effect("installs a contained binary whose name starts with two dots", () => {
845
const agent = makeAgent({
846
binary: { "linux-x86_64": { archive: archiveUrl, cmd: "..example-agent" } },
packages/provider-acp-registry/src/server/AcpRegistrySupport.ts
+82
-2
@@ -34,6 +34,8 @@ import * as Path from "effect/Path";
34
import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts";
35
import * as PlatformError from "effect/PlatformError";
36
import * as Ref from "effect/Ref";
37
+import * as Schedule from "effect/Schedule";
38
+import type * as Scope from "effect/Scope";
39
import * as Schema from "effect/Schema";
40
import * as Semaphore from "effect/Semaphore";
41
import * as Stream from "effect/Stream";
@@ -531,7 +533,7 @@ export class AcpRegistryCatalog extends Context.Service<
533
settings: AcpRegistrySettings,
534
cwd: string,
535
environment?: NodeJS.ProcessEnv,
534
- ) => Effect.Effect<ResolvedAcpRegistryAgent, AcpRegistryError>;
536
+ ) => Effect.Effect<ResolvedAcpRegistryAgent, AcpRegistryError, Scope.Scope>;
537
readonly uninstallManagedBinary: (
538
input: AcpRegistryManagedBinaryUninstallInput,
539
) => Effect.Effect<AcpRegistryManagedBinaryUninstallResult, AcpRegistryError>;
@@ -549,6 +551,8 @@ export const layerFromHost = Layer.merge(
551
return layer({
552
cacheDir: paths.providerStatusCacheDir,
553
toolsDir: path.join(paths.baseDir, "tools"),
554
+ // Beside the built-in driver's runtime temp, short for Windows' 260-character path limit.
555
+ runtimeTempDir: path.join(paths.stateDir, "antigravity-tmp", "acp-registry"),
556
});
557
}),
558
),
@@ -558,9 +562,14 @@ export const layerFromHost = Layer.merge(
562
export interface AcpRegistryCatalogOptions {
563
readonly cacheDir: string;
564
readonly toolsDir: string;
565
+ /** Owns the temp files of agents whose unpacker cannot clean up after a kill. */
566
+ readonly runtimeTempDir?: string;
567
readonly registryUrl?: string;
568
}
569
570
+// Unpacks about 140 MB into TEMP on every launch and cannot remove it when the process is killed.
571
+const UNPACKING_AGENT_IDS: ReadonlySet<string> = new Set(["antigravity-acp"]);
572
+
573
const INSTALL_LOCK_RETRY_COUNT = 300;
574
const INSTALL_LOCK_RETRY_DELAY = "100 millis";
575
const INSTALL_LOCK_STALE_MS = 5 * 60 * 1_000;
@@ -693,6 +702,73 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
702
};
703
const preparedBinaryReservations = yield* Ref.make<ReadonlyMap<string, number>>(new Map());
704
705
+ const runtimeTempDir = input.runtimeTempDir;
706
+ if (runtimeTempDir !== undefined) {
707
+ // Move leftovers of a previous server aside so the slow delete cannot race new runs.
708
+ const parent = path.dirname(runtimeTempDir);
709
+ const prefix = `${path.basename(runtimeTempDir)}.old-`;
710
+ const retire = Effect.gen(function* () {
711
+ if (yield* fileSystem.exists(runtimeTempDir)) {
712
+ yield* fileSystem.makeTempDirectory({ directory: parent, prefix }).pipe(
713
+ Effect.flatMap((retired) =>
714
+ fileSystem.rename(runtimeTempDir, path.join(retired, "runtime")),
715
+ ),
716
+ Effect.catch(() => fileSystem.remove(runtimeTempDir, { recursive: true, force: true })),
717
+ );
718
+ }
719
+ return yield* fileSystem.readDirectory(parent);
720
+ }).pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []));
721
+ const retired = (yield* retire).filter((entry) => entry.startsWith(prefix));
722
+ yield* Effect.forkDetach(
723
+ Effect.forEach(
724
+ retired,
725
+ (entry) =>
726
+ fileSystem
727
+ .remove(path.join(parent, entry), { recursive: true, force: true })
728
+ .pipe(
729
+ Effect.catch(() =>
730
+ Effect.logWarning("Could not remove leftover ACP agent temp files."),
731
+ ),
732
+ ),
733
+ { discard: true },
734
+ ),
735
+ );
736
+ }
737
+
738
+ // One directory per process, removed after it exits; the next server start sweeps what Windows kept.
739
+ const acquireRuntimeTempEnvironment = Effect.fn("AcpRegistryCatalog.acquireRuntimeTemp")(
740
+ function* (root: string, environment: NodeJS.ProcessEnv) {
741
+ const directory = yield* Effect.acquireRelease(
742
+ fileSystem.makeDirectory(root, { recursive: true }).pipe(
743
+ Effect.andThen(fileSystem.makeTempDirectory({ directory: root, prefix: "run-" })),
744
+ Effect.mapError(
745
+ (cause) =>
746
+ new AcpRegistryError({
747
+ reason: "install_failed",
748
+ detail: "Could not create a temp directory for the ACP agent.",
749
+ cause,
750
+ }),
751
+ ),
752
+ ),
753
+ (directory) => {
754
+ const remove = fileSystem.remove(directory, { recursive: true, force: true });
755
+ // Windows keeps a killed process's files locked for a few seconds after it exits.
756
+ const retry = remove.pipe(
757
+ Effect.retry({ schedule: Schedule.spaced("2 seconds"), times: 30 }),
758
+ Effect.catch(() => Effect.logWarning("Could not remove an ACP agent temp directory.")),
759
+ );
760
+ return remove.pipe(Effect.catch(() => Effect.asVoid(Effect.forkDetach(retry))));
761
+ },
762
+ );
763
+ if (platform !== "win32") return { ...environment, TMPDIR: directory };
764
+ // Windows env keys are case-insensitive; drop aliases so ours win.
765
+ const rest = Object.fromEntries(
766
+ Object.entries(environment).filter(([key]) => !["temp", "tmp"].includes(key.toLowerCase())),
767
+ );
768
+ return { ...rest, TEMP: directory, TMP: directory };
769
+ },
770
+ );
771
+
772
const managerBinDirectory = Effect.fn("AcpRegistryCatalog.managerBinDirectory")(function* (
773
runner: string,
774
) {
@@ -1938,10 +2014,14 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
2014
...effectiveEnvironment,
2015
...distribution.env,
2016
};
1941
- const spawnEnvironment =
2017
+ const pathEnvironment =
2018
commandBinDirectory === undefined
2019
? baseSpawnEnvironment
2020
: withPreferredPath(baseSpawnEnvironment, commandBinDirectory, platform);
2021
+ const spawnEnvironment =
2022
+ runtimeTempDir !== undefined && UNPACKING_AGENT_IDS.has(agent.id)
2023
+ ? yield* acquireRuntimeTempEnvironment(runtimeTempDir, pathEnvironment)
2024
+ : pathEnvironment;
2025
2026
return {
2027
agent,