@devries-cameron20 / t3code-1 / commits / 315b06c5ec
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(providers): managed Antigravity and Codex installs can update past their pin (#21249)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Yash Singh <saiansh2525@gmail.com>

Wout Stiens committed Nov 12, 2026 at 19:03 UTC 315b06c5ecf6587acf53baa0a5691579e04c3f8c
11 files changed +1028 -99
apps/server/src/provider/AntigravityInstallation.test.ts
+230 -1
@@ -17,12 +17,16 @@ import * as Schema from "effect/Schema";
17 import * as Scope from "effect/Scope";
18 import * as Sink from "effect/Sink";
19 import * as Stream from "effect/Stream";
20 +import * as TestClock from "effect/testing/TestClock";
21 import { HttpClient, HttpClientError, HttpClientResponse } from "effect/http";
22 import * as ChildProcess from "effect/process/ChildProcess";
23 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
24
25 +import { ACP_REGISTRY_URL } from "@t3tools/provider-acp-registry/server/AcpRegistrySupport";
26 +
27 import * as AntigravityInstallation from "./AntigravityInstallation.ts";
28 import { type AntigravityReleaseAsset } from "./antigravityRelease.ts";
29 +import * as ModelManifest from "./ModelManifest.ts";
30
31 const serverContents = "antigravity runtime\n";
32 const harnessContents = "local harness\n";
@@ -126,6 +130,11 @@ interface HarnessOptions {
130 readonly spawner?: ChildProcessSpawner.ChildProcessSpawner["Service"];
131 readonly validate?: AntigravityInstallation.AntigravityInstallationOptions["validate"];
132 readonly useDefaultValidation?: boolean;
133 + /** Served for the ACP Registry index. */
134 + readonly registry?: unknown;
135 + /** Served by URL instead of the pinned archive. */
136 + readonly archives?: Readonly<Record<string, Uint8Array>>;
137 + readonly manifest?: Effect.Effect<ModelManifest.ModelManifestData>;
138 readonly connectTimeout?: boolean;
139 }
140
@@ -186,11 +195,31 @@ const makeHarness = Effect.fn("test.makeAntigravityInstallation")(function* (
195 Effect.provideService(HostProcess.Platform, platform),
196 Effect.provideService(HostProcess.Architecture, arch),
197 Effect.provideService(HostProcess.Environment, { PATH: options.path ?? "" }),
198 + Effect.provideService(ModelManifest.ModelManifest, {
199 + current: options.manifest ?? Effect.succeed(ModelManifest.BUNDLED_MODEL_MANIFEST),
200 + refresh: Effect.succeed(ModelManifest.BUNDLED_MODEL_MANIFEST),
201 + forceRefresh: Effect.succeed(ModelManifest.BUNDLED_MODEL_MANIFEST),
202 + refreshOnDemand: Effect.succeed(ModelManifest.BUNDLED_MODEL_MANIFEST),
203 + refreshInBackground: Effect.void,
204 + }),
205 Effect.provideService(
206 HttpClient.HttpClient,
207 HttpClient.make((request) =>
208 Effect.suspend(() => {
209 requests.push(request.url);
210 + if (request.url === ACP_REGISTRY_URL) {
211 + return Effect.succeed(
212 + HttpClientResponse.fromWeb(
213 + request,
214 + options.registry === undefined
215 + ? new Response(null, { status: 503 })
216 + : Response.json(options.registry),
217 + ),
218 + );
219 + }
220 + const served = options.archives?.[request.url];
221 + if (served)
222 + return Effect.succeed(HttpClientResponse.fromWeb(request, new Response(served)));
223 if (options.connectTimeout) {
224 return Effect.fail(
225 new HttpClientError.HttpClientError({
@@ -254,6 +283,43 @@ const expectPreviousRelease = Effect.fn("test.expectPreviousAntigravityRelease")
283 expect((yield* installation.state).installedVersion).toBe(previousVersion);
284 });
285
286 +// A zip comment changes the archive's hash without changing its members.
287 +const withZipComment = (archive: Buffer, comment: string) => {
288 + const bytes = Buffer.concat([archive, Buffer.from(comment)]);
289 + bytes.writeUInt16LE(Buffer.byteLength(comment), archive.byteLength - 2);
290 + return bytes;
291 +};
292 +const upstreamArchive = withZipComment(completeArchive, "upstream");
293 +const upstreamUrl = "https://dl.google.com/agy-extensions/releases/test/agy-acp-server-1.4.1.zip";
294 +const registryListing = (archive = upstreamUrl) => ({
295 + version: "1.0.0",
296 + agents: [
297 + { id: "other-agent", version: "9.9.9", distribution: { npx: { package: "other" } } },
298 + {
299 + id: "antigravity-acp",
300 + version: "1.4.1",
301 + distribution: {
302 + binary: Object.fromEntries(
303 + ["linux-x86_64", "windows-x86_64"].map((target) => [target, { archive, cmd: "./agy" }]),
304 + ),
305 + },
306 + },
307 + ],
308 +});
309 +const withdrawnManifest: ModelManifest.ModelManifestData = {
310 + ...ModelManifest.BUNDLED_MODEL_MANIFEST,
311 + compatibility: [
312 + {
313 + driver: "antigravity",
314 + t3CodeRange: ">=0.0.42",
315 + ranges: [{ range: ">=1.4.0", status: "broken" }],
316 + },
317 + ],
318 +};
319 +const pinnedAsset = Effect.fn("test.pinnedAntigravityAsset")(function* () {
320 + return { ...(yield* releaseAsset()), version: "1.3.0" };
321 +});
322 +
323 it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity installation", (it) => {
324 it.effect("reports missing Node before downloading the standalone provider runtime", () =>
325 Effect.gen(function* () {
@@ -764,7 +830,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
830 });
831
832 const { installation: windows } = yield* makeHarness({ baseDir, platform: "win32" });
767 - for (const name of ["agy.EXE", "agy.cmd"]) {
833 + for (const name of ["agy.EXE", "agy.CMD"]) {
834 const windowsDirectory = path.join(baseDir, `windows-${name}`);
835 yield* fs.makeDirectory(windowsDirectory);
836 yield* fs.writeFileString(path.join(windowsDirectory, name), "cli");
@@ -1018,4 +1084,167 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
1084 expect(requests).toEqual([]);
1085 }),
1086 );
1087 +
1088 + it.effect("updates past the pinned release to the registry release and never downgrades", () =>
1089 + Effect.gen(function* () {
1090 + const asset = yield* pinnedAsset();
1091 + const h = yield* makeHarness({
1092 + asset,
1093 + registry: registryListing(),
1094 + archives: { [upstreamUrl]: upstreamArchive },
1095 + });
1096 + yield* h.installation.checkForUpdate;
1097 + // A fresh install still gets the pinned release.
1098 + expect(yield* h.installation.state).toMatchObject({ version: "1.3.0" });
1099 + yield* h.installation.start;
1100 + expect(yield* terminalState(h.installation)).toMatchObject({
1101 + phase: "succeeded",
1102 + installedVersion: "1.3.0",
1103 + version: "1.4.1",
1104 + totalBytes: null,
1105 + });
1106 +
1107 + yield* h.installation.start;
1108 + expect(yield* terminalState(h.installation)).toMatchObject({
1109 + phase: "succeeded",
1110 + installedVersion: "1.4.1",
1111 + version: "1.4.1",
1112 + });
1113 + expect(h.validations.at(-1)?.version).toBe("1.4.1");
1114 + expect(h.requests).toEqual([ACP_REGISTRY_URL, asset.url, upstreamUrl]);
1115 + const selected = yield* h.installation.resolve();
1116 + expect(selected.version).toBe("1.4.1");
1117 + expect(yield* h.fs.readFileString(selected.executablePath)).toBe(serverContents);
1118 +
1119 + // Without registry information the older pin is not offered as a reinstall.
1120 + const restarted = yield* makeHarness({ baseDir: h.baseDir, asset });
1121 + expect(yield* restarted.installation.state).toMatchObject({
1122 + installedVersion: "1.4.1",
1123 + version: "1.4.1",
1124 + });
1125 + yield* restarted.installation.start;
1126 + expect(yield* terminalState(restarted.installation)).toMatchObject({
1127 + phase: "succeeded",
1128 + installedVersion: "1.4.1",
1129 + });
1130 + expect(restarted.requests).toEqual([]);
1131 + expect(restarted.validations.map((entry) => entry.version)).toEqual(["1.4.1"]);
1132 + }),
1133 + );
1134 +
1135 + it.effect.each([
1136 + {
1137 + name: "hosted outside Google's downloads",
1138 + registry: registryListing("https://example.com/agy.zip"),
1139 + },
1140 + {
1141 + name: "from an oversized registry index",
1142 + registry: { ...registryListing(), padding: "x".repeat(1024 * 1024) },
1143 + },
1144 + {
1145 + name: "escaping Google's releases path",
1146 + registry: registryListing(
1147 + "https://dl.google.com/agy-extensions/releases/%2e%2e/%2e%2e/other.zip",
1148 + ),
1149 + },
1150 + {
1151 + name: "withdrawn by the model manifest",
1152 + registry: registryListing(),
1153 + manifest: Effect.succeed(withdrawnManifest),
1154 + },
1155 + ])("does not offer a registry release $name", ({ registry, manifest }) =>
1156 + Effect.gen(function* () {
1157 + const h = yield* makeHarness({
1158 + asset: yield* pinnedAsset(),
1159 + registry,
1160 + ...(manifest ? { manifest } : {}),
1161 + });
1162 + yield* h.installation.start;
1163 + yield* terminalState(h.installation);
1164 + yield* h.installation.checkForUpdate;
1165 + expect(yield* h.installation.state).toMatchObject({
1166 + installedVersion: "1.3.0",
1167 + version: "1.3.0",
1168 + });
1169 + }),
1170 + );
1171 +
1172 + it.effect("does not retry a failed registry lookup within the hour", () =>
1173 + Effect.gen(function* () {
1174 + const h = yield* makeHarness();
1175 + yield* h.installation.checkForUpdate;
1176 + yield* h.installation.checkForUpdate;
1177 + expect(h.requests).toEqual([ACP_REGISTRY_URL]);
1178 + yield* TestClock.adjust("1 hour");
1179 + yield* h.installation.checkForUpdate;
1180 + expect(h.requests).toEqual([ACP_REGISTRY_URL, ACP_REGISTRY_URL]);
1181 + }),
1182 + );
1183 +
1184 + it.effect.each(["update", "reinstall"] as const)(
1185 + "rejects withdrawal during $0 validation",
1186 + (operation) =>
1187 + Effect.gen(function* () {
1188 + let manifest = ModelManifest.BUNDLED_MODEL_MANIFEST;
1189 + let withdraw = operation === "update";
1190 + const h = yield* makeHarness({
1191 + asset: yield* pinnedAsset(),
1192 + registry: registryListing(),
1193 + archives: { [upstreamUrl]: upstreamArchive },
1194 + manifest: Effect.sync(() => manifest),
1195 + validate: (_executable, version) =>
1196 + Effect.sync(() => {
1197 + if (withdraw && version === "1.4.1") manifest = withdrawnManifest;
1198 + }),
1199 + });
1200 + yield* h.installation.start;
1201 + yield* terminalState(h.installation);
1202 + yield* h.installation.checkForUpdate;
1203 + if (operation === "reinstall") {
1204 + yield* h.installation.start;
1205 + expect((yield* terminalState(h.installation)).phase).toBe("succeeded");
1206 + withdraw = true;
1207 + }
1208 + yield* h.installation.start;
1209 + expect((yield* terminalState(h.installation)).phase).toBe("failed");
1210 + if (operation === "update") {
1211 + expect((yield* h.installation.resolve()).version).toBe("1.3.0");
1212 + } else {
1213 + expect((yield* h.installation.state).version).toBe("1.3.0");
1214 + yield* Effect.flip(h.installation.resolve());
1215 + }
1216 + }),
1217 + );
1218 +
1219 + it.effect("returns an install the manifest withdraws to the pinned release", () =>
1220 + Effect.gen(function* () {
1221 + let manifest = ModelManifest.BUNDLED_MODEL_MANIFEST;
1222 + const h = yield* makeHarness({
1223 + asset: yield* pinnedAsset(),
1224 + registry: registryListing(),
1225 + archives: { [upstreamUrl]: upstreamArchive },
1226 + manifest: Effect.sync(() => manifest),
1227 + });
1228 + yield* h.installation.checkForUpdate;
1229 + yield* h.installation.start;
1230 + yield* terminalState(h.installation);
1231 + yield* h.installation.start;
1232 + expect(yield* terminalState(h.installation)).toMatchObject({ installedVersion: "1.4.1" });
1233 +
1234 + manifest = withdrawnManifest;
1235 + expect((yield* Effect.flip(h.installation.resolve())).detail).toContain("no longer works");
1236 + yield* h.installation.checkForUpdate;
1237 + expect(yield* h.installation.state).toMatchObject({
1238 + installedVersion: "1.4.1",
1239 + version: "1.3.0",
1240 + });
1241 + yield* h.installation.start;
1242 + expect(yield* terminalState(h.installation)).toMatchObject({
1243 + phase: "succeeded",
1244 + installedVersion: "1.3.0",
1245 + version: "1.3.0",
1246 + });
1247 + expect((yield* h.installation.resolve()).version).toBe("1.3.0");
1248 + }),
1249 + );
1250 });
apps/server/src/provider/AntigravityInstallation.ts
+342 -82
@@ -22,13 +22,26 @@ import * as Scope from "effect/Scope";
22 import * as Semaphore from "effect/Semaphore";
23 import * as Stream from "effect/Stream";
24 import * as SubscriptionRef from "effect/SubscriptionRef";
25 -import { HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse } from "effect/http";
25 +import {
26 + FetchHttpClient,
27 + HttpClient,
28 + HttpClientError,
29 + HttpClientRequest,
30 + HttpClientResponse,
31 +} from "effect/http";
32 import * as ChildProcess from "effect/process/ChildProcess";
33 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
34 import * as NodeCrypto from "node:crypto";
35 import * as NodeFSP from "node:fs/promises";
36 import * as EffectAcpErrors from "effect-acp/errors";
37
38 +import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStreamText";
39 +import {
40 + ACP_REGISTRY_URL,
41 + MAX_REGISTRY_BYTES,
42 + resolveAcpRegistryPlatformTarget,
43 +} from "@t3tools/provider-acp-registry/server/AcpRegistrySupport";
44 +
45 import * as ServerConfig from "../config.ts";
46 import { openZipArchive } from "../zipArchive.ts";
47 import { makeAntigravityAcpRuntime } from "./acp/AntigravityAcpSupport.ts";
@@ -38,8 +51,13 @@ import {
51 } from "./antigravityAuthSupport.ts";
52 import {
53 resolveAntigravityReleaseAsset,
54 + type AntigravityRelease,
55 type AntigravityReleaseAsset,
56 + type AntigravityUpstreamRelease,
57 } from "./antigravityRelease.ts";
58 +import { selectManagedRelease } from "./managedRelease.ts";
59 +import * as ModelManifest from "./ModelManifest.ts";
60 +import { resolveProviderCompatibility } from "./providerCompatibility.ts";
61
62 const DRIVER = ProviderDriverKind.make("antigravity");
63 const DOWNLOAD_TIMEOUT = "45 minutes";
@@ -47,6 +65,29 @@ const VALIDATION_TIMEOUT = "90 seconds";
65 const FREE_SPACE_MARGIN = 256 * 1024 * 1024;
66 const RECORD_MAX_BYTES = 8 * 1024;
67 const RELEASE_RECORD = ".install-complete.json";
68 +const UPDATE_CHECK_INTERVAL_MS = 60 * 60_000;
69 +const UPDATE_CHECK_TIMEOUT = "20 seconds";
70 +const UPSTREAM_AGENT_ID = "antigravity-acp";
71 +const UPSTREAM_DOWNLOAD_PREFIX = "https://dl.google.com/agy-extensions/releases/";
72 +// An upstream release has no pinned sizes. Current archives are about 340 MB
73 +// and extract to about 1.1 GB.
74 +const UPSTREAM_MAX_ARCHIVE_BYTES = 1024 * 1024 * 1024;
75 +const UPSTREAM_MAX_EXTRACTED_BYTES = 2 * 1024 * 1024 * 1024;
76 +
77 +const decodeRegistryIndex = Schema.decodeUnknownEffect(
78 + Schema.fromJsonString(Schema.Struct({ agents: Schema.Array(Schema.Unknown) })),
79 +);
80 +const isUpstreamAgent = Schema.is(Schema.Struct({ id: Schema.Literal(UPSTREAM_AGENT_ID) }));
81 +const decodeRegistryAgent = Schema.decodeUnknownEffect(
82 + Schema.Struct({
83 + version: Schema.String,
84 + distribution: Schema.Struct({
85 + binary: Schema.optionalKey(
86 + Schema.Record(Schema.String, Schema.Struct({ archive: Schema.String })),
87 + ),
88 + }),
89 + }),
90 +);
91 const LARGE_PAGE_KERNEL_MESSAGE =
92 "Google's linux-arm64 Antigravity runtime needs a kernel with 4 KiB memory pages, and this kernel uses larger pages (as on Asahi Linux or Raspberry Pi 5). Use a remote environment or a custom Antigravity executable.";
93
@@ -103,6 +144,11 @@ interface AntigravityInstallationService {
144 ) => Effect.Effect<ProviderInstallState, AntigravityInstallationError>;
145 readonly state: Effect.Effect<ProviderInstallState>;
146 readonly changes: Stream.Stream<ProviderInstallState>;
147 + /**
148 + * Looks up the newest release in the ACP Registry, at most hourly, and
149 + * offers it through `state.version` when it is newer than the install.
150 + */
151 + readonly checkForUpdate: Effect.Effect<void>;
152 readonly remove: (
153 protectedBinaryPaths?: ReadonlyArray<string>,
154 ) => Effect.Effect<void, AntigravityInstallationError>;
@@ -162,6 +208,7 @@ function isRunning(state: ProviderInstallState) {
208 export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.make")(function* (
209 options: AntigravityInstallationOptions,
210 ) {
211 + const manifestService = yield* ModelManifest.ModelManifest;
212 const fs = yield* FileSystem.FileSystem;
213 const path = yield* Path.Path;
214 const random = yield* SecureRandom.SecureRandom;
@@ -185,20 +232,112 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
232 const versionsDirectory = path.join(managedDirectory, "versions");
233 const activePath = path.join(managedDirectory, "active.json");
234 const gate = yield* Semaphore.make(1);
235 + const updateCheckGate = yield* Semaphore.make(1);
236 const leases = new Map<string, number>();
237 let running: { readonly operationId: string; readonly fiber: Fiber.Fiber<void> } | undefined;
238 + let upstream: AntigravityUpstreamRelease | null = null;
239 + let upstreamCheckedAt: number | null = null;
240 +
241 + // What `start` installs next. Clients compare `version` with
242 + // `installedVersion` to offer an update.
243 + const offer = (installedVersion: string | null) => {
244 + const release = selectManagedRelease<AntigravityRelease>(
245 + installedVersion,
246 + releaseAsset,
247 + upstream,
248 + );
249 + return {
250 + version: release?.version ?? installedVersion,
251 + totalBytes: release && "archiveBytes" in release ? release.archiveBytes : null,
252 + };
253 + };
254 +
255 const state = yield* SubscriptionRef.make<ProviderInstallState>({
256 driver: DRIVER,
257 operationId: null,
258 phase: "idle",
259 downloadedBytes: 0,
195 - totalBytes: releaseAsset?.archiveBytes ?? null,
196 - version: releaseAsset?.version ?? null,
260 + ...offer(null),
261 installedVersion: null,
262 canRemove: false,
263 message: null,
264 });
265
266 + // The model manifest can withdraw a bad upstream release without a T3 Code release.
267 + const isWithdrawn = Effect.fn("AntigravityInstallation.isWithdrawn")(function* (version: string) {
268 + const manifest = yield* manifestService.current;
269 + const status = (
270 + resolveProviderCompatibility(manifest.compatibility, DRIVER, version) ??
271 + resolveProviderCompatibility(
272 + ModelManifest.BUNDLED_MODEL_MANIFEST.compatibility,
273 + DRIVER,
274 + version,
275 + )
276 + )?.status;
277 + return status === "broken" || status === "unsupported";
278 + });
279 +
280 + // Forgets what the manifest withdrew after it was seen. A withdrawn install
281 + // is not kept either, so the pin replaces it rather than a re-check.
282 + const keptInstall = Effect.fn("AntigravityInstallation.keptInstall")(function* (
283 + installedVersion: string | null,
284 + ) {
285 + if (upstream && (yield* isWithdrawn(upstream.version))) upstream = null;
286 + return installedVersion !== null && !(yield* isWithdrawn(installedVersion))
287 + ? installedVersion
288 + : null;
289 + });
290 +
291 + const lookupUpstream = Effect.gen(function* () {
292 + const target = resolveAcpRegistryPlatformTarget(platform, arch);
293 + if (!target) return null;
294 + const response = yield* http
295 + .execute(HttpClientRequest.get(ACP_REGISTRY_URL))
296 + .pipe(Effect.flatMap(HttpClientResponse.filterStatusOk));
297 + const body = yield* collectUint8StreamText({
298 + stream: response.stream,
299 + maxBytes: MAX_REGISTRY_BYTES + 1,
300 + });
301 + if (body.truncated || body.bytes > MAX_REGISTRY_BYTES || body.invalidUtf8) return null;
302 + const index = yield* decodeRegistryIndex(body.text);
303 + const entry = index.agents.find(isUpstreamAgent);
304 + if (!entry) return null;
305 + const agent = yield* decodeRegistryAgent(entry);
306 + // Checked after normalization so an encoded `..` cannot leave the releases path.
307 + const archive = agent.distribution.binary?.[target]?.archive;
308 + const url = archive === undefined ? undefined : URL.parse(archive)?.href;
309 + if (!/^\d+\.\d+\.\d+$/u.test(agent.version) || !url?.startsWith(UPSTREAM_DOWNLOAD_PREFIX)) {
310 + return null;
311 + }
312 + if (yield* isWithdrawn(agent.version)) return null;
313 + return { version: agent.version, url } satisfies AntigravityUpstreamRelease;
314 + });
315 +
316 + // A check already in flight covers concurrent subscribers, including when it fails.
317 + const checkForUpdate = updateCheckGate
318 + .withPermitsIfAvailable(1)(
319 + Effect.gen(function* () {
320 + const now = yield* Clock.currentTimeMillis;
321 + if (upstreamCheckedAt === null || now - upstreamCheckedAt >= UPDATE_CHECK_INTERVAL_MS) {
322 + // A failed lookup counts too, and keeps whatever release was offered before.
323 + upstreamCheckedAt = now;
324 + upstream = yield* lookupUpstream.pipe(
325 + Effect.timeout(UPDATE_CHECK_TIMEOUT),
326 + Effect.orElseSucceed(() => upstream),
327 + );
328 + }
329 + // A running install already published the release it is installing.
330 + yield* SubscriptionRef.updateEffect(state, (current) =>
331 + isRunning(current)
332 + ? Effect.succeed(current)
333 + : keptInstall(current.installedVersion).pipe(
334 + Effect.map((kept) => ({ ...current, ...offer(kept) })),
335 + ),
336 + );
337 + }),
338 + )
339 + .pipe(Effect.ignore);
340 +
341 const readRecord = Effect.fn("AntigravityInstallation.readRecord")(function* <A>(
342 filePath: string,
343 schema: Schema.Codec<A>,
@@ -343,7 +482,15 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
482 }
483 if (yield* fs.exists(activePath)) {
484 const active = yield* readRecord(activePath, ActiveRelease);
346 - return yield* completedRelease(active.releaseId);
485 + const installed = yield* completedRelease(active.releaseId);
486 + // Without this a withdrawn install keeps launching until its owner updates.
487 + if (yield* isWithdrawn(installed.version)) {
488 + return yield* installationError(
489 + "resolve",
490 + `Antigravity ${installed.version} no longer works with this T3 Code release. Update it in Antigravity setup.`,
491 + );
492 + }
493 + return installed;
494 }
495 for (const candidate of yield* commandCandidates(names.executable, processEnvironment)) {
496 const selected = yield* fromExternal(candidate, "path");
@@ -472,7 +619,20 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
619 );
620
621 const install = Effect.fn("AntigravityInstallation.install")(
475 - function* (asset: AntigravityReleaseAsset) {
622 + function* (release: AntigravityRelease) {
623 + // A pinned release is checked against its recorded hash and sizes. An
624 + // upstream release is bounded instead and identified by what downloads.
625 + const pin = "sha256" in release ? release : null;
626 + const ensureEligible = Effect.fn("AntigravityInstallation.ensureEligible")(function* () {
627 + if (!pin && (yield* isWithdrawn(release.version))) {
628 + return yield* installationError(
629 + "verify",
630 + "This Antigravity release was withdrawn. Check for updates and try again.",
631 + );
632 + }
633 + });
634 + const executable = pin?.executable ?? { name: names.executable, bytes: null };
635 + const harness = pin?.harness ?? { name: names.harness, bytes: null };
636 yield* resolveNodeExecutable("Antigravity", environment).pipe(
637 Effect.provideService(FileSystem.FileSystem, fs),
638 Effect.provideService(Path.Path, path),
@@ -497,27 +657,27 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
657 SubscriptionRef.update(state, (current) => ({ ...current, phase, message }));
658 yield* fs.makeDirectory(versionsDirectory, { recursive: true });
659 yield* SubscriptionRef.update(state, (current) => ({ ...current, canRemove: true }));
500 - const destination = path.join(versionsDirectory, asset.sha256);
660 const activate = Effect.fn("AntigravityInstallation.activate")(
502 - function* () {
661 + function* (releaseId: string) {
662 const pointerDirectory = yield* fs.makeTempDirectoryScoped({
663 directory: managedDirectory,
664 prefix: "active.json.",
665 });
666 const pointerPath = path.join(pointerDirectory, "contents.tmp");
508 - yield* fs.writeFileString(
509 - pointerPath,
510 - yield* encodeActiveRelease({ releaseId: asset.sha256 }),
511 - { flag: "wx", mode: 0o600 },
512 - );
667 + yield* fs.writeFileString(pointerPath, yield* encodeActiveRelease({ releaseId }), {
668 + flag: "wx",
669 + mode: 0o600,
670 + });
671 + yield* ensureEligible();
672 yield* fs.rename(pointerPath, activePath);
673 yield* SubscriptionRef.update(
674 state,
675 (current) =>
676 ({
677 ...current,
678 + ...offer(release.version),
679 phase: "succeeded",
520 - installedVersion: asset.version,
680 + installedVersion: release.version,
681 message: null,
682 }) satisfies ProviderInstallState,
683 );
@@ -531,37 +691,52 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
691 ),
692 Effect.uninterruptible,
693 );
534 -
535 - if (yield* fs.exists(destination)) {
536 - const existing = yield* completedRelease(asset.sha256);
537 - if (existing.version !== asset.version) {
694 + const reuse = Effect.fn("AntigravityInstallation.reuse")(function* (releaseId: string) {
695 + const existing = yield* completedRelease(releaseId);
696 + if (existing.version !== release.version) {
697 return yield* installationError(
698 "verify",
699 "The existing managed release has the wrong version. Remove it before reinstalling.",
700 );
701 }
702 yield* report("verifying", "Checking the installed runtime.");
544 - yield* validate(existing, asset.version).pipe(
703 + yield* ensureEligible();
704 + yield* validate(existing, release.version).pipe(
705 Effect.scoped,
706 Effect.timeout(VALIDATION_TIMEOUT),
707 );
548 - yield* activate();
549 - return;
708 + yield* activate(releaseId);
709 + });
710 +
711 + if (pin && (yield* fs.exists(path.join(versionsDirectory, pin.sha256)))) {
712 + return yield* reuse(pin.sha256);
713 }
714
552 - const available = yield* Effect.tryPromise({
553 - try: () => NodeFSP.statfs(versionsDirectory, { bigint: true }),
554 - catch: (cause) => installationError("download", "Could not check free disk space.", cause),
555 - }).pipe(Effect.option);
556 - const required =
557 - asset.archiveBytes + asset.executable.bytes + asset.harness.bytes + FREE_SPACE_MARGIN;
558 - if (
559 - Option.isSome(available) &&
560 - available.value.bavail * available.value.bsize < BigInt(required)
715 + const ensureFreeSpace = Effect.fn("AntigravityInstallation.ensureFreeSpace")(function* (
716 + operation: string,
717 + bytes: number,
718 ) {
562 - return yield* installationError(
719 + const available = yield* Effect.tryPromise({
720 + try: () => NodeFSP.statfs(versionsDirectory, { bigint: true }),
721 + catch: (cause) => installationError(operation, "Could not check free disk space.", cause),
722 + }).pipe(Effect.option);
723 + const required = bytes + FREE_SPACE_MARGIN;
724 + if (
725 + Option.isSome(available) &&
726 + available.value.bavail * available.value.bsize < BigInt(required)
727 + ) {
728 + return yield* installationError(
729 + operation,
730 + `Antigravity needs at least ${Math.ceil(required / 1024 / 1024)} MiB of free space to install.`,
731 + );
732 + }
733 + });
734 + // An upstream release has no recorded sizes, so each member is checked
735 + // against free space once the archive declares it.
736 + if (pin) {
737 + yield* ensureFreeSpace(
738 "download",
564 - `Antigravity needs at least ${Math.ceil(required / 1024 / 1024)} MiB of free space to install.`,
739 + pin.archiveBytes + pin.executable.bytes + pin.harness.bytes,
740 );
741 }
742 const staging = yield* fs.makeTempDirectoryScoped({
@@ -571,40 +746,63 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
746 const archivePath = path.join(staging, "download.zip");
747 const pairDirectory = path.join(staging, "runtime");
748 yield* fs.makeDirectory(pairDirectory);
749 + const maxArchiveBytes = pin?.archiveBytes ?? UPSTREAM_MAX_ARCHIVE_BYTES;
750 const hash = NodeCrypto.createHash("sha256");
751 let downloadedBytes = 0;
752 let lastProgressAt = yield* Clock.currentTimeMillis;
753 yield* Effect.gen(function* () {
578 - const response = yield* http
579 - .execute(HttpClientRequest.get(asset.url))
580 - .pipe(Effect.flatMap(HttpClientResponse.filterStatusOk));
581 - // dl.google.com may gzip the zip: content-length is encoded, while byte/hash checks use decoded data.
754 + const request = http.execute(HttpClientRequest.get(release.url));
755 + // Only its URL vouches for an upstream release, so a redirect is
756 + // refused rather than followed somewhere that check never saw.
757 + const response = yield* (
758 + pin
759 + ? request
760 + : request.pipe(
761 + Effect.provideService(FetchHttpClient.RequestInit, { redirect: "error" }),
762 + )
763 + ).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk));
764 + // dl.google.com gzips the zip when the client accepts it, so
765 + // `content-length` is the encoded size. The decoded stream is still
766 + // checked against the byte limit and, when pinned, the hash below.
767 const contentLength = response.headers["content-length"];
768 const contentEncoding = response.headers["content-encoding"]?.trim().toLowerCase();
769 const identityBody = contentEncoding === undefined || contentEncoding === "identity";
585 - if (
586 - identityBody &&
587 - contentLength !== undefined &&
588 - Number(contentLength) !== asset.archiveBytes
589 - ) {
590 - return yield* installationError(
591 - "download",
592 - "The Antigravity download size did not match the pinned release.",
593 - );
770 + if (identityBody && contentLength !== undefined) {
771 + const declaredBytes = Number(contentLength);
772 + if (pin && declaredBytes !== pin.archiveBytes) {
773 + return yield* installationError(
774 + "download",
775 + "The Antigravity download size did not match the pinned release.",
776 + );
777 + }
778 + if (!pin && Number.isSafeInteger(declaredBytes) && declaredBytes > 0) {
779 + if (declaredBytes > maxArchiveBytes) {
780 + return yield* installationError(
781 + "download",
782 + "The Antigravity download is larger than T3 Code accepts.",
783 + );
784 + }
785 + yield* SubscriptionRef.update(state, (current) => ({
786 + ...current,
787 + totalBytes: declaredBytes,
788 + }));
789 + }
790 }
791 yield* response.stream.pipe(
792 Stream.tap((chunk) =>
793 Effect.gen(function* () {
794 downloadedBytes += chunk.byteLength;
599 - if (downloadedBytes > asset.archiveBytes) {
795 + if (downloadedBytes > maxArchiveBytes) {
796 return yield* installationError(
797 "download",
602 - "The Antigravity download exceeded the pinned release size.",
798 + pin
799 + ? "The Antigravity download exceeded the pinned release size."
800 + : "The Antigravity download is larger than T3 Code accepts.",
801 );
802 }
803 hash.update(chunk);
804 const now = yield* Clock.currentTimeMillis;
607 - if (now - lastProgressAt >= 250 || downloadedBytes === asset.archiveBytes) {
805 + if (now - lastProgressAt >= 250 || downloadedBytes === pin?.archiveBytes) {
806 lastProgressAt = now;
807 yield* SubscriptionRef.update(state, (current) => ({
808 ...current,
@@ -627,14 +825,21 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
825 : cause,
826 ),
827 );
630 - if (downloadedBytes !== asset.archiveBytes || hash.digest("hex") !== asset.sha256) {
828 + const releaseId = hash.digest("hex");
829 + if (pin && (downloadedBytes !== pin.archiveBytes || releaseId !== pin.sha256)) {
830 return yield* installationError(
831 "download",
832 "The Antigravity download failed its size or SHA-256 check. Nothing was installed.",
833 );
834 }
835 + const destination = path.join(versionsDirectory, releaseId);
836 + if (!pin && (yield* fs.exists(destination))) {
837 + return yield* reuse(releaseId);
838 + }
839
840 yield* report("extracting", "Extracting the verified runtime.");
841 + const extracted = new Map<string, number>();
842 + let extractedTotal = 0;
843 yield* Effect.gen(function* () {
844 const archive = yield* openZipArchive(archivePath, (detail, cause) =>
845 installationError("extract", detail, cause),
@@ -645,31 +850,33 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
850 "The archive must contain exactly the Antigravity executable and its harness.",
851 );
852 }
648 - const seen = new Set<string>();
853 for (;;) {
854 const entry = yield* archive.next;
855 if (!entry) break;
652 - const expected = [asset.executable, asset.harness].find(
653 - (file) => file.name === entry.fileName,
654 - );
856 + const expected = [executable, harness].find((file) => file.name === entry.fileName);
857 + const expectedBytes = expected?.bytes ?? entry.uncompressedSize;
858 const unixType = (entry.externalFileAttributes >>> 16) & 0o170000;
859 if (
860 !expected ||
658 - seen.has(entry.fileName) ||
861 + extracted.has(entry.fileName) ||
862 entry.fileName.includes("/") ||
863 entry.fileName.includes("\\") ||
864 (unixType !== 0 && unixType !== 0o100000) ||
865 (entry.externalFileAttributes & 0x10) !== 0 ||
866 (entry.generalPurposeBitFlag & 1) !== 0 ||
867 ![0, 8].includes(entry.compressionMethod) ||
665 - entry.uncompressedSize !== expected.bytes
868 + entry.uncompressedSize !== expectedBytes ||
869 + expectedBytes <= 0 ||
870 + extractedTotal + expectedBytes > UPSTREAM_MAX_EXTRACTED_BYTES
871 ) {
872 return yield* installationError(
873 "extract",
874 "The archive contains an unexpected, unsafe, or incorrectly sized member.",
875 );
876 }
672 - seen.add(entry.fileName);
877 + if (!pin) yield* ensureFreeSpace("extract", expectedBytes);
878 + extracted.set(entry.fileName, expectedBytes);
879 + extractedTotal += expectedBytes;
880 yield* Effect.gen(function* () {
881 const readable = yield* archive.streamEntry(entry);
882 let extractedBytes = 0;
@@ -680,10 +887,10 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
887 Stream.tap((chunk) =>
888 Effect.gen(function* () {
889 extractedBytes += chunk.byteLength;
683 - if (extractedBytes > expected.bytes) {
890 + if (extractedBytes > expectedBytes) {
891 return yield* installationError(
892 "extract",
686 - "An archive member exceeded its pinned size.",
893 + "An archive member exceeded its expected size.",
894 );
895 }
896 }),
@@ -692,21 +899,23 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
899 fs.sink(path.join(pairDirectory, entry.fileName), { flag: "wx", mode: 0o700 }),
900 ),
901 );
695 - if (extractedBytes !== expected.bytes) {
902 + if (extractedBytes !== expectedBytes) {
903 return yield* installationError("extract", "An archive member was truncated.");
904 }
905 }).pipe(Effect.scoped);
906 }
700 - if (!seen.has(asset.executable.name) || !seen.has(asset.harness.name)) {
701 - return yield* installationError(
702 - "extract",
703 - "The archive is missing the Antigravity executable or its harness.",
704 - );
705 - }
907 }).pipe(Effect.scoped);
908 + const executableBytes = extracted.get(executable.name);
909 + const harnessBytes = extracted.get(harness.name);
910 + if (executableBytes === undefined || harnessBytes === undefined) {
911 + return yield* installationError(
912 + "extract",
913 + "The archive is missing the Antigravity executable or its harness.",
914 + );
915 + }
916 yield* fs.remove(archivePath);
708 - const executablePath = path.join(pairDirectory, asset.executable.name);
709 - const harnessPath = path.join(pairDirectory, asset.harness.name);
917 + const executablePath = path.join(pairDirectory, executable.name);
918 + const harnessPath = path.join(pairDirectory, harness.name);
919 if (platform !== "win32") {
920 yield* fs.chmod(executablePath, 0o755);
921 yield* fs.chmod(harnessPath, 0o755);
@@ -734,24 +943,25 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
943 }
944 }
945 yield* report("verifying", "Checking the downloaded runtime.");
946 + yield* ensureEligible();
947 yield* validate(
948 {
949 executablePath,
950 harnessPath,
951 source: "managed",
742 - version: asset.version,
952 + version: release.version,
953 managedVersionDirectory: pairDirectory,
954 },
745 - asset.version,
955 + release.version,
956 ).pipe(Effect.scoped, Effect.timeout(VALIDATION_TIMEOUT));
957 const record: InstalledRelease = {
748 - releaseId: asset.sha256,
749 - version: asset.version,
958 + releaseId,
959 + version: release.version,
960 executable: {
751 - name: asset.executable.name,
961 + name: executable.name,
962 bytes: Number((yield* fs.stat(executablePath)).size),
963 },
754 - harness: { name: asset.harness.name, bytes: Number((yield* fs.stat(harnessPath)).size) },
964 + harness: { name: harness.name, bytes: Number((yield* fs.stat(harnessPath)).size) },
965 };
966 yield* fs.writeFileString(
967 path.join(pairDirectory, RELEASE_RECORD),
@@ -760,10 +970,11 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
970 );
971 yield* fs.rename(pairDirectory, destination).pipe(
972 Effect.catch((cause) =>
763 - completedRelease(asset.sha256).pipe(
973 + completedRelease(releaseId).pipe(
974 Effect.flatMap((existing) =>
765 - existing.version === asset.version
766 - ? validate(existing, asset.version).pipe(
975 + existing.version === release.version
976 + ? ensureEligible().pipe(
977 + Effect.andThen(validate(existing, release.version)),
978 Effect.scoped,
979 Effect.timeout(VALIDATION_TIMEOUT),
980 )
@@ -784,7 +995,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
995 ),
996 ),
997 );
787 - yield* activate();
998 + yield* activate(releaseId);
999 },
1000 Effect.scoped,
1001 Effect.mapError(
@@ -795,12 +1006,56 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
1006 ),
1007 );
1008
1009 + // Nothing newer is known, so "reinstall" re-checks the active runtime rather
1010 + // than replacing it with an older pinned release.
1011 + const reverify = Effect.fn("AntigravityInstallation.reverify")(
1012 + function* () {
1013 + const active = yield* readRecord(activePath, ActiveRelease);
1014 + const installed = yield* completedRelease(active.releaseId);
1015 + yield* validate(installed, installed.version).pipe(
1016 + Effect.scoped,
1017 + Effect.timeout(VALIDATION_TIMEOUT),
1018 + );
1019 + const kept = yield* keptInstall(installed.version);
1020 + if (kept === null) {
1021 + yield* SubscriptionRef.update(state, (current) => ({ ...current, ...offer(kept) }));
1022 + return yield* installationError(
1023 + "verify",
1024 + "This Antigravity release was withdrawn. Check for updates and try again.",
1025 + );
1026 + }
1027 + yield* SubscriptionRef.update(
1028 + state,
1029 + (current) =>
1030 + ({
1031 + ...current,
1032 + ...offer(kept),
1033 + phase: "succeeded",
1034 + installedVersion: installed.version,
1035 + message: null,
1036 + }) satisfies ProviderInstallState,
1037 + );
1038 + },
1039 + Effect.mapError(
1040 + wrapFailure(
1041 + "verify",
1042 + "The installed Antigravity runtime could not start. Remove it and reinstall.",
1043 + ),
1044 + ),
1045 + );
1046 +
1047 const start = gate
1048 .withPermit(
1049 Effect.gen(function* () {
1050 const current = yield* SubscriptionRef.get(state);
1051 if (isRunning(current)) return current;
803 - if (!releaseAsset) {
1052 + const installedVersion = yield* keptInstall(current.installedVersion);
1053 + const release = selectManagedRelease<AntigravityRelease>(
1054 + installedVersion,
1055 + releaseAsset,
1056 + upstream,
1057 + );
1058 + if (!release && installedVersion === null) {
1059 return yield* installationError(
1060 "start",
1061 `Google does not publish an Antigravity runtime for ${platform}-${arch}. Use a supported remote environment or a custom executable.`,
@@ -810,16 +1065,17 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
1065 const next: ProviderInstallState = {
1066 driver: DRIVER,
1067 operationId,
813 - phase: "downloading",
1068 + phase: release ? "downloading" : "verifying",
1069 downloadedBytes: 0,
815 - totalBytes: releaseAsset.archiveBytes,
816 - version: releaseAsset.version,
1070 + ...offer(installedVersion),
1071 installedVersion: current.installedVersion,
1072 canRemove: current.canRemove,
819 - message: "Downloading Google's official Antigravity runtime.",
1073 + message: release
1074 + ? "Downloading Google's official Antigravity runtime."
1075 + : "Checking the installed runtime.",
1076 };
1077 yield* SubscriptionRef.set(state, next);
822 - const work = install(releaseAsset).pipe(
1078 + const work = (release ? install(release) : reverify()).pipe(
1079 Effect.onExit((exit) =>
1080 Exit.isFailure(exit)
1081 ? SubscriptionRef.update(state, (value) => {
@@ -908,6 +1164,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
1164 (current) =>
1165 ({
1166 ...current,
1167 + ...offer(null),
1168 operationId: null,
1169 phase: "idle",
1170 downloadedBytes: 0,
@@ -933,8 +1190,10 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
1190 if (!(yield* fs.exists(activePath))) return;
1191 const active = yield* readRecord(activePath, ActiveRelease);
1192 const installed = yield* completedRelease(active.releaseId);
1193 + const kept = yield* keptInstall(installed.version);
1194 yield* SubscriptionRef.update(state, (current) => ({
1195 ...current,
1196 + ...offer(kept),
1197 installedVersion: installed.version,
1198 }));
1199 }).pipe(
@@ -959,6 +1218,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma
1218 cancel,
1219 state: SubscriptionRef.get(state),
1220 changes: SubscriptionRef.changes(state),
1221 + checkForUpdate,
1222 remove,
1223 });
1224 });
apps/server/src/provider/CodexInstallation.test.ts
+215 -1
@@ -41,6 +41,8 @@ const makeHarness = Effect.fn("test.makeCodexInstallation")(function* (
41 platform?: NodeJS.Platform;
42 spawner?: ChildProcessSpawner.ChildProcessSpawner["Service"];
43 runtimeRenameFailures?: number;
44 + /** Served by URL instead of the pinned package. */
45 + responses?: Readonly<Record<string, () => Response>>;
46 } = {},
47 ) {
48 const fs = yield* FileSystem.FileSystem;
@@ -110,6 +112,8 @@ const makeHarness = Effect.fn("test.makeCodexInstallation")(function* (
112 HttpClient.make((request) =>
113 Effect.sync(() => {
114 downloads++;
115 + const respond = input.responses?.[request.url];
116 + if (respond) return HttpClientResponse.fromWeb(request, respond());
117 return Object.defineProperty(
118 HttpClientResponse.fromWeb(
119 request,
@@ -529,4 +533,214 @@ it.effect("keeps an activated runtime when a later update fails verification", (
533 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
534 );
535
532 -// Stands in for Windows' bsdtar: CRLF listings, and extraction writes the Windows layout.
536 +const upstreamVersion = "0.163.0";
537 +const upstreamArchive = Buffer.from(
538 + "H4sIAAAAAAACA+3WzY7CIBQF4D5Kw1oqtNQmPoh7rKStP9BQdMaYefcBE43T9RQ1nm8B7Q1Jk94cYN3peW026juZDvOqsrzO3nj2yofnUK9KwZKUJREcByet/2TymabuPby29S3/NIz0EIbWDC5u/sXf/PO8EAL5j+G/ew1vuP/TXrp2bpunnf/5KP+syCvkP4bJmg5vlf96JxuVbQej4+efi2qUf17g/h/Hhezl2RzdStmhM5osUz5Lyen+RljGF0XGiK/6H9UoF4pS2rpdCCr7fq/oRtqvTocVSjt77k2nr6vud0vyg6ABAAAAAAAAAAAAAABE8gvVbjvaACgAAA==",
539 + "base64",
540 +);
541 +const upstreamReleaseUrl = `https://github.com/openai/codex/releases/download/rust-v${upstreamVersion}`;
542 +const upstreamResponses = (checksum: string) => ({
543 + "https://registry.npmjs.org/@openai/codex/latest": () =>
544 + Response.json({ version: upstreamVersion }),
545 + [`${upstreamReleaseUrl}/codex-package_SHA256SUMS`]: () =>
546 + new Response(
547 + `${"0".repeat(64)} codex-package-x86_64-apple-darwin.tar.gz\n${checksum} codex-package-aarch64-apple-darwin.tar.gz\n`,
548 + ),
549 + [`${upstreamReleaseUrl}/codex-package-aarch64-apple-darwin.tar.gz`]: () =>
550 + new Response(upstreamArchive),
551 +});
552 +
553 +it.effect("updates a managed install to OpenAI's newest release and never downgrades it", () =>
554 + Effect.gen(function* () {
555 + const digest = yield* Digest.Digest;
556 + const checksum = Hex.encode(
557 + yield* digest.digest(Digest.sha256, upstreamArchive).pipe(Effect.orDie),
558 + );
559 + const h = yield* makeHarness({ responses: upstreamResponses(checksum) });
560 + yield* h.installation.checkForUpdate;
561 + // A fresh install still gets the pinned release.
562 + expect((yield* h.installation.state).version).toBe("0.156.1");
563 + yield* h.installation.start;
564 + expect(yield* terminalState(h.installation)).toMatchObject({
565 + phase: "succeeded",
566 + installedVersion: "0.156.1",
567 + version: upstreamVersion,
568 + });
569 +
570 + yield* h.installation.start;
571 + expect(yield* terminalState(h.installation)).toMatchObject({
572 + phase: "succeeded",
573 + installedVersion: upstreamVersion,
574 + version: upstreamVersion,
575 + });
576 + expect((yield* h.installation.resolve()).version).toBe(upstreamVersion);
577 +
578 + // Without upstream information the older pin is not offered as a reinstall.
579 + const restarted = yield* makeHarness({ baseDir: h.baseDir });
580 + expect(yield* restarted.installation.state).toMatchObject({
581 + installedVersion: upstreamVersion,
582 + version: upstreamVersion,
583 + });
584 + yield* restarted.installation.start;
585 + expect(yield* terminalState(restarted.installation)).toMatchObject({
586 + phase: "succeeded",
587 + installedVersion: upstreamVersion,
588 + });
589 + expect(restarted.downloads()).toBe(0);
590 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
591 +);
592 +
593 +it.effect("keeps the managed install when an update fails its published checksum", () =>
594 + Effect.gen(function* () {
595 + const h = yield* makeHarness({ responses: upstreamResponses("f".repeat(64)) });
596 + yield* h.installation.start;
597 + yield* terminalState(h.installation);
598 + yield* h.installation.checkForUpdate;
599 + yield* h.installation.start;
600 + expect(yield* terminalState(h.installation)).toMatchObject({
601 + phase: "failed",
602 + installedVersion: "0.156.1",
603 + message: expect.stringContaining("SHA-256"),
604 + });
605 + expect((yield* h.installation.resolve()).version).toBe("0.156.1");
606 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
607 +);
608 +
609 +it.effect("does not install a cached update the manifest has since withdrawn", () =>
610 + Effect.gen(function* () {
611 + const digest = yield* Digest.Digest;
612 + const checksum = Hex.encode(
613 + yield* digest.digest(Digest.sha256, upstreamArchive).pipe(Effect.orDie),
614 + );
615 + let manifest = ModelManifest.BUNDLED_MODEL_MANIFEST;
616 + const h = yield* makeHarness({
617 + responses: upstreamResponses(checksum),
618 + manifestCurrent: Effect.sync(() => manifest),
619 + });
620 + yield* h.installation.start;
621 + yield* terminalState(h.installation);
622 + yield* h.installation.checkForUpdate;
623 + expect((yield* h.installation.state).version).toBe(upstreamVersion);
624 + manifest = {
625 + ...manifest,
626 + compatibility: [
627 + {
628 + driver: "codex",
629 + t3CodeRange: ">=0.0.42",
630 + ranges: [
631 + { range: ">=0.160.0", status: "unsupported" },
632 + { range: ">=0.156.0 <0.160.0", status: "supported" },
633 + ],
634 + },
635 + ],
636 + };
637 + const downloads = h.downloads();
638 + yield* h.installation.start;
639 + expect(yield* terminalState(h.installation)).toMatchObject({
640 + phase: "succeeded",
641 + installedVersion: "0.156.1",
642 + version: "0.156.1",
643 + });
644 + expect(h.downloads()).toBe(downloads);
645 + expect((yield* h.installation.resolve()).version).toBe("0.156.1");
646 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
647 +);
648 +
649 +it.effect("returns a managed install the manifest withdraws to the pinned release", () =>
650 + Effect.gen(function* () {
651 + const digest = yield* Digest.Digest;
652 + const checksum = Hex.encode(
653 + yield* digest.digest(Digest.sha256, upstreamArchive).pipe(Effect.orDie),
654 + );
655 + let manifest = ModelManifest.BUNDLED_MODEL_MANIFEST;
656 + const h = yield* makeHarness({
657 + responses: upstreamResponses(checksum),
658 + manifestCurrent: Effect.sync(() => manifest),
659 + });
660 + yield* h.installation.checkForUpdate;
661 + yield* h.installation.start;
662 + yield* terminalState(h.installation);
663 + yield* h.installation.start;
664 + expect(yield* terminalState(h.installation)).toMatchObject({
665 + installedVersion: upstreamVersion,
666 + });
667 +
668 + manifest = {
669 + ...manifest,
670 + compatibility: [
671 + {
672 + driver: "codex",
673 + t3CodeRange: ">=0.0.42",
674 + ranges: [
675 + { range: ">=0.160.0", status: "unsupported" },
676 + { range: ">=0.156.0 <0.160.0", status: "supported" },
677 + ],
678 + },
679 + ],
680 + };
681 + yield* h.installation.checkForUpdate;
682 + expect(yield* h.installation.state).toMatchObject({
683 + installedVersion: upstreamVersion,
684 + version: "0.156.1",
685 + });
686 + yield* h.installation.start;
687 + expect(yield* terminalState(h.installation)).toMatchObject({
688 + phase: "succeeded",
689 + installedVersion: "0.156.1",
690 + version: "0.156.1",
691 + });
692 + expect((yield* h.installation.resolve()).version).toBe("0.156.1");
693 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
694 +);
695 +
696 +it.effect.each(["update", "reinstall"] as const)(
697 + "rejects withdrawal during $0 validation",
698 + (operation) =>
699 + Effect.gen(function* () {
700 + const digest = yield* Digest.Digest;
701 + const checksum = Hex.encode(
702 + yield* digest.digest(Digest.sha256, upstreamArchive).pipe(Effect.orDie),
703 + );
704 + let manifest = ModelManifest.BUNDLED_MODEL_MANIFEST;
705 + let withdraw = operation === "update";
706 + const h = yield* makeHarness({
707 + responses: upstreamResponses(checksum),
708 + manifestCurrent: Effect.sync(() => manifest),
709 + options: {
710 + validate: (_executable, version) =>
711 + Effect.sync(() => {
712 + if (withdraw && version === upstreamVersion)
713 + manifest = {
714 + ...ModelManifest.BUNDLED_MODEL_MANIFEST,
715 + compatibility: [
716 + {
717 + driver: "codex",
718 + t3CodeRange: ">=0.0.42",
719 + ranges: [
720 + { range: ">=0.160.0", status: "unsupported" },
721 + { range: ">=0.156.0 <0.160.0", status: "supported" },
722 + ],
723 + },
724 + ],
725 + };
726 + }),
727 + },
728 + });
729 + yield* h.installation.start;
730 + yield* terminalState(h.installation);
731 + yield* h.installation.checkForUpdate;
732 + if (operation === "reinstall") {
733 + yield* h.installation.start;
734 + expect((yield* terminalState(h.installation)).phase).toBe("succeeded");
735 + withdraw = true;
736 + }
737 + yield* h.installation.start;
738 + expect((yield* terminalState(h.installation)).phase).toBe("failed");
739 + if (operation === "update") {
740 + expect((yield* h.installation.resolve()).version).toBe("0.156.1");
741 + } else {
742 + expect((yield* h.installation.state).version).toBe("0.156.1");
743 + yield* Effect.flip(h.installation.resolve());
744 + }
745 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
746 +);
apps/server/src/provider/CodexInstallation.ts
+166 -12
@@ -4,7 +4,7 @@ import {
4 type ProviderInstallState,
5 type ServerProviderCompatibilityAdvisory,
6 } from "@t3tools/contracts";
7 -import { cliArchiveTarCommand } from "@t3tools/shared/cliRelease";
7 +import { cliArchiveTarCommand, parseChecksums } from "@t3tools/shared/cliRelease";
8 import { compareSemverVersions } from "@t3tools/shared/semver";
9 import * as HostProcess from "@t3tools/shared/HostProcess";
10 import { resolveCommandPath, resolveSpawnCommand } from "@t3tools/shared/shell";
@@ -29,11 +29,18 @@ import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
29 import { ChildProcess, ChildProcessSpawner } from "effect/process";
30 import * as NodeCrypto from "node:crypto";
31 import * as ServerConfig from "../config.ts";
32 +import { selectManagedRelease } from "./managedRelease.ts";
33 import * as ModelManifest from "./ModelManifest.ts";
34 import { resolveProviderCompatibility } from "./providerCompatibility.ts";
35
36 const DRIVER = ProviderDriverKind.make("codex");
37 const STAGING_STALE_AFTER_MS = 24 * 60 * 60_000;
38 +const UPDATE_CHECK_INTERVAL_MS = 60 * 60_000;
39 +const UPDATE_CHECK_TIMEOUT = "20 seconds";
40 +const UPSTREAM_LATEST_URL = "https://registry.npmjs.org/@openai/codex/latest";
41 +const UPSTREAM_RELEASES_URL = "https://github.com/openai/codex/releases/download";
42 +// An upstream release has no recorded size; current packages are about 160 MB.
43 +const UPSTREAM_MAX_ARCHIVE_BYTES = 1024 * 1024 * 1024;
44 const Version = Schema.String.check(Schema.isPattern(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/u));
45 const ActiveRelease = Schema.Struct({ version: Version });
46 const InstalledRelease = Schema.Struct({
@@ -48,6 +55,7 @@ const PackageManifest = Schema.Struct({
55 entrypoint: Schema.String,
56 });
57 const decodeVersion = Schema.decodeUnknownEffect(Version);
58 +const decodeNpmLatest = Schema.decodeUnknownEffect(Schema.Struct({ version: Version }));
59 const encodeRecord = Schema.encodeEffect(Schema.fromJsonString(InstalledRelease));
60 const encodeActive = Schema.encodeEffect(Schema.fromJsonString(ActiveRelease));
61 export interface CodexReleaseAsset {
@@ -55,7 +63,8 @@ export interface CodexReleaseAsset {
63 readonly target: string;
64 readonly url: string;
65 readonly sha256: string;
58 - readonly archiveBytes: number;
66 + /** Null for an upstream release, whose package checksum is published without a size. */
67 + readonly archiveBytes: number | null;
68 }
69 const RELEASES: Readonly<Record<string, CodexReleaseAsset>> = {
70 "darwin-arm64": {
@@ -139,6 +148,11 @@ interface CodexInstallationService {
148 ) => Effect.Effect<ProviderInstallState, CodexInstallationError>;
149 readonly state: Effect.Effect<ProviderInstallState>;
150 readonly changes: Stream.Stream<ProviderInstallState>;
151 + /**
152 + * Looks up OpenAI's newest Codex release, at most hourly, and offers it
153 + * through `state.version` when it is newer than the managed install.
154 + */
155 + readonly checkForUpdate: Effect.Effect<void>;
156 readonly remove: (
157 protectedBinaryPaths?: ReadonlyArray<string>,
158 ) => Effect.Effect<void, CodexInstallationError>;
@@ -186,15 +200,31 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
200 const activePath = path.join(managedDirectory, "active.json");
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;
205 let running: { readonly operationId: string; readonly fiber: Fiber.Fiber<void> } | undefined;
206 + let upstream: CodexReleaseAsset | null = null;
207 + let upstreamCheckedAt: number | null = null;
208 +
209 + // A local Codex is used as is, so only a managed install is ever updated.
210 + const managedVersion = (current: ProviderInstallState) =>
211 + current.source === "managed" ? current.installedVersion : null;
212 + // What `start` installs next. Clients compare `version` with
213 + // `installedVersion` to offer an update.
214 + const offer = (installedVersion: string | null) => {
215 + const release = selectManagedRelease(installedVersion, asset, upstream);
216 + return {
217 + version: release?.version ?? installedVersion,
218 + totalBytes: release?.archiveBytes ?? null,
219 + };
220 + };
221 +
222 const state = yield* SubscriptionRef.make<ProviderInstallState>({
223 driver: DRIVER,
224 operationId: null,
225 phase: "idle",
226 downloadedBytes: 0,
196 - totalBytes: asset?.archiveBytes ?? null,
197 - version: asset?.version ?? null,
227 + ...offer(null),
228 installedVersion: null,
229 executablePath: null,
230 canRemove: false,
@@ -279,6 +309,70 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
309 )
310 );
311 });
312 + const isSupported = (version: string) =>
313 + compatibility(version).pipe(Effect.map((advisory) => advisory?.status === "supported"));
314 + // Forgets what the manifest withdrew after it was seen. Managed resolution
315 + // refuses a withdrawn install, so the pin replaces it rather than a re-check.
316 + const keptInstall = Effect.fn("CodexInstallation.keptInstall")(function* (
317 + installedVersion: string | null,
318 + ) {
319 + if (upstream && !(yield* isSupported(upstream.version))) upstream = null;
320 + return installedVersion !== null && (yield* isSupported(installedVersion))
321 + ? installedVersion
322 + : null;
323 + });
324 + // npm names the latest stable release; its GitHub release lists the package
325 + // checksums, so an upstream update stays SHA-256 verified.
326 + const lookupUpstream = Effect.gen(function* () {
327 + if (!asset) return null;
328 + const latest = yield* http
329 + .execute(HttpClientRequest.get(UPSTREAM_LATEST_URL))
330 + .pipe(Effect.flatMap(HttpClientResponse.filterStatusOk));
331 + const { version } = yield* latest.json.pipe(Effect.flatMap(decodeNpmLatest));
332 + // Managed resolution refuses anything else, so offering it would break sessions.
333 + if (!(yield* isSupported(version))) return null;
334 + const releaseUrl = `${UPSTREAM_RELEASES_URL}/rust-v${version}`;
335 + const checksums = yield* http
336 + .execute(HttpClientRequest.get(`${releaseUrl}/codex-package_SHA256SUMS`))
337 + .pipe(
338 + Effect.flatMap(HttpClientResponse.filterStatusOk),
339 + Effect.flatMap((response) => response.text),
340 + );
341 + const fileName = `codex-package-${asset.target}.tar.gz`;
342 + const sha256 = parseChecksums(checksums).get(fileName);
343 + if (!sha256) return null;
344 + return {
345 + version,
346 + target: asset.target,
347 + url: `${releaseUrl}/${fileName}`,
348 + sha256,
349 + archiveBytes: null,
350 + } satisfies CodexReleaseAsset;
351 + });
352 + // A check already in flight covers concurrent subscribers, including when it fails.
353 + const checkForUpdate = updateCheckGate
354 + .withPermitsIfAvailable(1)(
355 + Effect.gen(function* () {
356 + const now = yield* Clock.currentTimeMillis;
357 + if (upstreamCheckedAt === null || now - upstreamCheckedAt >= UPDATE_CHECK_INTERVAL_MS) {
358 + // A failed lookup counts too, and keeps whatever release was offered before.
359 + upstreamCheckedAt = now;
360 + upstream = yield* lookupUpstream.pipe(
361 + Effect.timeout(UPDATE_CHECK_TIMEOUT),
362 + Effect.orElseSucceed(() => upstream),
363 + );
364 + }
365 + // A running install already published the release it is installing.
366 + yield* SubscriptionRef.updateEffect(state, (current) =>
367 + isRunning(current)
368 + ? Effect.succeed(current)
369 + : keptInstall(managedVersion(current)).pipe(
370 + Effect.map((kept) => ({ ...current, ...offer(kept) })),
371 + ),
372 + );
373 + }),
374 + )
375 + .pipe(Effect.ignore);
376 const resolveManaged = Effect.fn("CodexInstallation.resolveManaged")(
377 function* () {
378 const active = yield* readRecord(activePath, ActiveRelease);
@@ -464,6 +558,14 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
558 );
559 const install = Effect.fn("CodexInstallation.install")(
560 function* (release: CodexReleaseAsset) {
561 + const ensureEligible = Effect.fn("CodexInstallation.ensureEligible")(function* () {
562 + if (release.version !== asset?.version && !(yield* isSupported(release.version))) {
563 + return yield* installationError(
564 + "verify",
565 + "This Codex release was withdrawn. Check for updates and try again.",
566 + );
567 + }
568 + });
569 yield* decodeVersion(release.version);
570 yield* fs.makeDirectory(managedDirectory, { recursive: true });
571 yield* SubscriptionRef.update(state, (current) => ({ ...current, canRemove: true }));
@@ -480,12 +582,14 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
582 mode: 0o600,
583 flag: "wx",
584 });
585 + yield* ensureEligible();
586 yield* fs.rename(pointer, activePath);
587 yield* SubscriptionRef.update(
588 state,
589 (current) =>
590 ({
591 ...current,
592 + ...offer(release.version),
593 phase: "succeeded",
594 source: "managed",
595 installedVersion: release.version,
@@ -508,6 +612,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
612 "verify",
613 "The existing managed Codex release differs from the official package. Remove it and reinstall.",
614 );
615 + yield* ensureEligible();
616 yield* validate(existing, release.version).pipe(
617 Effect.scoped,
618 Effect.timeout("90 seconds"),
@@ -523,6 +628,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
628 const runtime = path.join(staging, "runtime");
629 yield* fs.makeDirectory(runtime);
630 const hash = NodeCrypto.createHash("sha256");
631 + const maxArchiveBytes = release.archiveBytes ?? UPSTREAM_MAX_ARCHIVE_BYTES;
632 let downloadedBytes = 0;
633 let lastProgressAt = yield* Clock.currentTimeMillis;
634 const response = yield* http
@@ -532,7 +638,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
638 Stream.tap((chunk) =>
639 Effect.gen(function* () {
640 downloadedBytes += chunk.byteLength;
535 - if (downloadedBytes > release.archiveBytes)
641 + if (downloadedBytes > maxArchiveBytes)
642 return yield* installationError(
643 "download",
644 "The Codex download exceeded the expected release size.",
@@ -556,7 +662,10 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
662 ),
663 }),
664 );
559 - if (downloadedBytes !== release.archiveBytes || hash.digest("hex") !== release.sha256)
665 + if (
666 + (release.archiveBytes !== null && downloadedBytes !== release.archiveBytes) ||
667 + hash.digest("hex") !== release.sha256
668 + )
669 return yield* installationError(
670 "download",
671 "The Codex download failed its size or SHA-256 check. Nothing was installed.",
@@ -600,6 +709,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
709 }) satisfies ProviderInstallState,
710 );
711 const executable = yield* fromDirectory(runtime, release.version, release.target);
712 + yield* ensureEligible();
713 yield* validate(executable, release.version).pipe(
714 Effect.scoped,
715 Effect.timeout("90 seconds"),
@@ -642,13 +752,54 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
752 ),
753 ),
754 );
755 + // Nothing newer is known, so "reinstall" re-checks the active runtime rather
756 + // than replacing it with an older pinned release.
757 + const reverify = Effect.fn("CodexInstallation.reverify")(
758 + function* () {
759 + const active = yield* readRecord(activePath, ActiveRelease);
760 + const executable = yield* completedRelease(active.version);
761 + yield* validate(executable, executable.version).pipe(
762 + Effect.scoped,
763 + Effect.timeout("90 seconds"),
764 + );
765 + const kept = yield* keptInstall(executable.version);
766 + if (kept === null) {
767 + yield* SubscriptionRef.update(state, (current) => ({ ...current, ...offer(kept) }));
768 + return yield* installationError(
769 + "verify",
770 + "This Codex release was withdrawn. Check for updates and try again.",
771 + );
772 + }
773 + yield* SubscriptionRef.update(
774 + state,
775 + (current) =>
776 + ({
777 + ...current,
778 + ...offer(kept),
779 + phase: "succeeded",
780 + source: "managed",
781 + installedVersion: executable.version,
782 + executablePath: executable.executablePath,
783 + message: null,
784 + }) satisfies ProviderInstallState,
785 + );
786 + },
787 + Effect.mapError(
788 + wrapFailure(
789 + "verify",
790 + "The installed Codex runtime could not start. Remove it and reinstall.",
791 + ),
792 + ),
793 + );
794 const start = gate
795 .withPermit(
796 Effect.gen(function* () {
797 const current = yield* SubscriptionRef.get(state);
798 if (isRunning(current)) return current;
799 if (yield* reuseLocal()) return yield* SubscriptionRef.get(state);
651 - if (!asset) {
800 + const installedVersion = yield* keptInstall(managedVersion(current));
801 + const release = selectManagedRelease(installedVersion, asset, upstream);
802 + if (!release && installedVersion === null) {
803 return yield* installationError(
804 "start",
805 `OpenAI does not publish a Codex runtime for ${platform}-${arch}. Use a supported remote environment or a custom executable.`,
@@ -658,14 +809,13 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
809 const next: ProviderInstallState = {
810 ...current,
811 operationId,
661 - phase: "downloading",
812 + phase: release ? "downloading" : "verifying",
813 downloadedBytes: 0,
663 - totalBytes: asset.archiveBytes,
664 - version: asset.version,
665 - message: "Downloading Codex.",
814 + ...offer(installedVersion),
815 + message: release ? "Downloading Codex." : "Checking Codex.",
816 };
817 yield* SubscriptionRef.set(state, next);
668 - const work = install(asset).pipe(
818 + const work = (release ? install(release) : reverify()).pipe(
819 Effect.onExit((exit) =>
820 Exit.isFailure(exit)
821 ? SubscriptionRef.update(state, (value) => {
@@ -745,6 +895,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
895 (current) =>
896 ({
897 ...current,
898 + ...offer(null),
899 operationId: null,
900 phase: "idle",
901 downloadedBytes: 0,
@@ -796,11 +947,13 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
947 if (!(yield* fs.exists(activePath))) return;
948 const active = yield* readRecord(activePath, ActiveRelease);
949 const installed = yield* completedRelease(active.version);
950 + const kept = yield* keptInstall(installed.version);
951 yield* SubscriptionRef.update(
952 state,
953 (current) =>
954 ({
955 ...current,
956 + ...offer(kept),
957 installedVersion: installed.version,
958 executablePath: installed.executablePath,
959 source: "managed",
@@ -832,6 +985,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
985 cancel,
986 state: SubscriptionRef.get(state),
987 changes: SubscriptionRef.changes(state),
988 + checkForUpdate,
989 remove,
990 });
991 });
apps/server/src/provider/antigravityRelease.ts
+12
@@ -17,6 +17,18 @@ export interface AntigravityReleaseAsset {
17 };
18 }
19
20 +/**
21 + * A newer release Google lists in the ACP Registry. The registry publishes no
22 + * hash or sizes, so the installer bounds the download, accepts only Google's
23 + * download host, and relies on the runtime's own handshake to identify it.
24 + */
25 +export interface AntigravityUpstreamRelease {
26 + readonly version: string;
27 + readonly url: string;
28 +}
29 +
30 +export type AntigravityRelease = AntigravityReleaseAsset | AntigravityUpstreamRelease;
31 +
32 const releaseAssets = new Map<string, AntigravityReleaseAsset>([
33 [
34 "darwin-arm64",
apps/server/src/provider/managedRelease.ts new
+29
@@ -0,0 +1,29 @@
1 +import { compareSemverVersions, parseSemver } from "@t3tools/shared/semver";
2 +
3 +// Older pins recorded non-semver versions such as `agy_acp_server_1.1.1`; any
4 +// other release is an update from those.
5 +const isNewer = (candidate: string, current: string) =>
6 + parseSemver(candidate) && parseSemver(current)
7 + ? compareSemverVersions(candidate, current) > 0
8 + : candidate !== current;
9 +
10 +/**
11 + * Picks the release a managed installation's `start` downloads. A fresh install
12 + * gets T3 Code's pinned release; an existing one moves to the newest known
13 + * release above it. Null means nothing newer is known, so `start` re-checks the
14 + * installed runtime instead of downgrading it.
15 + */
16 +export function selectManagedRelease<Release extends { readonly version: string }>(
17 + installedVersion: string | null,
18 + pinned: Release | null,
19 + upstream: Release | null,
20 +): Release | null {
21 + if (installedVersion === null) return pinned;
22 + let selected: Release | null = null;
23 + for (const candidate of [pinned, upstream]) {
24 + if (candidate && isNewer(candidate.version, selected?.version ?? installedVersion)) {
25 + selected = candidate;
26 + }
27 + }
28 + return selected;
29 +}
apps/server/src/provider/providerInstallation.test.ts
+2
@@ -95,6 +95,7 @@ const makeHarness = Effect.fn("providerInstallation.test.makeHarness")(function*
95 }),
96 state: Effect.succeed({ ...state, driver: ProviderDriverKind.make("codex") }),
97 changes: Stream.succeed({ ...state, driver: ProviderDriverKind.make("codex") }),
98 + checkForUpdate: Effect.void,
99 remove: (paths) =>
100 Effect.sync(() => {
101 protectedPaths = paths ?? [];
@@ -103,6 +104,7 @@ const makeHarness = Effect.fn("providerInstallation.test.makeHarness")(function*
104 }),
105 Layer.mock(AntigravityInstallation.AntigravityInstallation)({
106 managedDirectory: "/unused-managed-runtime",
107 + checkForUpdate: Effect.void,
108 start: Effect.sync(() => {
109 calls.push("start");
110 return { ...state, operationId: "install-1", phase: "downloading" as const };
apps/server/src/provider/providerInstallation.ts
+12
@@ -186,9 +186,21 @@ const make = Effect.fn("makeProviderInstallation")(function* () {
186 .pipe(Effect.mapError(failure(input.instanceId)));
187 });
188
189 + // Watching an installation is when its owner can act on an update, so the
190 + // lookup runs then, in the background, unless update checks are off.
191 const subscribe = (input: ProviderSetupInput) =>
192 Stream.unwrap(
193 requireInstance(input.instanceId, "observe-install").pipe(
194 + Effect.tap(({ installation }) =>
195 + settings.getSettings.pipe(
196 + Effect.flatMap((current) =>
197 + current.enableProviderUpdateChecks
198 + ? Effect.forkDetach(installation.checkForUpdate)
199 + : Effect.void,
200 + ),
201 + Effect.ignore,
202 + ),
203 + ),
204 Effect.map(({ installation }) => installation.changes),
205 ),
206 );
apps/web/src/components/settings/CodexSetupSection.tsx
+12
@@ -983,6 +983,18 @@ function ManagedCodexSetup({
983 </Button>
984 ) : authenticated ? (
985 <>
986 + {updateAvailable ? (
987 + <Button
988 + size="sm"
989 + variant="outline"
990 + disabled={unavailable || busy}
991 + onClick={() =>
992 + void run(() => startInstall({ environmentId, input: { instanceId } }))
993 + }
994 + >
995 + Update Codex
996 + </Button>
997 + ) : null}
998 <Button
999 size="sm"
1000 variant="outline"
docs/user/install.md
+4
@@ -233,6 +233,10 @@ Cursor and Antigravity update with T3 Code. Homebrew and Chocolatey installs
233 compare against the version their package manager offers, which can trail the
234 npm release; update Claude installed with Chocolatey through Chocolatey.
235
236 +The managed runtimes for Antigravity and for Codex connected through ChatGPT
237 +first install the release T3 Code tested. When T3 Code finds a newer compatible
238 +release, their setup in **Settings → Providers** offers an update.
239 +
240 Add another provider instance for a separate account or configuration. Each
241 instance can have its own environment variables, such as API keys or a custom
242 base URL. Mark secret values as sensitive; after saving, T3 Code does not display
packages/provider-acp-registry/src/server/AcpRegistrySupport.ts
+4 -3
@@ -48,9 +48,10 @@ import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStr
48 import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
49 import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
50
51 -const ACP_REGISTRY_URL = "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json";
51 +export const ACP_REGISTRY_URL =
52 + "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json";
53
53 -const MAX_REGISTRY_BYTES = 1024 * 1024;
54 +export const MAX_REGISTRY_BYTES = 1024 * 1024;
55 const MAX_ARCHIVE_BYTES = 1024 * 1024 * 1024;
56 const MAX_COMMAND_OUTPUT_BYTES = 1024 * 1024;
57 // Archive listings can exceed the output of package-manager commands.
@@ -231,7 +232,7 @@ export type AcpRegistryPlatformTarget =
232 | "windows-aarch64"
233 | "windows-x86_64";
234
234 -function resolveAcpRegistryPlatformTarget(
235 +export function resolveAcpRegistryPlatformTarget(
236 platform: NodeJS.Platform,
237 architecture: NodeJS.Architecture,
238 ): AcpRegistryPlatformTarget | undefined {