@devries-cameron20 / t3code Mirror · read-only / commits / 5e222be59a
Fork 0

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 22, 12:00 UTC

fix(server): stop reporting Codex HTTP failures as disk errors (#22308)

Co-authored-by: maria-rcks <maria@kuuro.net>

Patrick Schaub committed Oct 30, 2026 at 21:39 UTC 5e222be59ad0b657650c7286c189a9624bdda392
2 files changed +105 -3
apps/server/src/provider/CodexInstallation.test.ts
+83 -3
@@ -13,7 +13,8 @@ import * as Exit from "effect/Exit";
13 import * as Queue from "effect/Queue";
14 import * as Scope from "effect/Scope";
15 import * as Stream from "effect/Stream";
16 -import { HttpClient, HttpClientResponse } from "effect/http";
16 +import { HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse } from "effect/http";
17 +import * as TestClock from "effect/testing/TestClock";
18 import { ChildProcess, ChildProcessSpawner } from "effect/process";
19 import * as CodexInstallation from "./CodexInstallation.ts";
20
@@ -31,7 +32,8 @@ const makeHarness = Effect.fn("test.makeCodexInstallation")(function* (
32 input: {
33 options?: Partial<CodexInstallation.CodexInstallationOptions>;
34 manifestCurrent?: Effect.Effect<ModelManifest.ModelManifestData>;
34 - body?: Stream.Stream<Uint8Array>;
35 + body?: Stream.Stream<Uint8Array, HttpClientError.HttpClientError>;
36 + downloadStatus?: number;
37 baseDir?: string;
38 local?: { version: string; appServerFails?: boolean; versionFails?: boolean };
39 platform?: NodeJS.Platform;
@@ -106,7 +108,10 @@ const makeHarness = Effect.fn("test.makeCodexInstallation")(function* (
108 Effect.sync(() => {
109 downloads++;
110 return Object.defineProperty(
109 - HttpClientResponse.fromWeb(request, new Response(null)),
111 + HttpClientResponse.fromWeb(
112 + request,
113 + new Response(null, { status: input.downloadStatus ?? 200 }),
114 + ),
115 "stream",
116 {
117 value: input.body ?? Stream.succeed(archive),
@@ -366,6 +371,81 @@ it.effect("rejects corrupted downloads without publishing a runtime", () =>
371 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
372 );
373
374 +it.effect.each(["interrupted body", "HTTP 404"] as const)(
375 + "reports a download failure for %s without blaming disk access",
376 + (failure) =>
377 + Effect.gen(function* () {
378 + const request = HttpClientRequest.get(asset.url);
379 + const response = HttpClientResponse.fromWeb(request, new Response(null));
380 + const h = yield* makeHarness(
381 + failure === "HTTP 404"
382 + ? { downloadStatus: 404 }
383 + : {
384 + body: Stream.concat(
385 + Stream.succeed(archive.subarray(0, 10)),
386 + Stream.fail(
387 + new HttpClientError.HttpClientError({
388 + reason: new HttpClientError.DecodeError({
389 + request,
390 + response,
391 + cause: new TypeError("terminated"),
392 + }),
393 + }),
394 + ),
395 + ),
396 + },
397 + );
398 + yield* h.installation.start;
399 + expect(yield* terminalState(h.installation)).toMatchObject({
400 + phase: "failed",
401 + message:
402 + failure === "HTTP 404"
403 + ? "The Codex download server returned HTTP 404. Try again later."
404 + : "The Codex download was interrupted. Check your internet connection, then retry installation.",
405 + });
406 + expect(h.downloads()).toBe(1);
407 + expect(yield* h.fs.readDirectory(h.installation.managedDirectory)).toEqual([]);
408 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
409 +);
410 +
411 +it.effect(
412 + "preserves the filesystem failure message when installation cannot create its directory",
413 + () =>
414 + Effect.gen(function* () {
415 + const fs = yield* FileSystem.FileSystem;
416 + const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-codex-install-test-" });
417 + const baseDir = `${directory}/not-a-directory`;
418 + yield* fs.writeFileString(baseDir, "existing file");
419 + const h = yield* makeHarness({ baseDir });
420 + yield* h.installation.start;
421 + expect(yield* terminalState(h.installation)).toMatchObject({
422 + phase: "failed",
423 + message: "Could not install Codex. Check disk space and directory access, then try again.",
424 + });
425 + expect(h.downloads()).toBe(0);
426 + expect(yield* fs.readFileString(baseDir)).toBe("existing file");
427 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
428 +);
429 +
430 +it.effect("reports a download timeout and cleans the staging directory", () =>
431 + Effect.gen(function* () {
432 + const started = yield* Deferred.make<void>();
433 + const stall = Deferred.succeed(started, undefined).pipe(Effect.andThen(Effect.never));
434 + const h = yield* makeHarness({
435 + body: Stream.concat(Stream.succeed(archive.subarray(0, 10)), Stream.fromEffect(stall)),
436 + });
437 + yield* h.installation.start;
438 + yield* Deferred.await(started);
439 + yield* TestClock.adjust("45 minutes");
440 + expect(yield* terminalState(h.installation)).toMatchObject({
441 + phase: "failed",
442 + message: "The Codex download timed out. Retry installation.",
443 + });
444 + expect(h.downloads()).toBe(1);
445 + expect(yield* h.fs.readDirectory(h.installation.managedDirectory)).toEqual([]);
446 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
447 +);
448 +
449 it.effect("cancels an in-flight download and cleans the staging directory", () =>
450 Effect.gen(function* () {
451 const downloading = yield* Deferred.make<void>();
apps/server/src/provider/CodexInstallation.ts
+22
@@ -546,6 +546,14 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
546 ),
547 Stream.run(fs.sink(archivePath, { flag: "wx", mode: 0o600 })),
548 Effect.timeout("45 minutes"),
549 + Effect.catchTags({
550 + TimeoutError: (cause) =>
551 + installationError(
552 + "download",
553 + "The Codex download timed out. Retry installation.",
554 + cause,
555 + ),
556 + }),
557 );
558 if (downloadedBytes !== release.archiveBytes || hash.digest("hex") !== release.sha256)
559 return yield* installationError(
@@ -612,6 +620,20 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
620 yield* activate();
621 },
622 Effect.scoped,
623 + Effect.catchTags({
624 + HttpClientError: (cause) => {
625 + const httpStatus =
626 + cause.reason._tag === "StatusCodeError" ? cause.reason.response.status : undefined;
627 + return new CodexInstallationError({
628 + operation: "download",
629 + detail:
630 + httpStatus === undefined
631 + ? "The Codex download was interrupted. Check your internet connection, then retry installation."
632 + : `The Codex download server returned HTTP ${httpStatus}. Try again later.`,
633 + cause,
634 + });
635 + },
636 + }),
637 Effect.mapError(
638 wrapFailure(
639 "install",