Skip to content

fix/codex turn failed and model selection#415

Merged
pedramamini merged 1 commit intomainfrom
fix/codex-turn-failed-and-model-selection
Feb 19, 2026
Merged

fix/codex turn failed and model selection#415
pedramamini merged 1 commit intomainfrom
fix/codex-turn-failed-and-model-selection

Conversation

@pedramamini
Copy link
Collaborator

@pedramamini pedramamini commented Feb 19, 2026

  • fix: handle Codex turn.failed errors and add model selection support
  • ## CHANGES

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved error handling for Codex output to properly recognize errors in multiple formats
    • Enhanced error detection consistency and robustness across different error states
    • Strengthened error message normalization for more reliable error reporting

- Codex output parser now handles string-based `turn.failed` errors reliably 🧨
- Centralized error-text extraction for object-or-string Codex error payloads 🧩
- Improved error detection across `error`, `turn.failed`, and generic `error` fields 🔍
- Avoids false matches when JSON contains no useful error message 🚫
- Expanded test coverage for polymorphic Codex error formats to prevent regressions 🧪
@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

The PR refactors error handling in the Codex output parser by introducing a helper function to normalize error text extraction and expanding error detection to handle string-based errors alongside object errors, with corresponding test coverage added.

Changes

Cohort / File(s) Summary
Codex Output Parser Error Handling
src/main/parsers/codex-output-parser.ts, src/__tests__/main/parsers/codex-output-parser.test.ts
Introduces private extractErrorText() helper to normalize error text from string or object formats. Centralizes error text extraction in turn.failed and error message handling. Expands line-based error detection to recognize 'error' and 'turn.failed' types. Tests expanded to verify string error handling returns rate_limited type.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix/codex turn failed and model selection' references the main changes in the PR (turn.failed error handling) but mentions 'model selection' which is not evident in the provided summaries of actual code changes. Clarify whether model selection changes are present in this PR; if not, revise the title to focus solely on 'fix/codex turn failed error handling' to accurately reflect the implemented changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/codex-turn-failed-and-model-selection

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

@greptile-apps
Copy link

greptile-apps bot commented Feb 19, 2026

Greptile Summary

Refactored Codex output parser to improve error handling for turn.failed events by extracting error message logic into a reusable helper function.

Key changes:

  • Introduced extractErrorText() helper to handle Codex's polymorphic error field (string or object with message property)
  • Consolidated duplicate error extraction logic across turn.failed and error message handling
  • Updated detectErrorFromLine() to support both turn.failed and error event types using the same extraction logic
  • Added test coverage for turn.failed with string errors and missing error details scenarios
  • Improved code maintainability by eliminating 3 instances of duplicated error parsing logic

Confidence Score: 5/5

  • Safe to merge - well-structured refactoring with comprehensive test coverage
  • Clean refactoring that extracts duplicate logic into a helper function, maintains backward compatibility, and adds proper test coverage. No logic changes, only improved code organization.
  • No files require special attention

Important Files Changed

Filename Overview
src/main/parsers/codex-output-parser.ts Refactored error message extraction logic by introducing extractErrorText() helper function to handle polymorphic error fields consistently across turn.failed and error message types
src/tests/main/parsers/codex-output-parser.test.ts Added comprehensive test coverage for turn.failed events with string errors and missing error details, plus improved test naming clarity

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Codex JSON Output] --> B{Parse JSON Line}
    B --> C{Message Type?}
    
    C -->|turn.failed| D[extractErrorText]
    C -->|error| D
    C -->|other types| E[Other handlers]
    
    D --> F{Error field type?}
    F -->|object with message| G[Return error.message]
    F -->|string| H[Return error string]
    F -->|undefined/null| I[Return fallback]
    
    G --> J[Create error event]
    H --> J
    I --> J
    
    J --> K[Error Pattern Matching]
    K --> L{Pattern matches?}
    L -->|Yes| M[Return typed AgentError]
    L -->|No| N[Return null]
    
    style D fill:#90EE90
    style J fill:#FFB6C1
    style M fill:#87CEEB
Loading

Last reviewed commit: 8b3077d

@pedramamini pedramamini merged commit 90f0277 into main Feb 19, 2026
2 checks passed
@pedramamini pedramamini deleted the fix/codex-turn-failed-and-model-selection branch February 19, 2026 04:49
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

Comments