Title: codex-proxy: a turn.failed event with exit 0 is reported as a successful 'stop' — #677 judged failure by exit code only, no terminal-event check · Issue #680 · developing-today/code · GitHub
Open Graph Title: codex-proxy: a turn.failed event with exit 0 is reported as a successful 'stop' — #677 judged failure by exit code only, no terminal-event check · Issue #680 · developing-today/code
X Title: codex-proxy: a turn.failed event with exit 0 is reported as a successful 'stop' — #677 judged failure by exit code only, no terminal-event check · Issue #680 · developing-today/code
Description: Finding PR #677 fixed bin/codex-proxy.mjs judging failure only by the child's exit code (code !== 0 in the close handler, bin/codex-proxy.mjs:412 on main 4b85ef69). But codex exec --json also reports failure in-band: it emits a {"type":"...
Open Graph Description: Finding PR #677 fixed bin/codex-proxy.mjs judging failure only by the child's exit code (code !== 0 in the close handler, bin/codex-proxy.mjs:412 on main 4b85ef69). But codex exec --json also repor...
X Description: Finding PR #677 fixed bin/codex-proxy.mjs judging failure only by the child's exit code (code !== 0 in the close handler, bin/codex-proxy.mjs:412 on main 4b85ef69). But codex exec --json also r...
Opengraph URL: https://github.com/developing-today/code/issues/680
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"codex-proxy: a turn.failed event with exit 0 is reported as a successful 'stop' — #677 judged failure by exit code only, no terminal-event check","articleBody":"## Finding\n\nPR #677 fixed `bin/codex-proxy.mjs` judging failure **only by the child's exit code** (`code !== 0` in the `close` handler, `bin/codex-proxy.mjs:412` on main `4b85ef69`). But `codex exec --json` also reports failure **in-band**: it emits a `{\"type\":\"turn.failed\",\"error\":{\"message\": …}}` event for a fatal error during a turn, and that event can arrive on a run that **exits 0**. The proxy's event parser (`processJsonLine`, `bin/codex-proxy.mjs:340-380`) handles only `item.completed` and `turn.completed` — `turn.failed` is silently ignored, so an exit-0 failed turn is still reported as a successful `stop`:\n\n- no output before the failure → HTTP 200, empty content, `finish_reason: \"stop\"` (non-stream) / a bare `stop` chunk + `[DONE]` (stream)\n- partial output before the failure → HTTP 200 carrying the truncated text as a clean `stop` (both modes)\n\nThat is exactly the masked-failure shape #676 fixed for the exit-code half — and exactly the shape `bin/muse-proxy.mjs` already guards against by judging failure from the run's authoritative terminal event first and the exit code second (`failed = terminalState ? terminalState !== 'completed' : code !== 0`, the #672/#673 pattern PR #677's body says it mirrors). The codex half of that pattern — the event-state half — is missing.\n\nExit 0 does not rule out a failed turn for codex: other codex providers explicitly check for turn-failure events on exit 0 (e.g. the codex-cli AI SDK provider's exit-code logic: \"0 | Success | Check for turn failure events; return results if none\", with a dedicated event-based error-detection pass for \"failures that may not manifest as non-zero exit codes\"), and headless-codex guidance is to fail on a `turn.failed` event rather than trust the exit code. `turn.failed` (`TurnFailedEvent { error }`, \"on fatal error during a turn\") is part of the documented `codex exec --json` event protocol.\n\nNote on scope: top-level `{\"type\":\"error\", …}` events also exist in the protocol, but some are transient reconnect notices; this issue only requires the unambiguous `turn.failed` case. Whether to treat non-reconnect `error` events as failures is a judgement call for the implementer.\n\n## Evidence (reproduced on current main `4b85ef6906a25c1a59694c64986cb17828b6c2b6`)\n\nRan the real `bin/codex-proxy.mjs` (pristine copy from `origin/main`) with a stub `codex` at `$HOME/.local/bin/codex` (the proxy's own binary resolution):\n\n- Stub prints `{\"type\":\"turn.failed\",\"error\":{\"message\":\"stub codex: model overloaded\"}}`, exits 0:\n - non-stream → **200**, `content: \"\"`, `finish_reason: \"stop\"`\n - stream → **200**, one `finish_reason: \"stop\"` chunk, then `data: [DONE]` — no error anywhere\n- Stub prints an `item.completed` agent_message (`partial answer`), then `{\"type\":\"turn.failed\",\"error\":{\"message\":\"stub codex: run failed midway\"}}`, exits 0:\n - non-stream → **200**, `content: \"partial answer\"`, `finish_reason: \"stop\"`\n - stream → **200**, the `partial answer` chunk, then a `finish_reason: \"stop\"` chunk + `[DONE]`\n- Control ( `item.completed` + `turn.completed`, exit 0) → 200 with the full text and `stop` in both modes, unchanged.\n- The existing suites pass on the same main: `node --test bin/codex-proxy.test.mjs bin/muse-proxy.test.mjs` → 10/10 — no existing test emits `turn.failed`.\n\nSource PR: #677 (`fix(codex-proxy): report failed codex runs as errors, not successful stops`, fixes #676, commit `a0a1b077`, merge `4b85ef69`). Its failure predicate is the single line `if (code !== 0)` at `bin/codex-proxy.mjs:412`; nothing in the PR's new `bin/codex-proxy.test.mjs` covers an in-band failure event.\n\nDedup: searches for `turn.failed` across all issues (open + closed) return nothing; `codex-proxy failed` returns only #676 (closed, the exit-code half), #670 (muse-proxy streaming), #496 and the open #678 (agy-proxy's separate exit-code masking — a different proxy and a different mechanism; this finding is codex-only). The `bin/codex-proxy.mjs` bridge exists only in this repo.\n\n## Why it matters\n\nClients of the proxy (opencode's codex provider) cannot distinguish a failed codex turn from a successful empty or short answer: a rate-limited, overloaded, or otherwise fatally failed turn presents as a clean `stop`, so callers accept truncated/empty output instead of surfacing an error or retrying — the same silent-corruption failure mode #670/#672/#676 were filed and fixed for.\n\n## Acceptance criteria\n\n- [ ] `bin/codex-proxy.mjs` tracks a `turn.failed` event during the run; on `close`, a run that emitted `turn.failed` is reported as a failure even when the exit code is 0: non-stream returns HTTP 500 with `Codex execution failed: \u003cthe turn.failed error message>` (falling back to stderr/signal/exit-code detail when the event carries no message), and stream mode writes a `data:`-framed error event + `data: [DONE]` with no chunk claiming `finish_reason: \"stop\"` — mirroring the existing #677 error framing.\n- [ ] Partial output followed by `turn.failed` + exit 0 is an error in both modes, not a 200 `stop` carrying the truncated text.\n- [ ] Successful runs (exit 0, `turn.completed`, no `turn.failed`) are unchanged in both modes.\n- [ ] New stub modes in `bin/codex-proxy.test.mjs` pin the no-output and partial-output `turn.failed` + exit-0 shapes in both modes; ablating only the `turn.failed` check fails exactly those new tests, and the full codex-proxy + muse-proxy + proxy-port suites pass.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-23T18:42:06Z","url":"https://github.com/developing-today/code/issues/680"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:20ff9dda-adbf-2d59-8b1f-7a7a9270b13b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D80E:23E430:AA55AE:DC22B9:6B06373F |
| html-safe-nonce | de080a33097cda64c97a26819dc635477400b5cd9066d84a8b2194af94ffccf9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODBFOjIzRTQzMDpBQTU1QUU6REMyMkI5OjZCMDYzNzNGIiwidmlzaXRvcl9pZCI6IjcyMTI5Mjk2OTc4NTA0Njg0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 36c79f5e71cd42c6ffd9b40767bd75c01b5bcfc40e03fee710fe70d9fd83895f |
| hovercard-subject-tag | issue:6003542310 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/680/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4eb5e8d060b877f03967649c1d76234eb02e5256d2994393441126c79b17c76b/developing-today/code/issues/680 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4eb5e8d060b877f03967649c1d76234eb02e5256d2994393441126c79b17c76b/developing-today/code/issues/680 |
| og:image:alt | Finding PR #677 fixed bin/codex-proxy.mjs judging failure only by the child's exit code (code !== 0 in the close handler, bin/codex-proxy.mjs:412 on main 4b85ef69). But codex exec --json also repor... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | c3584c853cd39700ecff6e2cf8364295ffdb5313e571046c41cd2479270f7df0 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9eb3bb1597d09170a5f282cd38ae376dee1a5ec1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width