Skip to content

fix(codex): use terminal event response when get_final_response has empty output#6026

Open
dontcallmejames wants to merge 1 commit into
NousResearch:mainfrom
dontcallmejames:fix/codex-stream-terminal-response
Open

fix(codex): use terminal event response when get_final_response has empty output#6026
dontcallmejames wants to merge 1 commit into
NousResearch:mainfrom
dontcallmejames:fix/codex-stream-terminal-response

Conversation

@dontcallmejames

Copy link
Copy Markdown
Contributor

Bug (closes #5883)

GPT-5.4 via openai-codex fails in normal mode with "Empty/malformed response"
but works in verbose mode. The root cause: when
stream.get_final_response() returns an empty output list, the existing
backfill logic (from output_item.done events and text-delta synthesis) can
fail silently in normal mode. However, the terminal stream event
(response.completed) carries a fully-populated response object in
event.response that is never captured.

Fix

  1. Capture event.response for all terminal stream events
    (response.completed, response.incomplete, response.failed).
  2. After get_final_response(), prefer the terminal event's response when
    get_final_response() has empty output but the terminal event carries
    valid output.

This is the same approach as open PR #5720, implemented cleanly against the
current upstream.

Testing

tests/run_agent/test_run_agent_codex_responses.py passes (35 tests).

Closes #5883

…mpty output

When _run_codex_stream() calls stream.get_final_response(), the resulting
response object can have an empty output list even when the stream's terminal
event (response.completed) carried a fully-populated response object.

Capture event.response from terminal stream events and prefer it over
get_final_response() when the latter returns empty output.

Fixes NousResearch#5883
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/openai OpenAI / Codex Responses API labels Apr 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #5720 — same fix for Codex Responses stream empty output fallback. Also related to #5883, #5732.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #5720 — same root cause: Codex Responses stream returns empty output, fix captures terminal event response as fallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPT-5.4 via openai-codex fails in normal mode with 'Empty/malformed response' fallback

2 participants