Fix Codex Responses streaming crash on null-output snapshots#453
Open
Wondermonger-daydreaming wants to merge 1 commit into
Open
Conversation
The ChatGPT Codex backend (chatgpt.com/backend-api/codex) emits Responses SSE snapshot events with `output=None`. The OpenAI SDK's responses.stream() accumulator calls parse_response() on every event, which iterates `response.output` and raises "'NoneType' object is not iterable" on the very first event of every Codex turn — making the openai-codex provider (i.e. a ChatGPT subscription) unusable. - _run_codex_stream: catch the accumulator TypeError and route to the manual create(stream=True) fallback. Previously only a RuntimeError for the missing-`response.completed` case fell back, so this TypeError aborted. - _run_codex_create_stream_fallback: collect `response.output_item.done` items and reconstruct the terminal response's `.output` via the new _reconstruct_codex_output helper. The Codex backend leaves `.output` None on the terminal event; text/items arrive only via the streamed delta and output_item.done events, so `.output` / `.output_text` must be rebuilt. Verified against a live ChatGPT (Codex) subscription: default model, pinned gpt-5.3-codex, and tool-using turns all return correctly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
Every
gauss chatturn using the openai-codex provider (i.e. a ChatGPT subscription,chatgpt.com/backend-api/codex) aborts immediately with:Root cause
The ChatGPT Codex Responses backend deviates from the public
api.openai.comResponses API:output=None(the public API usesoutput=[]).responses.stream()accumulator callsparse_response()on every event, which doesfor output in response.output:— this raisesTypeError: 'NoneType' object is not iterableon the first event (response.created) of every Codex turn._run_codex_streamonly falls back on aRuntimeError(missingresponse.completed), so thisTypeErrorpropagates and the request is treated as a non-retryable client error..outputNoneon the terminalresponse.completedevent — the completed items arrive only viaresponse.output_item.done, and text only viaresponse.output_text.delta. So even the manual fallback returned a response whose.output/.output_textaccess crashed downstream.Note: this is a backend deviation, not documented OpenAI behavior — bumping the
openaiSDK does not fix it, and guarding the SDK'sparse_responseyields empty text (the accumulator has no populatedoutputto merge deltas onto).Fix
Two surgical changes in
run_agent.py:_run_codex_stream— catch the accumulatorTypeErrorand route to the existing manualcreate(stream=True)fallback._run_codex_create_stream_fallback— collectresponse.output_item.doneitems during iteration and reconstruct the terminal response's.outputvia a new_reconstruct_codex_output()helper (no-op when.outputis already populated, so non-Codex Responses backends are unaffected).Verification
Tested against a live ChatGPT (Codex) subscription:
gpt-5.3-codexEach path previously failed with the
TypeError; all now return correctly.