fix(codex): route commentary-phase text to the reasoning channel (salvage #58696 + #41343) - #58868
Merged
Conversation
…fixes #41293) GPT-5.x models on the Codex Responses API emit short pre-tool-call "preamble" text as message items with phase="commentary". Previously, _normalize_codex_response() added ALL message items to content_parts regardless of phase, causing commentary text to leak as visible assistant content on chat gateways. Fix: when normalized_phase is "commentary" or "analysis", route the message text to reasoning_parts instead of content_parts. This keeps preamble/internal planning in the reasoning channel where it belongs. Fixes #41293
Follow-up to the salvaged #58696 (devatnull) + #41343 (annguyenNous) commits: instead of fully suppressing commentary/analysis-phase stream deltas, fire on_reasoning_delta so the CLI/gateway display them like thinking text. Matches Codex CLI semantics where commentary is never the turn's final answer, while keeping the narration visible in the reasoning display. Adds devatnull to AUTHOR_MAP.
Collaborator
Maintainer salvage of #58696 (@devatnull) and #41343 (@annguyenNous), with both authorships preserved; Fixes #24933 and #41293. This is the authoritative version of the Codex commentary-phase leak cluster (also related: #21568, #26898). The earlier PRs should be closed in favor of this salvage once merged. |
This was referenced Jul 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Codex Responses
commentary/analysis-phase message text is now routed to the reasoning channel (thinking display) instead of leaking into user-visible assistant content — in both normalized responses and live streaming.Salvages #58696 (@devatnull, broadest coverage: adapter +
output_textfallback + streaming path) and #41343 (@annguyenNous, reasoning-channel destination), cherry-picked with both authorships preserved. Fixes #24933 and #41293.Root cause:
_normalize_codex_response()appended ALL message-item text tocontent_partsregardless ofphase, so GPT-5.x pre-tool-call planning fragments ("Vision.", "Let me inspect the repo first...") were concatenated into final answers or leaked as standalone visible messages on gateways. The streaming path had no phase awareness at all.Design: surveyed reference implementations (Codex CLI, OpenCode, pi) — all treat commentary as mid-turn narration that is never the turn's final answer. Hermes routes it through the reasoning channel so the CLI/gateway display it like thinking text: never counted as final content, never in the
output_textfallback, still visible as narration.Changes
agent/codex_responses_adapter.py: commentary/analysis-phase message text →reasoning_parts(notcontent_parts);output_textfallback skipped for commentary-only responses; raw phase-tagged items still preserved incodex_message_itemsfor replay/prompt-cache continuityagent/codex_runtime.py:_consume_codex_event_stream()tracks the active message item's phase fromresponse.output_item.added; commentary deltas fireon_reasoning_deltainstead ofon_text_deltaand stay out ofoutput_texttests/run_agent/test_run_agent_codex_responses.py: 3 new tests (commentary-delta routing, final_answer passthrough, no output_text fallback) + updated assertionsscripts/release.py: AUTHOR_MAP entry for @devatnullValidation
Targeted suite: 85/85 passing (
tests/run_agent/test_run_agent_codex_responses.py). E2E-verified all five scenarios with real imports.Credits
Infographic