Skip to content

fix: backfill Codex stream output from function_call_arguments.done when output_item.done is missing (#5732)#5935

Open
r266-tech wants to merge 1 commit into
NousResearch:mainfrom
r266-tech:fix/issue-5732
Open

fix: backfill Codex stream output from function_call_arguments.done when output_item.done is missing (#5732)#5935
r266-tech wants to merge 1 commit into
NousResearch:mainfrom
r266-tech:fix/issue-5732

Conversation

@r266-tech

Copy link
Copy Markdown
Contributor

Problem

When using openai-codex provider, the Codex Responses stream emits valid tool-call events (response.function_call_arguments.delta.done) but the SDK's get_final_response() returns output=[]. Hermes treats this as an empty response and falls back to the secondary model, even though the stream contained valid tool call data.

The root cause is a provider-side inconsistency: the ChatGPT Codex backend sometimes does not emit response.output_item.done events for function calls, so the existing backfill mechanism (which collects output_item.done items) has nothing to work with.

Fix

Add a collected_tool_calls accumulator that captures complete function call data from response.function_call_arguments.done events. When get_final_response() returns empty output AND collected_output_items is empty, fall back to reconstructing the output from collected_tool_calls.

Applied to both:

  1. _run_codex_stream — primary streaming path via responses.stream()
  2. _run_codex_create_stream_fallback — fallback path via responses.create(stream=True)

Priority order for backfill:

  1. output_item.done events (existing, preferred)
  2. function_call_arguments.done events (new fallback)
  3. Text delta synthesis (existing, for text-only turns)

Testing

  • test_run_codex_stream_backfills_tool_calls_from_function_call_done: verifies tool call reconstructed from function_call_arguments.done when no output_item.done emitted
  • test_run_codex_stream_prefers_output_item_done_over_function_call_done: verifies existing behavior takes precedence when both event types are present
  • Updated _FakeResponsesStream to accept optional events parameter (backward-compatible)

Fixes #5732

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists 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 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.

[Bug]: Codex Responses stream completes with empty output after tool-call events, forcing fallback

2 participants