Skip to content

fix(codex): render reasoning summaries from both CLI output shapes#1078

Merged
jSydorowicz21 merged 1 commit into
rcfrom
fix/codex-thinking-windows
Jun 6, 2026
Merged

fix(codex): render reasoning summaries from both CLI output shapes#1078
jSydorowicz21 merged 1 commit into
rcfrom
fix/codex-thinking-windows

Conversation

@jSydorowicz21
Copy link
Copy Markdown
Contributor

@jSydorowicz21 jSydorowicz21 commented Jun 6, 2026

@-

Summary by CodeRabbit

Bug Fixes

  • Enhanced parser handling of reasoning content from Codex responses with support for multiple data formats and structures.
  • Improved event streaming for reasoning summaries with proper text formatting and robust fallback behavior when content is unavailable, encrypted, or blank.
  • Better compatibility with both legacy and modern reasoning data formats.

Codex emits the reasoning `summary` field in two shapes depending on CLI
version: a plain `string[]` (older app-server) and an
`Array<{ type: 'summary_text', text }>` (newer Responses API). The parser
previously dropped every reasoning payload to a non-displayable `system`
event, so the model's thinking was never shown for either shape.

Add `extractReasoningSummaryText()` to normalize both shapes into display
text, emit it as partial reasoning text (run through `formatReasoningText`),
and fall back to a `system` event only when there is no plain-text summary
(encrypted_content only, or blank strings). Covered by four new parser tests.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 6, 2026

PR changed again? Review this PR in Change Stack to compare snapshots and stay oriented.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ab04c2e0-beaa-48f2-b39f-bc4810e6521d

📥 Commits

Reviewing files that changed from the base of the PR and between b7c9c5f and 28dde6d.

📒 Files selected for processing (2)
  • src/__tests__/main/parsers/codex-output-parser.test.ts
  • src/main/parsers/codex-output-parser.ts

📝 Walkthrough

Walkthrough

The PR extends the Codex output parser to properly handle and emit reasoning summaries from response items. It adds a helper function to normalize reasoning text from multiple payload shapes and updates the parser to emit text events marked as reasoning-specific, or fall back to system events when no displayable summary is available.

Changes

Reasoning Summary Extraction

Layer / File(s) Summary
Reasoning summary extraction and event emission
src/main/parsers/codex-output-parser.ts
New extractReasoningSummaryText() helper normalizes reasoning summaries from legacy string[] and object-array Responses API shapes, returning empty string when no displayable text exists. transformResponseItem uses this helper to emit a text event with isPartial: true, isReasoning: true when summary is present, or skips to system fallback when empty.
Reasoning summary parsing test coverage
src/__tests__/main/parsers/codex-output-parser.test.ts
Updated reasoning test verifies summary: string[] form as partial text with isReasoning: true. Added test for object-array shape using summary_text entries. Added fallback tests confirming system event when payload contains only encrypted_content or only blank strings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A reasoning mind now speaks its case,
with summaries parsed from every place,
from strings and shapes both old and new,
the Codex parser knows what's true. ✨
When thoughts run empty, systems chime,
in partial text, one thought at a time. 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: fixing the rendering of reasoning summaries from both CLI output shapes, which matches the core intent of normalizing Codex summary data handling.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/codex-thinking-windows

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.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 6, 2026

Greptile Summary

This PR fixes reasoning-summary rendering so both the older string[] shape (app-server) and the newer Array<{ type: 'summary_text'; text: string }> shape (Responses API) are surfaced as text/isReasoning events rather than silent system events. When neither shape yields displayable text (e.g. only encrypted_content is present), the code correctly falls back to a system event.

  • Adds extractReasoningSummaryText, a module-level helper that accepts unknown, guards both array shapes, skips blank entries, and returns an empty string for the fallback path.
  • Updates transformResponseItem to call the helper and only emit a reasoning text event when content is actually available.
  • Adds four new test cases that cover the string[], object-array, encrypted-only, and blank-strings scenarios.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to the reasoning payload branch of the parser, with no impact on other event types.

The new helper is well-guarded (unknown input, explicit Array.isArray check, per-entry type narrowing, blank-string filtering), the fallback to a system event is preserved for encrypted-only payloads, and four targeted test cases verify each code path. No existing behaviour is removed.

No files require special attention.

Important Files Changed

Filename Overview
src/main/parsers/codex-output-parser.ts Adds extractReasoningSummaryText helper that handles both string[] and summary_text object array shapes; wires it into transformResponseItem to emit a text/isReasoning event instead of a system event when displayable content is found.
src/tests/main/parsers/codex-output-parser.test.ts Expands the reasoning-type test block with four cases: string[] shape, summary_text object shape, encrypted_content-only fallback, and blank-strings fallback. All assertions are consistent with the new logic.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["response_item (payload.type = reasoning)"] --> B["extractReasoningSummaryText(payload.summary)"]
    B --> C{"Array.isArray and length > 0?"}
    C -- No --> D["return empty string"]
    C -- Yes --> E["Iterate entries"]
    E --> F{"string entry?"}
    F -- "Yes, non-blank" --> H["push entry"]
    F -- "Yes, blank" --> E
    F -- No --> I{"object entry?"}
    I -- "type=summary_text, non-blank" --> K["push obj.text"]
    I -- No --> E
    H --> E
    K --> E
    E --> L["parts.join newline then trim"]
    L --> M{"summaryText truthy?"}
    D --> M
    M -- Yes --> N["formatReasoningText(summaryText)"]
    N --> O["return type=text, isReasoning=true"]
    M -- No --> P["return type=system"]
Loading

Reviews (1): Last reviewed commit: "fix(codex): render reasoning summaries f..." | Re-trigger Greptile

@pedramamini
Copy link
Copy Markdown
Collaborator

Thanks for the contribution, @jSydorowicz21! 🙏

I reviewed the change along with the CodeRabbit and Greptile passes, and this looks great:

  • Tightly scoped to the reasoning branch of transformResponseItem, with no impact on other event types.
  • Both CLI shapes handled cleanly via the new extractReasoningSummaryText helper: the legacy string[] (app-server) form and the newer Array<{ type: 'summary_text'; text }> (Responses API) form.
  • Solid guarding for unknown input, blank-string filtering, and the encrypted_content-only fallback that preserves the previous system-event behavior.
  • Reuses the existing formatReasoningText helper rather than re-rolling formatting, consistent with the adjacent streaming path.
  • Four targeted tests cover the string[], object-array, encrypted-only, and blank-string cases.

CodeRabbit reported no actionable comments and Greptile scored it 5/5 "safe to merge." No merge conflicts against rc. Approving. ✅

@jSydorowicz21 jSydorowicz21 merged commit 13ff437 into rc Jun 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants