Skip to content

fix(codex): monkey-patch openai SDK parse_response to handle output=None - #55797

Closed
nicha16 wants to merge 1 commit into
NousResearch:mainfrom
nicha16:fix/codex-parse-response-none
Closed

fix(codex): monkey-patch openai SDK parse_response to handle output=None#55797
nicha16 wants to merge 1 commit into
NousResearch:mainfrom
nicha16:fix/codex-parse-response-none

Conversation

@nicha16

@nicha16 nicha16 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

The OpenAI SDK's parse_response can return None for certain edge cases (non-recoverable stream errors, cancellation mid-parse). Without handling, this propagates as AttributeError: 'NoneType' object has no attribute 'model_dump'.

Adds a monkey-patch in codex_responses_adapter.py that wraps parse_response to return an empty completion instead of None.

Codex backend can return responses with output=None. OpenAI SDK 2.32.0 crashes in parse_response (for output in response.output) before Hermes sees the response. Coerce None to empty list via a Hermes-side import-time monkey-patch. Verified with direct streaming smoke test against Codex.

(cherry picked from commit a00dd04cc0e1b722a655fba835febd737a835f82)
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API duplicate This issue or pull request already exists labels Jun 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #32963 (merged 2026-05-27, "recover Codex Responses streams with null output"). That fix — plus the structural refactor in #33042 — already handles the Codex output=None case in agent/codex_responses_adapter.py; main no longer needs an OpenAI-SDK parse_response monkey-patch. Four earlier PRs taking this same monkey-patch approach (#33173, #32959, #33275, #33553) were closed as duplicates for the same reason.

@teknium1

teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Closing as redundant against current main.

The Codex Responses output=None crash this targets is already fixed by the event-driven rewrite of agent/codex_runtime.py (merged as #32963 and hardened afterward): the main agent loop and the auxiliary client both consume the raw SSE stream via responses.create(stream=True) and assemble the final response from response.output_item.done events, rather than going through the high-level responses.stream(...) / SDK parse_response helper that reads response.completed.response.output. Since we never read that field for content reconstruction, null output can no longer crash us — so monkey-patching the SDK's parse_response is no longer needed on either path.

Thanks for the fix — the approach was sound; the code path it patched just no longer exists on main.

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have 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