Skip to content

fix: recover Codex stream final parse TypeError#32891

Closed
ahmertsengol wants to merge 1 commit into
NousResearch:mainfrom
ahmertsengol:fix/codex-stream-final-parse-typeerror
Closed

fix: recover Codex stream final parse TypeError#32891
ahmertsengol wants to merge 1 commit into
NousResearch:mainfrom
ahmertsengol:fix/codex-stream-final-parse-typeerror

Conversation

@ahmertsengol

Copy link
Copy Markdown

Summary

Fixes a Codex streaming edge case where the OpenAI SDK final response parser can raise:

TypeError: 'NoneType' object is not iterable

This was observed with the openai-codex provider against https://chatgpt.com/backend-api/codex. The stream had already produced usable assistant output, but stream.get_final_response() failed while parsing the final response. Hermes then treated the turn as a non-retryable provider/client failure even though output was available.

What changed

  • Adds a recovery path around Codex stream.get_final_response() for the specific NoneType final parse error.
  • If response.output_item.done events were collected, Hermes synthesizes a completed response from those output items.
  • If no output items exist but text deltas were streamed and no tool calls are active, Hermes synthesizes a completed assistant message from the accumulated text deltas.
  • Keeps unrelated TypeErrors unchanged by re-raising them.

Why

The Codex backend can stream valid output items/text before the SDK final parser fails. In that case, dropping the turn is worse than using the already streamed output, especially because the user may see the text but Hermes still marks the request as failed.

Observed log shape:

API call failed (attempt 1/3): TypeError
Provider: openai-codex  Model: gpt-5.5
Endpoint: https://chatgpt.com/backend-api/codex
Error: 'NoneType' object is not iterable
Non-retryable client error: 'NoneType' object is not iterable

After the fix, the same failure mode is logged as a warning and Hermes continues with the collected streamed output.

Tests

  • source venv/bin/activate && python -m pytest tests/run_agent/test_run_agent_codex_responses.py -q
    • 67 passed
  • source venv/bin/activate && python -m pytest tests/run_agent/test_streaming.py tests/run_agent/test_codex_xai_oauth_recovery.py -q
    • 77 passed

@ahmertsengol ahmertsengol force-pushed the fix/codex-stream-final-parse-typeerror branch from da32929 to fa1f970 Compare May 27, 2026 00:25
@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 #32888 and #32890. This PR only fixes codex_runtime.py; #32890 and #32888 also cover auxiliary_client.py.

@ahmertsengol

Copy link
Copy Markdown
Author

I’m happy to either close this as duplicate, or adapt this PR to also cover auxiliary_client.py if maintainers prefer a single consolidated fix. The main value here may be the conversation-level regression coverage; I can move that over if useful.

@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). Thanks for the help during the outage. Closes #11179.

@teknium1 teknium1 closed this May 27, 2026
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.

3 participants