Address Codex review feedback

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex authored and maria-rcks committed 2026-08-03 11:44:56 -04:00
1 parent 4953425822
commit aaae99ec50
5 files changed
+75 -8

No files matched your search

@@ -180,11 +180,12 @@ function normalizeCodexTokenUsage(
}
function toTurnStatus(
value: EffectCodexSchema.V2TurnCompletedNotification["turn"]["status"],
value: EffectCodexSchema.V2TurnCompletedNotification["turn"]["status"] | "cancelled",
): "completed" | "failed" | "cancelled" | "interrupted" {
switch (value) {
case "completed":
case "failed":
case "cancelled":
case "interrupted":
return value;
default:
@@ -171,6 +171,27 @@ describe("isRecoverableThreadResumeError", () => {
false,
);
});
it("ignores unrelated missing-resource errors that do not mention threads", () => {
assert.equal(
isRecoverableThreadResumeError(
new CodexErrors.CodexAppServerRequestError({
code: -32603,
errorMessage: "Config file not found",
}),
),
false,
);
assert.equal(
isRecoverableThreadResumeError(
new CodexErrors.CodexAppServerRequestError({
code: -32603,
errorMessage: "Model does not exist",
}),
),
false,
);
});
});
describe("openCodexThread", () => {
@@ -383,6 +383,9 @@ function classifyCodexStderrLine(rawLine: string): { readonly message: string }
export function isRecoverableThreadResumeError(error: unknown): boolean {
const message = (error instanceof Error ? error.message : String(error)).toLowerCase();
if (!message.includes("thread")) {
return false;
}
return RECOVERABLE_THREAD_RESUME_ERROR_SNIPPETS.some((snippet) => message.includes(snippet));
}
@@ -390,8 +393,17 @@ type CodexThreadOpenResponse =
| CodexRpc.ClientRequestResponsesByMethod["thread/start"]
| CodexRpc.ClientRequestResponsesByMethod["thread/resume"];
type CodexThreadOpenMethod = "thread/start" | "thread/resume";
interface CodexThreadOpenClient {
readonly request: <M extends CodexThreadOpenMethod>(
method: M,
payload: CodexRpc.ClientRequestParamsByMethod[M],
) => Effect.Effect<CodexRpc.ClientRequestResponsesByMethod[M], CodexErrors.CodexAppServerError>;
}
export const openCodexThread = (input: {
readonly client: CodexClient.CodexAppServerClientShape;
readonly client: CodexThreadOpenClient;
readonly threadId: ThreadId;
readonly runtimeMode: RuntimeMode;
readonly cwd: string;
@@ -1288,6 +1300,7 @@ export const makeCodexSessionRuntime = (
requestId,
});
}
const codexAnswers = yield* toCodexUserInputAnswers(answers);
yield* Ref.update(pendingUserInputsRef, (current) => {
const next = new Map(current);
next.delete(requestId);
@@ -1302,7 +1315,7 @@ export const makeCodexSessionRuntime = (
...(pending.turnId ? { turnId: pending.turnId } : {}),
...(pending.itemId ? { itemId: pending.itemId } : {}),
payload: {
answers: yield* toCodexUserInputAnswers(answers),
answers: codexAnswers,
},
});
}),
@@ -121,4 +121,34 @@ it.layer(NodeServices.layer)("effect-codex-app-server client", (it) => {
]);
}),
);
it.effect("initializes a command-backed app-server client", () =>
Effect.gen(function* () {
const path = yield* Path.Path;
const scope = yield* Scope.make();
const clientLayer = CodexClient.layerCommand({
command: "bun",
args: ["run", yield* mockPeerPath],
cwd: path.join(import.meta.dirname, ".."),
});
const context = yield* Layer.buildWithScope(clientLayer, scope);
const initialized = yield* Effect.gen(function* () {
const client = yield* CodexClient.CodexAppServerClient;
return yield* client.request("initialize", {
clientInfo: {
name: "effect-codex-app-server-test",
title: "Effect Codex App Server Test",
version: "0.0.0",
},
capabilities: {
experimentalApi: true,
optOutNotificationMethods: null,
},
});
}).pipe(Effect.provide(context), Effect.ensuring(Scope.close(scope, Exit.void)));
assert.equal(initialized.userAgent, "mock-codex-app-server");
}),
);
});
@@ -281,7 +281,7 @@ export const layerCommand = (
...(options.env ? { env: { ...process.env, ...options.env } } : {}),
shell: process.platform === "win32",
});
const handle = yield* spawner.spawn(command).pipe(
return yield* spawner.spawn(command).pipe(
Effect.mapError(
(cause) =>
new CodexError.CodexAppServerSpawnError({
@@ -290,9 +290,11 @@ export const layerCommand = (
}),
),
);
const client = yield* make(makeChildStdio(handle), options, makeTerminationError(handle));
return { client, handle };
}),
({ handle }) => handle.kill().pipe(Effect.orDie),
).pipe(Effect.map(({ client }) => client)),
(handle) => handle.kill().pipe(Effect.orDie),
).pipe(
Effect.flatMap((handle) =>
make(makeChildStdio(handle), options, makeTerminationError(handle)),
),
),
);