Skip to content

Commit e026556

Browse files
saphidclaude
authored andcommitted
fix(server): failed Codex text generation shows Codex's error, not the echoed prompt
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f6503f0 commit e026556

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎apps/server/src/textGeneration/CodexTextGeneration.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,36 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
310310
),
311311
);
312312

313+
it.effect("reports Codex's final error instead of its banner and echoed prompt", () =>
314+
withFakeCodexEnv(
315+
{
316+
output: "",
317+
exitCode: 1,
318+
stderr: [
319+
"OpenAI Codex v0.160.0",
320+
"--------",
321+
"user",
322+
"Remove default shapes from characters",
323+
"ERROR: Reconnecting... 5/5",
324+
"ERROR: unexpected status 401 Unauthorized: Missing bearer authentication",
325+
].join("\n"),
326+
},
327+
(textGeneration) =>
328+
Effect.gen(function* () {
329+
const error = yield* textGeneration
330+
.generateBranchName({
331+
cwd: process.cwd(),
332+
message: "Remove default shapes from characters",
333+
modelSelection: DEFAULT_TEST_MODEL_SELECTION,
334+
})
335+
.pipe(Effect.flip);
336+
expect(error.detail).toBe(
337+
"Codex CLI command failed: unexpected status 401 Unauthorized: Missing bearer authentication",
338+
);
339+
}),
340+
),
341+
);
342+
313343
it.effect("keeps plugins and apps off over launch args that turn them on", () =>
314344
withFakeCodexEnv(
315345
{

‎apps/server/src/textGeneration/CodexTextGeneration.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,13 @@ export const makeCodexTextGeneration = Effect.fn("makeCodexTextGeneration")(func
334334
);
335335

336336
if (exitCode !== 0) {
337-
const stderrDetail = stderr.trim();
337+
// Codex echoes its banner and the whole prompt to stderr before reporting the error.
338+
const stderrLines = stderr.trim().split("\n");
339+
const lastErrorLine = stderrLines.findLastIndex((line) => line.startsWith("ERROR: "));
340+
const stderrDetail =
341+
lastErrorLine === -1
342+
? stderr.trim()
343+
: stderrLines.slice(lastErrorLine).join("\n").slice("ERROR: ".length);
338344
const stdoutDetail = stdout.trim();
339345
const detail = stderrDetail.length > 0 ? stderrDetail : stdoutDetail;
340346
return yield* new TextGenerationError({

0 commit comments

Comments
 (0)