fix: include exitCode on Codex completion events#879
Conversation
📝 WalkthroughWalkthrough
ChangesAbort-aware Completion Signaling
Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/openai-codex.js (1)
313-320:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDon’t emit
exitCode: 0for aborted sessions.At Line 313–320 an abort only breaks the stream loop, but Line 356 still sends
kind: 'complete'withexitCode: 0. That marks aborted runs as success and bypasses the client’s aborted-complete path (msg.aborted). Please branch completion payload by abort state (for example:aborted: true, non-zeroexitCode, and non-completedstop reason for aborted runs).Also applies to: 356-363
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server/openai-codex.js` around lines 313 - 320, The abort checks at lines 313-320 break the stream loop when an abort is detected, but the completion payload sent at lines 356-363 unconditionally includes `kind: 'complete'` with `exitCode: 0`, which marks the run as successful. Track whether an abort occurred during the stream loop (by detecting either abortController.signal.aborted or session status being aborted), and then at lines 356-363 conditionally construct the completion payload based on this abort state. For aborted runs, set `aborted: true`, use a non-zero `exitCode`, and use a non-`completed` stop reason instead of the normal success completion payload.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@server/openai-codex.js`:
- Around line 313-320: The abort checks at lines 313-320 break the stream loop
when an abort is detected, but the completion payload sent at lines 356-363
unconditionally includes `kind: 'complete'` with `exitCode: 0`, which marks the
run as successful. Track whether an abort occurred during the stream loop (by
detecting either abortController.signal.aborted or session status being
aborted), and then at lines 356-363 conditionally construct the completion
payload based on this abort state. For aborted runs, set `aborted: true`, use a
non-zero `exitCode`, and use a non-`completed` stop reason instead of the normal
success completion payload.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fa74b8f6-8f79-40a1-bbc2-248856740c9a
📒 Files selected for processing (1)
server/openai-codex.js
Successful Codex completions now include an explicit success exit code. Aborted streams skip the normal success completion path, and persisted Codex turn completions normalize the same field. Constraint: abort-session already emits the aborted complete payload Rejected: Emit a second aborted complete from queryCodex | duplicate terminal messages Confidence: high Scope-risk: narrow Tested: node --check server/openai-codex.js; git diff --check; npm ci Tested: npm run typecheck; npm run build; provider normalization check Not-tested: live Codex abort against upstream service
164f039 to
b1b6e36
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/openai-codex.js (1)
405-410:⚠️ Potential issue | 🟠 Major | ⚡ Quick winFailure paths are being finalized as completed status
Line 409 still maps all non-aborted terminal states to
'completed'. WhenterminalFailureis set (for example afterturn.failed), this creates a contradictory lifecycle: failure notifications are emitted, but session state says completed.Use an explicit failed state in finalization.
Suggested fix
- session.status = wasAborted || session.status === 'aborted' ? 'aborted' : 'completed'; + session.status = wasAborted || session.status === 'aborted' + ? 'aborted' + : terminalFailure + ? 'failed' + : 'completed';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server/openai-codex.js` around lines 405 - 410, The session status finalization logic in the activeCodexSessions update block only accounts for aborted states and defaults all other terminal states to completed, which contradicts failure notifications. Modify the conditional assignment for session.status to check for terminalFailure in addition to wasAborted, and assign a failed status when terminalFailure is true, an aborted status when wasAborted or session.status is already aborted, and completed status otherwise. This ensures the session lifecycle is consistent between the emitted failure notifications and the recorded status.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@server/openai-codex.js`:
- Around line 405-410: The session status finalization logic in the
activeCodexSessions update block only accounts for aborted states and defaults
all other terminal states to completed, which contradicts failure notifications.
Modify the conditional assignment for session.status to check for
terminalFailure in addition to wasAborted, and assign a failed status when
terminalFailure is true, an aborted status when wasAborted or session.status is
already aborted, and completed status otherwise. This ensures the session
lifecycle is consistent between the emitted failure notifications and the
recorded status.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8923e5e5-e930-4766-91a7-e34ccb1b6db0
📒 Files selected for processing (2)
server/modules/providers/list/codex/codex-sessions.provider.tsserver/openai-codex.js
|
Hey @CoderLuii, thanks for the update. I completely revamped the websocket logic and this issue should be completely resolved now. As a result, I'm closing this PR. Lmk if the issue still occurs tho. |
|
@blackmammoth thanks for the websocket rewrite. I checked current The current live path still lets
I verified that sequence with a small registry probe: first send the Codex-normalized The smallest fix I see is to keep live Codex No need to reopen this PR if you would rather handle it as a small follow-up. I just wanted to flag that current |
Summary
exitCode: 0to successful Codexcompleteevents.exitCode: 0to Codexturn_completeprovider normalization so live and history paths agree.actualSessionId,sessionId, and provider fields unchanged for successful completions.Context
Codex was the only provider sending the final successful
completeevent without an explicit success exit code. This is the server-side version of the session finalization problem discussed in #614 and CoderLuii/HolyClaude#19.This supersedes #614. Current
mainalready handles session replacement throughactualSessionId; this PR makes the provider lifecycle payload consistent at the source.Abort handling stays separate from success handling. The abort request path already sends an aborted
completepayload for client cleanup, soqueryCodexnow avoids sending a second normal success completion after an aborted stream.Testing
node --check server/openai-codex.jsgit diff --checknpm cicompleted; npm audit reported 38 existing advisoriesnpm run typechecknpm run buildpassed with existing CSS/chunk/Browserslist warningsCodexSessionsProviderturn_completenormalization check returnedkind: completewithexitCode: 0Not live-tested: live Codex abort against the upstream service.
Summary by CodeRabbit
Release Notes
Bug Fixes
0) to completion payloads to make stream termination clearer.Chores