Skip to content

fix(codex): recover from null terminal stream output#32888

Closed
glesperance wants to merge 1 commit into
NousResearch:mainfrom
glesperance:fix/codex-null-output-stream
Closed

fix(codex): recover from null terminal stream output#32888
glesperance wants to merge 1 commit into
NousResearch:mainfrom
glesperance:fix/codex-null-output-stream

Conversation

@glesperance

Copy link
Copy Markdown
Contributor

Rationale

OpenAI Codex/ChatGPT backend streams can emit usable output through response.output_item.done, then finish with a response.completed payload whose response.output is null. The OpenAI Python SDK raises TypeError: 'NoneType' object is not iterable while parsing that terminal event, so Hermes loses the already-streamed answer and shows an error instead.

Summary

  • Recover run_codex_stream() from the exact SDK terminal parse error when collected stream output or text deltas are available.
  • Apply the same recovery path to the auxiliary Codex chat-completions adapter, covering calls like automatic title generation.
  • Add regression coverage for both the main Codex stream path and auxiliary adapter without invoking fallback when stream output is recoverable.

Test Plan

  • uv run pytest tests/run_agent/test_run_agent_codex_responses.py tests/agent/test_auxiliary_client.py::TestCodexAdapterReasoningTranslation -q
  • uv run ruff check agent/codex_runtime.py agent/auxiliary_client.py tests/run_agent/test_run_agent_codex_responses.py tests/agent/test_auxiliary_client.py
  • git diff --check -- agent/codex_runtime.py agent/auxiliary_client.py tests/run_agent/test_run_agent_codex_responses.py tests/agent/test_auxiliary_client.py

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder provider/openai OpenAI / Codex Responses API P2 Medium — degraded but workaround exists labels May 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #32884 (same root cause: Codex Responses stream null output, #11179). Also competing with #32890 and #32891. All four PRs fix codex_runtime.py for the same SDK TypeError: 'NoneType' object is not iterable; #32888 and #32890 also fix auxiliary_client.py.

@ligolnik

Copy link
Copy Markdown

Tested. Confirms the fix.

Cherry-picked your commit (32a19b11c) onto Hermes v0.14.0 (main at 30928f945 from May 25) running against the official chatgpt.com/backend-api/codex endpoint with gpt-5.5. Same Telegram session that had been failing repeatedly with 'NoneType' object is not iterable on long-thread + post-compression turns is now landing the model's reply cleanly.

The dual-path coverage matters: I had been seeing agent.context_compressor: Failed to generate context summary fire on the same TypeError ~5s before the main-path failure (so the bug breaks the compressor's own LLM call too, not just conversation_loop). PRs that only patch codex_runtime.py would still let the secondary failure through. Including auxiliary_client.py in this fix means both paths recover.

Runtime evidence:

  • from agent.codex_runtime import run_codex_stream clean
  • from agent.auxiliary_client import ... clean
  • ✅ The 3 added regression tests pass under pytest -k 'null or recover'
  • ✅ End-to-end: a follow-up turn on the previously-broken Telegram session completed with the right answer (QB Time tool call + summary), no more Non-retryable client error in agent.log

This is one of 8 racing PRs for the same bug. Of the dual-path fixes (yours, #32890, #11182), yours has the smallest diff (+158/-15 vs +250/-62 and the 4-month-stale #11182). Cleanest path to merge IMO.

Will run for a day; will report back if anything regresses. Thanks for shipping this fast.

@teknium1

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants