The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
fix(server): managed Antigravity and Codex runtimes prune old versions (#38740)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 18, 2026 at 13:14 UTC
68ea2220c12cef2fad673d87d731c828e73a6e4d
4 files changed
+65
-8
apps/server/src/provider/AntigravityInstallation.test.ts
+5
-2
@@ -595,7 +595,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
595
expect(yield* fs.readFileString(selected.executablePath)).toBe(serverContents);
596
expect(yield* fs.readFileString(selected.harnessPath!)).toBe(harnessContents);
597
expect(yield* fs.readDirectory(path.join(installation.managedDirectory, "versions"))).toEqual(
598
- expect.arrayContaining([previousReleaseId, (yield* releaseAsset()).sha256]),
598
+ [(yield* releaseAsset()).sha256],
599
);
600
expect(requests).toEqual([(yield* releaseAsset()).url]);
601
}),
@@ -1217,7 +1217,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
1217
Effect.gen(function* () {
1218
const manifestEntered = yield* Deferred.make<void>();
1219
const releaseManifest = yield* Deferred.make<void>();
1220
- const { installation, fs, stagingReleased } = yield* makeHarness({
1220
+ const { installation, fs, baseDir, stagingReleased } = yield* makeHarness({
1221
native: true,
1222
platform: "win32",
1223
archive: Buffer.from(serverContents),
@@ -1242,6 +1242,9 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
1242
expect(yield* fs.readFileString(oldExecutable.executablePath)).toBe(serverContents);
1243
expect(yield* installation.remove().pipe(Effect.flip)).toMatchObject({ operation: "remove" });
1244
yield* Scope.close(processScope, Exit.void);
1245
+ yield* makeHarness({ native: true, platform: "win32", baseDir });
1246
+ expect(yield* fs.exists(oldExecutable.managedVersionDirectory!)).toBe(false);
1247
+ expect(yield* fs.readFileString(current.executablePath)).toBe(serverContents);
1248
yield* installation.remove();
1249
expect(yield* fs.exists(installation.managedDirectory)).toBe(false);
1250
}),
apps/server/src/provider/AntigravityInstallation.ts
+20
@@ -540,6 +540,22 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
540
}),
541
);
542
543
+ // Each update lands in its own directory. Best effort: a busy gate means a session is
544
+ // resolving, so the next start or update finishes the cleanup.
545
+ const pruneInactiveReleases = Effect.gen(function* () {
546
+ const active = yield* readRecord(activePath, ActiveRelease);
547
+ for (const entry of yield* fs.readDirectory(versionsDirectory)) {
548
+ if (entry === active.releaseId || !/^[a-f0-9]{64}$/u.test(entry)) continue;
549
+ const directory = path.join(versionsDirectory, entry);
550
+ if (leases.has(directory)) continue;
551
+ yield* fs.remove(directory, { recursive: true, force: true }).pipe(Effect.ignore);
552
+ }
553
+ }).pipe(
554
+ gate.withPermitsIfAvailable(1),
555
+ Effect.ignore,
556
+ Effect.withSpan("AntigravityInstallation.pruneInactiveReleases"),
557
+ );
558
+
559
const install = Effect.fn("AntigravityInstallation.install")(
560
function* (asset: AntigravityReleaseAsset | AntigravityCliReleaseAsset) {
561
yield* ensureEligible(asset.version);
@@ -585,6 +601,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
601
mode: 0o600,
602
});
603
yield* fs.rename(pointerPath, activePath);
604
+ yield* pruneInactiveReleases;
605
yield* SubscriptionRef.update(
606
state,
607
(current) =>
@@ -1170,6 +1187,9 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
1187
),
1188
);
1189
1190
+ // A startup install prunes when it activates; pruning now could delete the release it is verifying.
1191
+ if (!isRunning(yield* SubscriptionRef.get(state))) yield* pruneInactiveReleases;
1192
+
1193
return AntigravityInstallation.of({
1194
managedDirectory,
1195
resolve,
apps/server/src/provider/CodexInstallation.test.ts
+6
@@ -629,6 +629,8 @@ it.effect("updates a managed install to OpenAI's newest release and never downgr
629
version: upstreamVersion,
630
});
631
632
+ const sessionScope = yield* Scope.make();
633
+ const previous = yield* h.installation.acquire().pipe(Scope.provide(sessionScope));
634
yield* h.installation.start;
635
expect(yield* terminalState(h.installation)).toMatchObject({
636
phase: "succeeded",
@@ -636,9 +638,13 @@ it.effect("updates a managed install to OpenAI's newest release and never downgr
638
version: upstreamVersion,
639
});
640
expect((yield* h.installation.resolve()).version).toBe(upstreamVersion);
641
+ // The running session keeps its release until the next start prunes it.
642
+ expect(yield* h.fs.exists(previous.managedVersionDirectory!)).toBe(true);
643
+ yield* Scope.close(sessionScope, Exit.void);
644
645
// Without upstream information the older pin is not offered as a reinstall.
646
const restarted = yield* makeHarness({ baseDir: h.baseDir });
647
+ expect(yield* h.fs.exists(previous.managedVersionDirectory!)).toBe(false);
648
expect(yield* restarted.installation.state).toMatchObject({
649
installedVersion: upstreamVersion,
650
version: upstreamVersion,
apps/server/src/provider/CodexInstallation.ts
+34
-6
@@ -201,7 +201,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
201
const executableName = platform === "win32" ? "codex.exe" : "codex";
202
const gate = yield* Semaphore.make(1);
203
const updateCheckGate = yield* Semaphore.make(1);
204
- let leases = 0;
204
+ const leases = new Map<string, number>();
205
let running: { readonly operationId: string; readonly fiber: Fiber.Fiber<void> } | undefined;
206
let upstream: CodexReleaseAsset | null = null;
207
let upstreamCheckedAt: number | null = null;
@@ -393,16 +393,20 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
393
return yield* Effect.acquireRelease(
394
gate.withPermit(
395
resolve().pipe(
396
- Effect.tap(() =>
396
+ Effect.tap((executable) =>
397
Effect.sync(() => {
398
- leases += 1;
398
+ const key = executable.managedVersionDirectory ?? executable.executablePath;
399
+ leases.set(key, (leases.get(key) ?? 0) + 1);
400
}),
401
),
402
),
403
),
403
- () =>
404
+ (executable) =>
405
Effect.sync(() => {
405
- leases -= 1;
406
+ const key = executable.managedVersionDirectory ?? executable.executablePath;
407
+ const remaining = (leases.get(key) ?? 1) - 1;
408
+ if (remaining > 0) leases.set(key, remaining);
409
+ else leases.delete(key);
410
}),
411
);
412
});
@@ -566,6 +570,26 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
570
},
571
Effect.mapError(wrapFailure("verify", "The downloaded Codex runtime could not start.")),
572
);
573
+ // Each update lands in its own directory. Best effort: a busy gate means a session is
574
+ // resolving, so the next start or update finishes the cleanup.
575
+ const pruneInactiveReleases = Effect.gen(function* () {
576
+ const active = yield* readRecord(activePath, ActiveRelease);
577
+ for (const entry of yield* fs.readDirectory(managedDirectory)) {
578
+ if (
579
+ entry === active.version ||
580
+ Option.isNone(yield* decodeVersion(entry).pipe(Effect.option))
581
+ )
582
+ continue;
583
+ const directory = path.join(managedDirectory, entry);
584
+ if (leases.has(directory)) continue;
585
+ yield* fs.remove(directory, { recursive: true, force: true }).pipe(Effect.ignore);
586
+ }
587
+ }).pipe(
588
+ gate.withPermitsIfAvailable(1),
589
+ Effect.ignore,
590
+ Effect.withSpan("CodexInstallation.pruneInactiveReleases"),
591
+ );
592
+
593
const install = Effect.fn("CodexInstallation.install")(
594
function* (release: CodexReleaseAsset) {
595
const ensureEligible = Effect.fn("CodexInstallation.ensureEligible")(function* () {
@@ -594,6 +618,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
618
});
619
yield* ensureEligible();
620
yield* fs.rename(pointer, activePath);
621
+ yield* pruneInactiveReleases;
622
yield* SubscriptionRef.update(
623
state,
624
(current) =>
@@ -872,7 +897,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
897
function* (protectedBinaryPaths: ReadonlyArray<string> = []) {
898
yield* gate.withPermit(
899
Effect.gen(function* () {
875
- if (isRunning(yield* SubscriptionRef.get(state)) || leases > 0) {
900
+ if (isRunning(yield* SubscriptionRef.get(state)) || leases.size > 0) {
901
return yield* installationError(
902
"remove",
903
"Stop Codex sessions and sign-in flows before removing its managed runtime.",
@@ -977,6 +1002,9 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
1002
),
1003
);
1004
1005
+ // A startup install prunes when it activates; pruning now could delete the release it is verifying.
1006
+ if (!isRunning(yield* SubscriptionRef.get(state))) yield* pruneInactiveReleases;
1007
+
1008
return CodexInstallation.of({
1009
managedDirectory,
1010
resolve,