Skip to content

Commit 908872c

Browse files
committed
fix(codex): retain isolated setup diagnostics
1 parent 6f60f31 commit 908872c

3 files changed

Lines changed: 51 additions & 7 deletions

File tree

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,8 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
829829
),
830830
);
831831

832-
const managedState = Effect.fn("CodexInstallation.managedState")(function* (
833-
current: ProviderInstallState,
834-
) {
832+
// These projections run for every download-progress emission; avoid a span per update.
833+
const managedState = Effect.fnUntraced(function* (current: ProviderInstallState) {
835834
if (current.source !== "local") return current;
836835
const executable = yield* resolveManaged().pipe(Effect.option);
837836
return {
@@ -858,9 +857,7 @@ export const makeCodexInstallation = Effect.fn("makeCodexInstallation")(function
858857
changes: SubscriptionRef.changes(state).pipe(Stream.mapEffect(managedState)),
859858
remove,
860859
};
861-
const automaticState = Effect.fn("CodexInstallation.automaticState")(function* (
862-
current: ProviderInstallState,
863-
) {
860+
const automaticState = Effect.fnUntraced(function* (current: ProviderInstallState) {
864861
if (current.source !== "managed") return current;
865862
const local = yield* resolveLocal();
866863
return local

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as Effect from "effect/Effect";
55
import * as FileSystem from "effect/FileSystem";
66
import * as Layer from "effect/Layer";
77
import * as Path from "effect/Path";
8+
import * as PlatformError from "effect/PlatformError";
9+
import * as Result from "effect/Result";
810
import * as Schema from "effect/Schema";
911
import * as Stream from "effect/Stream";
1012
import * as ServerConfig from "../config.ts";
@@ -114,6 +116,49 @@ it.effect(
114116
yield* fs.readFileString(path.join(userHome, "sessions", "normal.jsonl")),
115117
"normal history",
116118
);
119+
const installationFailure = new CodexInstallation.CodexInstallationError({
120+
operation: "resolve",
121+
detail: "Install the separate runtime first.",
122+
});
123+
const homeFailure = new PlatformError.PlatformError(
124+
new PlatformError.SystemError({
125+
_tag: "PermissionDenied",
126+
module: "FileSystem",
127+
method: "makeDirectory",
128+
}),
129+
);
130+
for (const acquireFails of [true, false]) {
131+
const result = yield* makeCodexIsolatedRuntime({
132+
instanceId: ProviderInstanceId.make("codex-failure"),
133+
config,
134+
environment: {},
135+
}).pipe(
136+
Effect.flatMap((runtime) => runtime.resolve),
137+
Effect.provide(
138+
Layer.mock(CodexInstallation.CodexInstallation)({
139+
managedDirectory: managed.managedDirectory,
140+
managed: Effect.succeed({
141+
...managed,
142+
acquire: acquireFails ? () => Effect.fail(installationFailure) : managed.acquire,
143+
}),
144+
}),
145+
),
146+
Effect.provideService(FileSystem.FileSystem, {
147+
...fs,
148+
makeDirectory: () => Effect.fail(homeFailure),
149+
}),
150+
Effect.result,
151+
Effect.scoped,
152+
);
153+
assert.isTrue(Result.isFailure(result));
154+
if (Result.isFailure(result)) {
155+
assert.strictEqual(
156+
result.failure.cause,
157+
acquireFails ? installationFailure : homeFailure,
158+
);
159+
}
160+
assert.equal(leases, 0);
161+
}
117162
}).pipe(
118163
Effect.provide(
119164
Layer.mock(CodexInstallation.CodexInstallation)({

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ export const makeCodexIsolatedRuntime = Effect.fn("makeCodexIsolatedRuntime")(fu
4141
instanceId: options.instanceId,
4242
operation: "runtime",
4343
detail: cause.detail,
44+
cause,
4445
}),
4546
),
4647
);
4748
yield* fs.makeDirectory(homePath, { recursive: true, mode: 0o700 }).pipe(
4849
Effect.mapError(
49-
() =>
50+
(cause) =>
5051
new ProviderSetupError({
5152
instanceId: options.instanceId,
5253
operation: "runtime",
5354
detail: "Could not prepare the separate Codex home.",
55+
cause,
5456
}),
5557
),
5658
);

0 commit comments

Comments
 (0)