fix(codex): handle SDK TypeError when backend returns output=null - #32939
Closed
HongBoogie wants to merge 1 commit into
Closed
fix(codex): handle SDK TypeError when backend returns output=null#32939HongBoogie wants to merge 1 commit into
HongBoogie wants to merge 1 commit into
Conversation
The ChatGPT Codex backend (chatgpt.com/backend-api/codex) can return `response.output = null` in the `response.completed` SSE event. The OpenAI SDK (v2.32+) crashes with `TypeError: 'NoneType' object is not iterable` in `parse_response()` which iterates `response.output`. This error surfaces both during the `for event in stream:` iteration (inside `accumulate_event()`) and during `get_final_response()`. The agent loop catches it as a non-retryable TypeError, aborting the request entirely — even though the actual response content was already streamed successfully via delta events. Fix: catch TypeError at both levels in `run_codex_stream()` and fall back to manual response assembly from collected `output_item.done` events or accumulated text deltas. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
2 tasks
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.
The ChatGPT Codex backend (chatgpt.com/backend-api/codex) can return response.output = null in the
response.completed SSE event. The OpenAI SDK (v2.32+) crashes with TypeError: 'NoneType' object is not
iterable in parse_response() which iterates response.output.
This error surfaces both during the for event in stream: iteration (inside accumulate_event()) and during
get_final_response(). The agent loop catches it as a non-retryable TypeError, aborting the request
entirely — even though the actual response content was already streamed successfully via delta events.
Fix: catch TypeError at both levels in run_codex_stream() and fall back to manual response assembly from
collected output_item.done events or accumulated text deltas.
What does this PR do?
Fixes a crash where the Codex Responses streaming path raises TypeError: 'NoneType' object is not
iterable when the ChatGPT Codex backend returns response.output = null in the response.completed SSE
event. The OpenAI SDK (v2.32+) does not null-check response.output before iterating it in
parse_response(). This PR catches the TypeError at both the stream iteration and get_final_response()
levels, and falls back to assembling the response from already-collected stream events or text deltas.
Related Issue
None — discovered in production logs (Non-retryable error (HTTP None): 'NoneType' object is not
iterable).
Type of Change
Changes Made
during response.completed event processing
layer
deltas when SDK fails
How to Test
response.completed
Reproduction script:
from openai import OpenAI
client = OpenAI(api_key="<codex_token>", base_url="https://chatgpt.com/backend-api/codex")
with client.responses.stream(model="gpt-5.5", instructions="hi",
input=[{"role":"user","content":"hello"}], store=False) as stream:
for event in stream: # TypeError crashes here on response.completed
pass
Checklist
Code
Documentation & Housekeeping
Screenshots / Logs
Before fix:
⚠️ Non-retryable error (HTTP None) — trying fallback...
❌ Non-retryable error (HTTP None): 'NoneType' object is not iterable
After fix:
DEBUG: Codex stream: SDK TypeError during iteration (response.output=null); will assemble manually.
DEBUG: Codex stream: manually assembled response from 1 output items
Response delivered normally