Chat Completions streaming can emit function calls with an empty call_id - #4560
Chat Completions streaming can emit function calls with an empty call_id#4560ojassharma7 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c737aa3d72
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| else: | ||
| # Function call was not streamed (fallback to old behavior) | ||
| # This handles edge cases where function name never arrived | ||
| cls._validate_completed_tool_call(function_call.call_id, function_call.name) |
There was a problem hiding this comment.
Preserve usage before rejecting the malformed call
When an unbuffered stream reports CompletionUsage and then ends with a missing call ID or function name, this new validation raises while the usage remains only in handle_stream()'s local variable. OpenAIChatCompletionsModel.stream_response() catches ModelBehaviorError and populates its generation span from the base response (openai_chatcompletions.py lines 508-512), which has not received that usage, so the failed request and its tokens disappear from tracing. Copy the built usage and raw-usage snapshot to response—or mark the request completed when usage is absent—before raising.
AGENTS.md reference: AGENTS.md:L167-L167
Useful? React with 👍 / 👎.
Fixes #4553.
What changed
src/agents/models/chatcmpl_stream_handler.pytests/models/test_openai_chatcompletions_stream.pyVerification
The project's own test suite was run before and after this change; it introduces no new test failures or lint violations.