From fa3b93ec55df8fbd7f5c4c87db29cff7a5952ef4 Mon Sep 17 00:00:00 2001 From: Timur Sharifianov Date: Mon, 9 Nov 2026 11:15:12 +0100 Subject: [PATCH 1/3] fix(codex): keep the launcher error that precedes an exit summary A provider launcher that wraps the app server prints the actionable failure (for example a DNS or OAuth error) and then a generic "exit status 1" line. The excerpt picked only that last line, so the surfaced error said nothing about what actually failed. Include up to two preceding lines when the selected line is an exit summary, keeping the excerpt bounded at 512 characters. Co-Authored-By: Codex (gpt-6.1-sol) --- .../src/_internal/stdio.test.ts | 30 +++++++++++++++++++ .../src/_internal/stdio.ts | 15 +++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/effect-codex-app-server/src/_internal/stdio.test.ts b/packages/effect-codex-app-server/src/_internal/stdio.test.ts index cde2150ff66fa..e1e151e7a9783 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.test.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.test.ts @@ -166,6 +166,36 @@ describe("Codex App Server stderr excerpt", () => { stderr: "WARNING: proceeding without PATH aliases\nMissing OpenAI API key.\n", excerpt: "Missing OpenAI API key.", }, + { + name: "launcher exit summary after a DNS failure", + stderr: [ + "Starting provider", + 'проверить токен LLM: Get "https://llm-gateway.example/api/models": dial tcp: lookup llm-gateway.example: no such host', + "не удалось отправить метрики на сервер: no such host", + "Ошибка: ошибка запуска плагина: exit status 1", + ].join("\n"), + excerpt: + 'проверить токен LLM: Get "https://llm-gateway.example/api/models": dial tcp: lookup llm-gateway.example: no such host | не удалось отправить метрики на сервер: no such host | Ошибка: ошибка запуска плагина: exit status 1', + }, + { + name: "labelled launcher exit summary after an authentication failure", + stderr: [ + 'oauth2: "invalid_request" "Errors.OIDCSession.RefreshTokenInvalid"', + "Error: provider launcher exited with code 1.", + ].join("\n"), + excerpt: + 'oauth2: "invalid_request" "Errors.OIDCSession.RefreshTokenInvalid" | Error: provider launcher exited with code 1.', + }, + { + name: "launcher summary alone", + stderr: "Error: command failed with exit code 1\n", + excerpt: "Error: command failed with exit code 1", + }, + { + name: "launcher diagnostics remain bounded", + stderr: `${"x".repeat(1_000)}\nError: launcher exited with code 1\n`, + excerpt: `${"x".repeat(511)}…`, + }, { name: "ANSI color, carriage returns and repeated whitespace", stderr: "\u001b[31m Error:\t config.toml is invalid \u001b[0m\r\n", diff --git a/packages/effect-codex-app-server/src/_internal/stdio.ts b/packages/effect-codex-app-server/src/_internal/stdio.ts index a25ac0e6124b3..a260bf7fb887f 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.ts @@ -56,6 +56,7 @@ const STDERR_TAIL_MAX_CHARS = 8_192; const STDERR_EXCERPT_MAX_CHARS = 512; // `Error: …`, `TypeError: …`, `Error [ERR_MODULE_NOT_FOUND]: …`, `error: …`, `ERROR: …`, `fatal: …` const ERROR_LINE_PATTERN = /^(?:[a-z]*error|fatal)(?: ?\[[^\]]+\])?:\s*\S/i; +const EXIT_SUMMARY_PATTERN = /\b(?:exit status|exit code|exited with code)\s+\d+\.?$/i; export const appendStderrTail = (current: string, chunk: string): string => { const next = `${current}${chunk}`; @@ -68,13 +69,19 @@ export const stderrExcerpt = (tail: string): string | undefined => { .split(/\r?\n/) .map((line) => line.trim().replace(/\s+/g, " ")) .filter((line) => line.length > 0); - const line = lines.findLast((candidate) => ERROR_LINE_PATTERN.test(candidate)) ?? lines.at(-1); + const errorIndex = lines.findLastIndex((candidate) => ERROR_LINE_PATTERN.test(candidate)); + const lineIndex = errorIndex === -1 ? lines.length - 1 : errorIndex; + const line = lines[lineIndex]; if (line === undefined) { return undefined; } - return line.length <= STDERR_EXCERPT_MAX_CHARS - ? line - : `${line.slice(0, STDERR_EXCERPT_MAX_CHARS - 1)}…`; + // Wrappers can print the actual failure before their generic exit-status summary. + const excerpt = EXIT_SUMMARY_PATTERN.test(line) + ? lines.slice(Math.max(0, lineIndex - 2), lineIndex + 1).join(" | ") + : line; + return excerpt.length <= STDERR_EXCERPT_MAX_CHARS + ? excerpt + : `${excerpt.slice(0, STDERR_EXCERPT_MAX_CHARS - 1)}…`; }; export const makeStderrTail = Effect.fn("makeStderrTail")(function* ( From 6f91b908a1771cebba823b1744598ef5a3886417 Mon Sep 17 00:00:00 2001 From: Timur Sharifianov Date: Mon, 9 Nov 2026 11:44:57 +0100 Subject: [PATCH 2/3] fix(codex): prefer final launcher exit summaries Select a final exit summary before an earlier error-labelled line so intervening diagnostics remain visible. Add the reproduced DNS failure to the existing excerpt test table. Co-Authored-By: Codex (gpt-6.1-sol) --- .../effect-codex-app-server/src/_internal/stdio.test.ts | 9 +++++++++ packages/effect-codex-app-server/src/_internal/stdio.ts | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/effect-codex-app-server/src/_internal/stdio.test.ts b/packages/effect-codex-app-server/src/_internal/stdio.test.ts index e1e151e7a9783..c3c43f5e58ca9 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.test.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.test.ts @@ -186,6 +186,15 @@ describe("Codex App Server stderr excerpt", () => { excerpt: 'oauth2: "invalid_request" "Errors.OIDCSession.RefreshTokenInvalid" | Error: provider launcher exited with code 1.', }, + { + name: "final launcher summary takes precedence over an earlier error label", + stderr: [ + "Error: starting provider", + "lookup failed: no such host", + "Ошибка: exit status 1", + ].join("\n"), + excerpt: "Error: starting provider | lookup failed: no such host | Ошибка: exit status 1", + }, { name: "launcher summary alone", stderr: "Error: command failed with exit code 1\n", diff --git a/packages/effect-codex-app-server/src/_internal/stdio.ts b/packages/effect-codex-app-server/src/_internal/stdio.ts index a260bf7fb887f..c1a5ca0600ce8 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.ts @@ -70,7 +70,10 @@ export const stderrExcerpt = (tail: string): string | undefined => { .map((line) => line.trim().replace(/\s+/g, " ")) .filter((line) => line.length > 0); const errorIndex = lines.findLastIndex((candidate) => ERROR_LINE_PATTERN.test(candidate)); - const lineIndex = errorIndex === -1 ? lines.length - 1 : errorIndex; + const lineIndex = + errorIndex === -1 || EXIT_SUMMARY_PATTERN.test(lines.at(-1) ?? "") + ? lines.length - 1 + : errorIndex; const line = lines[lineIndex]; if (line === undefined) { return undefined; From 65bc2580b7a709a1f8b14b18d4d8cb2d639fb355 Mon Sep 17 00:00:00 2001 From: Timur Sharifianov Date: Mon, 9 Nov 2026 13:53:32 +0100 Subject: [PATCH 3/3] fix(codex): retain newest diagnostics when truncating excerpts Trim older context from joined launcher excerpts so long preceding lines cannot hide newer diagnostics and the exit summary. The existing bounded-output regression fails before the fix and passes afterward; all 53 package tests and focused lint pass. Co-Authored-By: Codex (gpt-6.1-sol) --- .../effect-codex-app-server/src/_internal/stdio.test.ts | 4 ++-- packages/effect-codex-app-server/src/_internal/stdio.ts | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/effect-codex-app-server/src/_internal/stdio.test.ts b/packages/effect-codex-app-server/src/_internal/stdio.test.ts index c3c43f5e58ca9..dcb00247b36ac 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.test.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.test.ts @@ -202,8 +202,8 @@ describe("Codex App Server stderr excerpt", () => { }, { name: "launcher diagnostics remain bounded", - stderr: `${"x".repeat(1_000)}\nError: launcher exited with code 1\n`, - excerpt: `${"x".repeat(511)}…`, + stderr: `${"x".repeat(1_000)}\noauth2: invalid_request\nError: launcher exited with code 1\n`, + excerpt: `…${`${"x".repeat(1_000)} | oauth2: invalid_request | Error: launcher exited with code 1`.slice(-511)}`, }, { name: "ANSI color, carriage returns and repeated whitespace", diff --git a/packages/effect-codex-app-server/src/_internal/stdio.ts b/packages/effect-codex-app-server/src/_internal/stdio.ts index c1a5ca0600ce8..a047d1aa804d4 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.ts @@ -82,8 +82,11 @@ export const stderrExcerpt = (tail: string): string | undefined => { const excerpt = EXIT_SUMMARY_PATTERN.test(line) ? lines.slice(Math.max(0, lineIndex - 2), lineIndex + 1).join(" | ") : line; - return excerpt.length <= STDERR_EXCERPT_MAX_CHARS - ? excerpt + if (excerpt.length <= STDERR_EXCERPT_MAX_CHARS) { + return excerpt; + } + return excerpt !== line + ? `…${excerpt.slice(-(STDERR_EXCERPT_MAX_CHARS - 1))}` : `${excerpt.slice(0, STDERR_EXCERPT_MAX_CHARS - 1)}…`; };