Skip to content

Commit 8f49d00

Browse files
committed
fix(server): report Codex archive download timeouts
1 parent 812992d commit 8f49d00

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎apps/server/src/provider/CodexInstallation.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,25 @@ it.effect(
427427
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
428428
);
429429

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+
430449
it.effect("cancels an in-flight download and cleans the staging directory", () =>
431450
Effect.gen(function* () {
432451
const downloading = yield* Deferred.make<void>();

‎apps/server/src/provider/CodexInstallation.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
542542
),
543543
Stream.run(fs.sink(archivePath, { flag: "wx", mode: 0o600 })),
544544
Effect.timeout("45 minutes"),
545+
Effect.catchTags({
546+
TimeoutError: (cause) =>
547+
installationError(
548+
"download",
549+
"The Codex download timed out. Retry installation.",
550+
cause,
551+
),
552+
}),
545553
);
546554
if (downloadedBytes !== release.archiveBytes || hash.digest("hex") !== release.sha256)
547555
return yield* installationError(

0 commit comments

Comments
 (0)