Skip to content

fix: finalize Codex sessions without explicit exitCode#614

Open
CoderLuii wants to merge 2 commits intositeboon:mainfrom
CoderLuii:fix/codex-session-finalization
Open

fix: finalize Codex sessions without explicit exitCode#614
CoderLuii wants to merge 2 commits intositeboon:mainfrom
CoderLuii:fix/codex-session-finalization

Conversation

@CoderLuii
Copy link
Copy Markdown

@CoderLuii CoderLuii commented Apr 4, 2026

Summary

  • allow successful complete events without an explicit exitCode to finalize the pending Codex session
  • keep the existing explicit exitCode === 0 behavior unchanged when the field is present

Testing

  • validated in HolyClaude integration flow while reproducing the first-turn Codex session redirect issue

Summary by CodeRabbit

  • Bug Fixes
    • Improved chat session handling to properly finalize sessions in additional scenarios where exit status information is absent or indicates success.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

The complete message handler in the chat realtime hooks was modified to treat msg.exitCode as successful when it is either non-numeric or equals zero, replacing the previous strict check for only 0. This changes when pendingSessionId is cleared and currentSessionId is finalized.

Changes

Cohort / File(s) Summary
Chat Realtime Handlers
src/components/chat/hooks/useChatRealtimeHandlers.ts
Modified the complete message handler condition to consider non-numeric or zero exitCode values as successful, broadening the trigger for clearing pending session state and finalizing navigation.

Poem

🐰 A status code once strict and true,

Now welcomes numbers old and new,

When zero or undefined we see,

Sessions clear in harmony!

A softer touch, yet still we flow,

To destination, swift we go!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: allowing Codex session finalization when no explicit exitCode is provided, which matches the primary modification in the useChatRealtimeHandlers.ts file.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/chat/hooks/useChatRealtimeHandlers.ts`:
- Around line 276-278: The current success detection treats any non-number
exitCode as success (completedSuccessfully = typeof msg.exitCode !== 'number' ||
msg.exitCode === 0), which lets malformed values like "1" or null pass; change
the logic so success is only when exitCode is explicitly absent/undefined or the
numeric value 0—e.g. compute completedSuccessfully by checking (msg.exitCode ===
undefined || (typeof msg.exitCode === 'number' && msg.exitCode === 0)) so that
strings, null, or other malformed payloads do not clear pendingSessionId when
pendingSessionId and !currentSessionId are true.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: aa1b9c80-2a0c-47ff-9123-34d7ef705c4d

📥 Commits

Reviewing files that changed from the base of the PR and between 388134c and 3fc9d5d.

📒 Files selected for processing (1)
  • src/components/chat/hooks/useChatRealtimeHandlers.ts

Comment on lines +276 to +278
const completedSuccessfully = typeof msg.exitCode !== 'number' || msg.exitCode === 0;

if (pendingSessionId && !currentSessionId && completedSuccessfully) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Tighten success detection to avoid false-positive session finalization

On Line 276, typeof msg.exitCode !== 'number' marks all non-numeric values as success. That includes malformed payloads like "1" or null, which can wrongly clear pendingSessionId on Line 278.

Proposed fix
-const completedSuccessfully = typeof msg.exitCode !== 'number' || msg.exitCode === 0;
+const completedSuccessfully = msg.exitCode === undefined || msg.exitCode === 0;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const completedSuccessfully = typeof msg.exitCode !== 'number' || msg.exitCode === 0;
if (pendingSessionId && !currentSessionId && completedSuccessfully) {
const completedSuccessfully = msg.exitCode === undefined || msg.exitCode === 0;
if (pendingSessionId && !currentSessionId && completedSuccessfully) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/chat/hooks/useChatRealtimeHandlers.ts` around lines 276 - 278,
The current success detection treats any non-number exitCode as success
(completedSuccessfully = typeof msg.exitCode !== 'number' || msg.exitCode ===
0), which lets malformed values like "1" or null pass; change the logic so
success is only when exitCode is explicitly absent/undefined or the numeric
value 0—e.g. compute completedSuccessfully by checking (msg.exitCode ===
undefined || (typeof msg.exitCode === 'number' && msg.exitCode === 0)) so that
strings, null, or other malformed payloads do not clear pendingSessionId when
pendingSessionId and !currentSessionId are true.

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.

1 participant