fix(agent): guard openai parse_response against null response.output - #33579
Closed
marcelopaniza wants to merge 1 commit into
Closed
fix(agent): guard openai parse_response against null response.output#33579marcelopaniza wants to merge 1 commit into
marcelopaniza wants to merge 1 commit into
Conversation
The ChatGPT consumer Codex backend (chatgpt.com/backend-api/codex) intermittently emits response.completed events with response.output = null (gpt-5.5, May 2026). openai==2.24.0 lib/_parsing/_responses.py:61 iterates response.output without a None guard, raising "TypeError: 'NoneType' object is not iterable" mid-stream. agent/codex_runtime.py already sidesteps the bug structurally by consuming the raw event stream -- but any caller still on the high-level responses.stream() / responses.parse() helpers (third-party plugins, future provider profiles, regressions) is exposed. This adds a small defensive wrapper around parse_response in agent/_openai_compat.py, installed on `import agent`. It coerces a None response.output to [] before delegating to the original function. Becomes a no-op once openai-python ships a guarded release. Refs: openai/openai-python#3322, NousResearch#3316, NousResearch#3286. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
|
Thanks for this — closing as already fixed on The Codex null-output crash (
Your fix targets the same path that's now hardened upstream, so there's nothing left to merge here. Your authorship is preserved in your branch; I'm crediting your report in the umbrella issue #33932 (now closed). Appreciate the contribution. |
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.
Why
0.14.0crashes onchatgpt.com/backend-api/codexwithTypeError: 'NoneType' object is not iterablewhen the backend returnsresponse.output: null. Tracked in #33578.agent/codex_runtime.pyonmainis already structurally immune — it never readsresponse.completed.response.outputfor content. But any caller still on the high-levelresponses.stream(...)/responses.parse(...)helpers (third-party plugins, future provider profiles, regressions) remains exposed to the same SDK bug as long asopenai==2.24.0is pinned.What
agent/_openai_compat.py— wrapsopenai.lib._parsing._responses.parse_response. If the incomingresponse.output is None, it's coerced to[]before delegating to the original function. The wrapper re-binds the symbol in the two SDK modules that imported it by name (openai.lib.streaming.responses._responses,openai.resources.responses.responses) so already-loaded code paths pick up the guard.agent/__init__.py— imports_openai_compatso installation happens on first agent use, before any provider profile is exercised.tests/agent/test_openai_compat.py— three tests: module importable, guard active on the canonical symbol, streaming/resource modules use the guarded reference.Scope
_hermes_or_empty_guardflag on the function).None → [], which the fixed parser also accepts.agent/codex_runtime.py— main's structural fix stays the primary defense.Test
→ 263 passed locally (
Python 3.14.4/openai==2.24.0).Refs: #33578, openai/openai-python#3322, openai/openai-python#3316, openai/openai-python#3286.
🤖 Generated with Claude Code