From 7f8664b6cf6b622bc4e7c360d87e0951ede0b580 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 31 Oct 2026 13:36:49 -0500 Subject: [PATCH] fix(codex-proxy): meaningful fallback for message-less turn.failed + pin string/message-less shapes (#694) Message-less turn.failed on an exit-0 run now reports codex turn failed (turn.failed event carried no error message) instead of the self-contradictory codex exec exited with code 0; nonzero/signal diagnostics unchanged. Tests gain INBANDSTR/INBANDNONE/INBANDOBJ stub modes covering both transports, and startProxy pins the stub via a new CODEX_PROXY_CODEX_BIN env seam so a host-installed codex cannot shadow it. --- bin/codex-proxy.mjs | 7 ++++++- bin/codex-proxy.test.mjs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/bin/codex-proxy.mjs b/bin/codex-proxy.mjs index 7b361c72e2..59e2ec299f 100755 --- a/bin/codex-proxy.mjs +++ b/bin/codex-proxy.mjs @@ -131,6 +131,9 @@ const STATIC_MODELS = [ ]; const findCodexBinary = () => { + // Explicit override first: the test suite points this at its stub so + // a host-installed codex can never shadow it (#694). + if (process.env.CODEX_PROXY_CODEX_BIN) return process.env.CODEX_PROXY_CODEX_BIN; const candidates = [ '/run/current-system/sw/bin/codex', `${process.env.HOME}/.local/bin/codex`, @@ -977,7 +980,9 @@ const runCodexOnce = ({ args, prompt, emit, onSpawn }) => ? spawnError.message : signal ? `codex exec terminated by signal ${signal}` - : `codex exec exited with code ${code}`; + : turnFailedMessage !== null && code === 0 + ? 'codex turn failed (turn.failed event carried no error message)' + : `codex exec exited with code ${code}`; const detail = (turnFailedMessage || stderrLine || fallback).trim(); done({ ok: false, diff --git a/bin/codex-proxy.test.mjs b/bin/codex-proxy.test.mjs index a2cc66456a..753c4e2d83 100644 --- a/bin/codex-proxy.test.mjs +++ b/bin/codex-proxy.test.mjs @@ -7,6 +7,8 @@ // whose behaviour is keyed on markers in the prompt: a run that exits // non-zero used to be reported as a successful 'stop' — empty when it // produced nothing, and carrying the truncated text when it produced +// (startProxy additionally pins the stub via CODEX_PROXY_CODEX_BIN so a +// host-installed codex can never shadow it, #694.) // partial output. import assert from 'node:assert/strict'; import { spawn, execFileSync } from 'node:child_process'; @@ -57,6 +59,15 @@ case "$prompt" in *INBANDFAIL*) printf '%s\\n' '{"type":"turn.failed","error":{"message":"stub codex: model overloaded"}}' exit 0 ;; + *INBANDSTR*) + printf '%s\\n' '{"type":"turn.failed","error":"stub codex: string overload"}' + exit 0 ;; + *INBANDNONE*) + printf '%s\\n' '{"type":"turn.failed"}' + exit 0 ;; + *INBANDOBJ*) + printf '%s\\n' '{"type":"turn.failed","error":{}}' + exit 0 ;; *SIGKILLME*) kill -9 $$ ;; *) @@ -207,6 +218,7 @@ const startProxy = async (reuse, extraEnv = {}, seedHome = null) => { HOME: home, XDG_STATE_HOME: stateHome, CODEX_PROXY_PORT: String(port), + CODEX_PROXY_CODEX_BIN: path.join(home, '.local', 'bin', 'codex'), ...extraEnv }, stdio: ['ignore', 'pipe', 'pipe'] @@ -326,6 +338,24 @@ test('partial output then turn.failed with exit 0: masked success becomes an err await assertFailure(port, 'INBANDPARTIAL', /Codex execution failed: stub codex: run failed midway/); }); +test('turn.failed with a bare-string error: the string is the detail on both transports (#694)', async (t) => { + const { port, stop } = await startProxy(); + t.after(stop); + await assertFailure(port, 'INBANDSTR', /Codex execution failed: stub codex: string overload/); +}); + +test('turn.failed with no error message: fallback names the in-band failure, not exit 0 (#694)', async (t) => { + const { port, stop } = await startProxy(); + t.after(stop); + await assertFailure(port, 'INBANDNONE', /Codex execution failed: codex turn failed \(turn\.failed event carried no error message\)/); + await assertFailure(port, 'INBANDOBJ', /Codex execution failed: codex turn failed \(turn\.failed event carried no error message\)/); + + const plainRes = await post(port, { messages: [{ role: 'user', content: 'please INBANDNONE now' }] }); + assert.equal(plainRes.status, 500); + const plainBody = JSON.parse(await plainRes.text()); + assert.doesNotMatch(plainBody.error.message, /exited with code 0/, 'message-less in-band failure must not blame a successful exit'); +}); + test('empty-stderr fallback names the killing signal, not code null (#676)', async (t) => { const { port, stop } = await startProxy(); t.after(stop);