From d6738698fc2f7b4006f2d35a2f1b70e92c9ee43e Mon Sep 17 00:00:00 2001 From: Patrick Schaub Date: Tue, 20 Oct 2026 04:09:10 +0200 Subject: [PATCH 1/4] fix(server): distinguish Codex HTTP failures from filesystem errors --- .../src/provider/CodexInstallation.test.ts | 67 ++++++++++++++++++- apps/server/src/provider/CodexInstallation.ts | 10 +++ 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/apps/server/src/provider/CodexInstallation.test.ts b/apps/server/src/provider/CodexInstallation.test.ts index 849b3c928af8b..c03e9f7c1ba6d 100644 --- a/apps/server/src/provider/CodexInstallation.test.ts +++ b/apps/server/src/provider/CodexInstallation.test.ts @@ -13,7 +13,8 @@ import * as Exit from "effect/Exit"; import * as Queue from "effect/Queue"; import * as Scope from "effect/Scope"; import * as Stream from "effect/Stream"; -import { HttpClient, HttpClientResponse } from "effect/http"; +import { HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse } from "effect/http"; +import * as TestClock from "effect/testing/TestClock"; import { ChildProcess, ChildProcessSpawner } from "effect/process"; import * as CodexInstallation from "./CodexInstallation.ts"; @@ -31,7 +32,8 @@ const makeHarness = Effect.fn("test.makeCodexInstallation")(function* ( input: { options?: Partial; manifestCurrent?: Effect.Effect; - body?: Stream.Stream; + body?: Stream.Stream; + downloadStatus?: number; baseDir?: string; local?: { version: string; appServerFails?: boolean; versionFails?: boolean }; platform?: NodeJS.Platform; @@ -106,7 +108,10 @@ const makeHarness = Effect.fn("test.makeCodexInstallation")(function* ( Effect.sync(() => { downloads++; return Object.defineProperty( - HttpClientResponse.fromWeb(request, new Response(null)), + HttpClientResponse.fromWeb( + request, + new Response(null, { status: input.downloadStatus ?? 200 }), + ), "stream", { value: input.body ?? Stream.succeed(archive), @@ -366,6 +371,62 @@ it.effect("rejects corrupted downloads without publishing a runtime", () => }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), ); +it.effect.each(["interrupted body", "HTTP 404"] as const)( + "reports a download failure for %s without blaming disk access", + (failure) => + Effect.gen(function* () { + const request = HttpClientRequest.get(asset.url); + const response = HttpClientResponse.fromWeb(request, new Response(null)); + const h = yield* makeHarness( + failure === "HTTP 404" + ? { downloadStatus: 404 } + : { + body: Stream.concat( + Stream.succeed(archive.subarray(0, 10)), + Stream.fail( + new HttpClientError.HttpClientError({ + reason: new HttpClientError.DecodeError({ + request, + response, + cause: new TypeError("terminated"), + }), + }), + ), + ), + }, + ); + yield* h.installation.start; + expect(yield* terminalState(h.installation)).toMatchObject({ + phase: "failed", + message: + failure === "HTTP 404" + ? "The Codex download server returned HTTP 404. Try again later." + : "The Codex download was interrupted. Check your internet connection, then retry installation.", + }); + expect(h.downloads()).toBe(1); + expect(yield* h.fs.readDirectory(h.installation.managedDirectory)).toEqual([]); + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), +); + +it.effect( + "preserves the filesystem failure message when installation cannot create its directory", + () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-codex-install-test-" }); + const baseDir = `${directory}/not-a-directory`; + yield* fs.writeFileString(baseDir, "existing file"); + const h = yield* makeHarness({ baseDir }); + yield* h.installation.start; + expect(yield* terminalState(h.installation)).toMatchObject({ + phase: "failed", + message: "Could not install Codex. Check disk space and directory access, then try again.", + }); + expect(h.downloads()).toBe(0); + expect(yield* fs.readFileString(baseDir)).toBe("existing file"); + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), +); + it.effect("cancels an in-flight download and cleans the staging directory", () => Effect.gen(function* () { const downloading = yield* Deferred.make(); diff --git a/apps/server/src/provider/CodexInstallation.ts b/apps/server/src/provider/CodexInstallation.ts index e481f95e3c578..b6b619b61cda6 100644 --- a/apps/server/src/provider/CodexInstallation.ts +++ b/apps/server/src/provider/CodexInstallation.ts @@ -606,6 +606,16 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function yield* activate(); }, Effect.scoped, + Effect.catchTags({ + HttpClientError: (cause) => + installationError( + "download", + cause.reason._tag === "StatusCodeError" + ? `The Codex download server returned HTTP ${cause.reason.response.status}. Try again later.` + : "The Codex download was interrupted. Check your internet connection, then retry installation.", + cause, + ), + }), Effect.mapError( wrapFailure( "install", From 812992d581735f583a21a8d3b1da16ddd40e8015 Mon Sep 17 00:00:00 2001 From: Patrick Schaub Date: Tue, 20 Oct 2026 14:39:33 +0200 Subject: [PATCH 2/4] fix(server): preserve structured Codex download status --- apps/server/src/provider/CodexInstallation.ts | 26 ++++++++++++------- .../src/provider/providerInstallation.ts | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/apps/server/src/provider/CodexInstallation.ts b/apps/server/src/provider/CodexInstallation.ts index b6b619b61cda6..f4a402836380a 100644 --- a/apps/server/src/provider/CodexInstallation.ts +++ b/apps/server/src/provider/CodexInstallation.ts @@ -103,11 +103,14 @@ export class CodexInstallationError extends Schema.TaggedError - installationError( - "download", - cause.reason._tag === "StatusCodeError" - ? `The Codex download server returned HTTP ${cause.reason.response.status}. Try again later.` - : "The Codex download was interrupted. Check your internet connection, then retry installation.", + HttpClientError: (cause) => { + const httpStatus = + cause.reason._tag === "StatusCodeError" ? cause.reason.response.status : undefined; + return new CodexInstallationError({ + operation: "download", + detail: + httpStatus === undefined + ? "The Codex download was interrupted. Check your internet connection, then retry installation." + : "The Codex download server returned an HTTP error. Try again later.", + ...(httpStatus === undefined ? {} : { httpStatus }), cause, - ), + }); + }, }), Effect.mapError( wrapFailure( @@ -662,7 +670,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function message: cancelled ? "Installation cancelled. The previous runtime is unchanged." : Option.isSome(error) - ? error.value.detail + ? error.value.message : "Could not finish the Codex installation. Check disk space and directory access.", } satisfies ProviderInstallState; }) diff --git a/apps/server/src/provider/providerInstallation.ts b/apps/server/src/provider/providerInstallation.ts index 7b4c0bd478abb..7e7271a7f2994 100644 --- a/apps/server/src/provider/providerInstallation.ts +++ b/apps/server/src/provider/providerInstallation.ts @@ -103,7 +103,7 @@ export const makeProviderInstallation = Effect.fn("makeProviderInstallation")(fu | AntigravityInstallation.AntigravityInstallationError | CodexInstallation.CodexInstallationError, ) => - new ProviderSetupError({ instanceId, operation: error.operation, detail: error.detail }); + new ProviderSetupError({ instanceId, operation: error.operation, detail: error.message }); const start = Effect.fn("ProviderInstallation.start")(function* (input: ProviderSetupInput) { const { installation } = yield* requireInstance(input.instanceId, "install", true); From 8f49d00f23b6780b1df1f6f7c1e7135d244cc95b Mon Sep 17 00:00:00 2001 From: Patrick Schaub Date: Tue, 20 Oct 2026 22:07:32 +0200 Subject: [PATCH 3/4] fix(server): report Codex archive download timeouts --- .../src/provider/CodexInstallation.test.ts | 19 +++++++++++++++++++ apps/server/src/provider/CodexInstallation.ts | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/apps/server/src/provider/CodexInstallation.test.ts b/apps/server/src/provider/CodexInstallation.test.ts index c03e9f7c1ba6d..e0683199ffd5f 100644 --- a/apps/server/src/provider/CodexInstallation.test.ts +++ b/apps/server/src/provider/CodexInstallation.test.ts @@ -427,6 +427,25 @@ it.effect( }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), ); +it.effect("reports a download timeout and cleans the staging directory", () => + Effect.gen(function* () { + const started = yield* Deferred.make(); + const stall = Deferred.succeed(started, undefined).pipe(Effect.andThen(Effect.never)); + const h = yield* makeHarness({ + body: Stream.concat(Stream.succeed(archive.subarray(0, 10)), Stream.fromEffect(stall)), + }); + yield* h.installation.start; + yield* Deferred.await(started); + yield* TestClock.adjust("45 minutes"); + expect(yield* terminalState(h.installation)).toMatchObject({ + phase: "failed", + message: "The Codex download timed out. Retry installation.", + }); + expect(h.downloads()).toBe(1); + expect(yield* h.fs.readDirectory(h.installation.managedDirectory)).toEqual([]); + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), +); + it.effect("cancels an in-flight download and cleans the staging directory", () => Effect.gen(function* () { const downloading = yield* Deferred.make(); diff --git a/apps/server/src/provider/CodexInstallation.ts b/apps/server/src/provider/CodexInstallation.ts index f4a402836380a..b542ca8b8cb8b 100644 --- a/apps/server/src/provider/CodexInstallation.ts +++ b/apps/server/src/provider/CodexInstallation.ts @@ -542,6 +542,14 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function ), Stream.run(fs.sink(archivePath, { flag: "wx", mode: 0o600 })), Effect.timeout("45 minutes"), + Effect.catchTags({ + TimeoutError: (cause) => + installationError( + "download", + "The Codex download timed out. Retry installation.", + cause, + ), + }), ); if (downloadedBytes !== release.archiveBytes || hash.digest("hex") !== release.sha256) return yield* installationError( From 17d65e014d7bc14b69594fc81cb20da8b8efabd4 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Mon, 26 Oct 2026 08:54:48 +0000 Subject: [PATCH 4/4] fix(server): simplify Codex download failure details --- apps/server/src/provider/CodexInstallation.ts | 10 +++------- apps/server/src/provider/providerInstallation.ts | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/server/src/provider/CodexInstallation.ts b/apps/server/src/provider/CodexInstallation.ts index 1be85d1239b6e..d63ca93cef80a 100644 --- a/apps/server/src/provider/CodexInstallation.ts +++ b/apps/server/src/provider/CodexInstallation.ts @@ -103,14 +103,11 @@ export class CodexInstallationError extends Schema.TaggedError - new ProviderSetupError({ instanceId, operation: error.operation, detail: error.message }); + new ProviderSetupError({ instanceId, operation: error.operation, detail: error.detail }); const start = Effect.fn("ProviderInstallation.start")(function* (input: ProviderSetupInput) { const { installation } = yield* requireInstance(input.instanceId, "install", true);