Skip to content

fix(codex-proxy): report failed codex runs as errors, not successful stops - #677

Merged
dezren39 merged 1 commit into
mainfrom
creator/676-codex-proxy-failure
Oct 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
creator/676-codex-proxy-failure

Conversation

@dezren39

@dezren39 dezren39 commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #676

The close handler in bin/codex-proxy.mjs ignored the child's exit code and signal and did not track stderr, so a failed codex exec run was reported as a successful stop — HTTP 200 with empty content when nothing was produced, and HTTP 200 carrying truncated text when partial output preceded the failure. Stream mode likewise ended with a stop chunk + [DONE].

Fix (mirrors the muse-proxy #670/#672 pattern):

  • Track a stderrTail (last 2000 chars) and any spawn error.
  • On close, code !== 0 is a failure regardless of content produced: non-stream returns 500 with Codex execution failed: <last stderr line | spawn error | signal | exit code>; stream mode writes a data:-framed error event + data: [DONE] and no chunk claims finish_reason: stop.
  • Successful (exit 0) runs are unchanged.

Tests: new bin/codex-proxy.test.mjs with a stub codex at $HOME/.local/bin/codex — success (both modes), FAILME (no output, exit 3), FAILPARTIAL (partial item.completed, exit 3), SIGKILLME (empty-stderr signal fallback). Local: 19/19 across codex-proxy + muse-proxy + proxy-port suites. Ablation: with the proxy fix reverted, exactly the 3 new failure tests fail (1 pass / 3 fail); restored, all pass.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Failed Codex executions now return an error instead of appearing successful, including when partial output was produced.
    • Error details are included in responses when available, based on diagnostic output or the process exit status.
    • Streaming responses now include an error event and a completion marker; non-streaming responses return an HTTP 500 when possible.
  • Tests
    • Added coverage for successful requests and execution failures, including partial output and forced termination.

@dezren39
dezren39 requested a review from a team as a code owner October 23, 2026 18:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T18:20:50.919458Z a0a1b07 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0c4aa262-581a-4602-ae90-7d0b61f2bf6c
📥 Commits

Reviewing files that changed from the base of the PR and between d8bfe7c and a0a1b07.

📒 Files selected for processing: 2
  • bin/codex-proxy.mjs
  • bin/codex-proxy.test.mjs
+---------------------------------------------+
| You shall not pass...without a code review! |
+---------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0a1b07747

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bin/codex-proxy.test.mjs
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'codex-proxy-test-'));
const home = path.join(tmp, 'home');
fs.mkdirSync(path.join(home, '.local', 'bin'), { recursive: true });
fs.writeFileSync(path.join(home, '.local', 'bin', 'codex'), STUB, { mode: 0o755 });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Force the proxy test to select its stub

On the NixOS hosts configured by this repository, latestCli.codex is installed system-wide (nixos/environment/default.nix:407), while findCodexBinary() checks /run/current-system/sw/bin/codex before $HOME/.local/bin/codex (bin/codex-proxy.mjs:93-101). Therefore, changing HOME and writing this stub does not isolate the test: it invokes the real authenticated Codex binary, potentially making paid/network calls and causing these assertions to fail or hang. Add an injectable binary override or otherwise ensure the proxy selects the stub.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codex-proxy: a failed codex run is reported as a successful 'stop' — close handler ignores exit code and signal in both modes

1 participant