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
Open
Conversation
…hen output_item.done is missing (NousResearch#5732)
19 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
openai-codexprovider, the Codex Responses stream emits valid tool-call events (response.function_call_arguments.delta→.done) but the SDK'sget_final_response()returnsoutput=[]. 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.doneevents for function calls, so the existing backfill mechanism (which collectsoutput_item.doneitems) has nothing to work with.Fix
Add a
collected_tool_callsaccumulator that captures complete function call data fromresponse.function_call_arguments.doneevents. Whenget_final_response()returns empty output ANDcollected_output_itemsis empty, fall back to reconstructing the output fromcollected_tool_calls.Applied to both:
_run_codex_stream— primary streaming path viaresponses.stream()_run_codex_create_stream_fallback— fallback path viaresponses.create(stream=True)Priority order for backfill:
output_item.doneevents (existing, preferred)function_call_arguments.doneevents (new fallback)Testing
test_run_codex_stream_backfills_tool_calls_from_function_call_done: verifies tool call reconstructed fromfunction_call_arguments.donewhen nooutput_item.doneemittedtest_run_codex_stream_prefers_output_item_done_over_function_call_done: verifies existing behavior takes precedence when both event types are present_FakeResponsesStreamto accept optionaleventsparameter (backward-compatible)Fixes #5732