Skip to content

openai-codex crashes when Codex Responses terminal event has output=null #32974

@xyang199

Description

@xyang199

Issue Title

openai-codex crashes when Codex Responses terminal event has output=null

Issue Body

Summary

When using the openai-codex provider against https://chatgpt.com/backend-api/codex, Hermes can receive usable streamed output, then fail at the terminal response.completed event with:

TypeError: 'NoneType' object is not iterable

This affects both the main Codex runtime path and auxiliary calls such as automatic title generation.

Observed behavior

Main agent call:

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 (HTTP None). Aborting.

Auxiliary title generation:

Auxiliary title generation failed: 'NoneType' object is not iterable

The same issue was also observed with gpt-5.4.

Root cause

The Codex backend streams useful content first, including events such as:

response.output_item.done
response.output_text.delta
response.output_text.done

But the terminal response.completed event can contain a response object where:

response.output = None

openai-python 2.24.0 assumes response.output is iterable while parsing the terminal event:

openai/lib/_parsing/_responses.py, line 61
for output in response.output:
TypeError: 'NoneType' object is not iterable

In one path the exception is raised while iterating the stream. In another path it can be raised by stream.get_final_response(). Hermes already collected streamed output before that terminal parse failure, so the call can be recovered safely when no tool-call ambiguity exists.

Environment

Hermes: 0.14.0
Python: 3.11.15
openai-python: 2.24.0
Provider: openai-codex
Endpoint: https://chatgpt.com/backend-api/codex
Models observed: gpt-5.5, gpt-5.4
OS: Ubuntu 24.04 under WSL

Proposed fix

The patch attached below adds recovery for this null-output terminal event in both places:

  • agent/codex_runtime.py

    • catches TypeError: 'NoneType' object is not iterable
    • recovers from collected_output_items
    • falls back to synthesized text output from streamed text parts when there are no tool calls
  • agent/auxiliary_client.py

    • handles the same null-output case in _CodexCompletionsAdapter
    • covers both failure locations:
      • during for event in stream
      • during stream.get_final_response()
    • treats final.output is None like an empty output list and backfills from collected stream events

Local validation

After applying the patch:

python -m py_compile agent/codex_runtime.py agent/auxiliary_client.py

passed.

Main provider call completed without the non-retryable client error:

hermes -z "Say only OK" --provider openai-codex -m gpt-5.5

Auxiliary title-generation path also completed successfully in a direct local test:

generate_title(...) -> Hermes Title Generation Fix

Patch

Patch file generated from local diff:

hermes-codex-null-output-recovery.patch

The patch changes only:

agent/codex_runtime.py
agent/auxiliary_client.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecodexcomp/agentCore agent loop, run_agent.py, prompt builderduplicateThis issue or pull request already existsprovider/copilotGitHub Copilot (ACP + Chat)type/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions