fix(codex): recover from response.completed with output=null on chatgpt.com backend - #32901
Closed
brennonatal wants to merge 1 commit into
Closed
fix(codex): recover from response.completed with output=null on chatgpt.com backend#32901brennonatal wants to merge 1 commit into
brennonatal wants to merge 1 commit into
Conversation
…pt.com backend
The chatgpt.com/backend-api/codex backend intermittently sends
`response.completed` SSE events whose `response.output` field is `null`
(observed on gpt-5.5). The OpenAI SDK's `parse_response()` then does
`for output in response.output:` and raises `TypeError: 'NoneType' object
is not iterable`. The outer conversation loop classifies that as a
non-retryable local validation error and aborts the turn, even though
every text delta was already streamed to us.
`run_codex_stream` now catches that specific `TypeError` and recovers by
synthesizing a response from the deltas / output items it already
collected — the same backfill the post-stream path runs when
`get_final_response()` returns an empty output list. When nothing was
collected it falls back to `run_codex_create_stream_fallback`, matching
how the existing `RuntimeError("Expected to have received
\`response.completed\`")` branch already handles broken Responses
backends.
Also: log a full traceback in `conversation_loop` when an API call fails
with `TypeError`/`ValueError` (excluding `UnicodeEncodeError` /
`json.JSONDecodeError`, which are handled elsewhere). These are
local-validation-class errors that almost always indicate a bug in our
request building or in the upstream SDK's response parsing — without the
traceback this exact bug was undiagnosable from the logs.
1 task
|
Can confirm this fixes my local repro with gpt-5.5/openai-codex. Thanks for the patch. |
This was referenced May 27, 2026
|
Confirmed on another Hermes gateway setup. Environment:
Before patch:
Validation:
This matches the root cause described here: the Codex backend can send terminal |
Contributor
|
Closing as duplicate — the Codex null-output fix has been merged via #32963 (cherry-picked from @carltonawong's PR #32890, the one Gille reviewed). Thanks for jumping on the outage so quickly; appreciate the help. Closes #11179. |
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
The chatgpt.com/backend-api/codex endpoint intermittently sends
response.completedSSE events whoseresponse.outputfield isnull(observed on gpt-5.5, May 2026). The OpenAI SDK 2.24.0'sparse_response()then doesfor output in response.output:atopenai/lib/_parsing/_responses.py:61and raises:The outer conversation loop classifies that as a non-retryable local-validation error and aborts the turn. The user sees a generic "I encountered an error" message instead of the model's actual answer — even though every text delta was already streamed to us and accumulated in
agent._codex_streamed_text_parts.Existing protection in
run_codex_streamfor empty-output responses only runs afterstream.get_final_response()returns. The TypeError fires insidefor event in stream:(during theresponse.completedaccumulation), so the post-stream backfill never gets a chance.Changes
agent/codex_runtime.py:run_codex_stream— catch the specificTypeError: 'NoneType' object is not iterablefromparse_response()and recover by synthesizing a response from the deltas/items already collected (same shape as the existing post-stream backfill). When nothing was collected, fall back to_run_codex_create_stream_fallback— mirrors how the existingRuntimeError(\"Expected to have received \response.completed`")` branch handles broken Responses backends like xAI OAuth, codex-lb relays, and custom Responses relays.agent/conversation_loop.py— when an API call fails withTypeError/ValueError(excludingUnicodeEncodeError/json.JSONDecodeError, which are handled elsewhere), log the full traceback viaexc_info=. Without this the original bug was undiagnosable from the logs — only the one-line summary'NoneType' object is not iterablereachederrors.log, with no stack frame to point atparse_response.tests/run_agent/test_codex_stream_null_output_recovery.py— three regression tests:completedresponse with the assembled text._run_codex_create_stream_fallback.TypeErrormessages still propagate (so we don't mask real bugs).Test plan
scripts/run_tests.sh tests/run_agent/test_codex_stream_null_output_recovery.py— 3 passedscripts/run_tests.sh tests/run_agent/test_codex_xai_oauth_recovery.py tests/agent/test_codex_ttfb_watchdog.py tests/run_agent/test_run_agent_codex_responses.py— 105 passed, no regressions in adjacent Codex paths'NoneType' object is not iterablenow succeeds and emits the newCodex response.completed had output=null; recovered from N collected items / M text deltaswarning inagent.log.Notes
response.completedwithoutput=nullin the first place — worth reporting to OpenAI separately. The OpenAI SDK could also defensively handle this case inparse_response().exc_infochange is small but worth keeping — it catches an entire class of failures (any future SDK-side iteration bug, request-building bug, or backend payload-shape regression) that would otherwise reacherrors.logwith no traceback.