Skip to content

fix(codex): recover from SDK none-output iterator crash - #33279

Closed
ahmadashfq wants to merge 2 commits into
NousResearch:mainfrom
ahmadashfq:ahmad/codex-none-output-guard
Closed

fix(codex): recover from SDK none-output iterator crash#33279
ahmadashfq wants to merge 2 commits into
NousResearch:mainfrom
ahmadashfq:ahmad/codex-none-output-guard

Conversation

@ahmadashfq

Copy link
Copy Markdown
Contributor

Summary

Fix the remaining openai-codex streamed Responses crash when the OpenAI SDK
raises TypeError: 'NoneType' object is not iterable after chatgpt.com
returns a terminal snapshot with response.output = null.

This supersedes the old branch-level fix in #33138. That PR targeted the
pre-agent/codex_runtime.py layout; the current mainline still hits the same
SDK iterator crash because responses.create(stream=True) continues to run the
SDK accumulator while yielding events.

Fixes #33237.

What changed

  • recover inside agent/codex_runtime._consume_codex_event_stream() when the
    SDK iterator raises the null-output TypeError after streamed
    response.output_item.done / response.output_text.delta events already
    arrived
  • preserve tool-call turns as well as plain-text turns by synthesizing the
    final response from the streamed state already collected before the crash
  • apply the same protection to auxiliary Codex calls automatically, because
    they share _consume_codex_event_stream()
  • replace misleading HTTP None fallback messaging with the actual exception
    class and summarized error text (TypeError, etc.)

Why this is still needed after the raw-event migration

The current code correctly avoids reconstructing content from
response.completed.response.output, but the OpenAI SDK's streamed iterator
still performs its own accumulator work internally while we iterate over
responses.create(stream=True). That means the SDK can still throw the
null-output TypeError after Hermes has already received valid streamed
items. The right Hermes-side fix is therefore to recover from the streamed
state instead of assuming raw iteration is structurally immune.

Verification

Ran locally with the project venv:

  • ./venv/bin/python -m pytest tests/run_agent/test_run_agent_codex_responses.py -k 'null_output or none_output_typeerror'
  • ./venv/bin/python -m pytest tests/agent/test_auxiliary_client.py -k 'NullOutputRecovery or none_output_typeerror'
  • ./venv/bin/python -m pytest tests/run_agent/test_run_agent.py -k 'nonretryable_error_kind'

All passed.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API codex P3 Low — cosmetic, nice to have labels May 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Late duplicate of merged #32963 which already adds TypeError recovery for Codex response.output=None in codex_runtime.py. See also #33083, #33050, #33040 (same late-arriving fix).

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for this — closing as already fixed on main.

The Codex null-output crash (response.completed with output: null from the chatgpt.com backend → TypeError: 'NoneType' object is not iterable → surfaced as "non-retryable HTTP None") is resolved by commits already on main:

  • cb38ce28c — drop the SDK responses.stream() helper and consume events directly, rebuilding output from response.output_item.done events so the null terminal-event output is never iterated (refactor(codex): drop SDK responses.stream() helper; consume events directly #33042).
  • 43a3f119f — recover Codex streams with null output.
  • dc9d677d5 — classify TypeError('NoneType … not iterable') as a retryable provider-shape error so retry/fallback runs instead of killing the turn.

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.

@teknium1 teknium1 closed this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have provider/openai OpenAI / Codex Responses API type/bug Something isn't working

Projects

None yet

3 participants