Skip to content

Fix Codex stream handling when final response output is empty#5720

Open
misery-hl wants to merge 1 commit into
NousResearch:mainfrom
misery-hl:fix-codex-stream-empty-output
Open

Fix Codex stream handling when final response output is empty#5720
misery-hl wants to merge 1 commit into
NousResearch:mainfrom
misery-hl:fix-codex-stream-empty-output

Conversation

@misery-hl

Copy link
Copy Markdown
Contributor

Problem

Hermes can fail on gpt-5.4 / Codex Responses streams with:

Invalid API response: response.output is empty

This can happen even on very small prompts, and leads Hermes to retry as if the provider returned a malformed or rate-limited response.

Root cause

In _run_codex_stream(), Hermes already tries several recovery paths:

  • stream.get_final_response()
  • response.output_item.done
  • synthesized output from streamed text deltas

However, it does not recover the final response object attached to terminal stream events like response.completed.

If the provider/backend returns the usable final payload on event.response, while get_final_response() returns an object with output=[], Hermes currently treats that as an invalid response and retries.

Fix

  • capture event.response for terminal stream events
  • prefer that terminal response when get_final_response() has empty output
  • add regression coverage for this response shape

User impact

This avoids false malformed/rate-limit retries on gpt-5.4 / Codex Responses streams and restores expected behavior for affected sessions.

Test coverage

Adds a regression test for the case where:

  • the stream emits response.completed with a valid response
  • get_final_response() returns output=[]
  • Hermes should use the terminal event response instead of rejecting it

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent loop, run_agent.py, prompt builder provider/openai OpenAI / Codex Responses API labels Apr 30, 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 P1 High — major feature broken, no workaround 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.

2 participants