Skip to content

Chat Completions streaming can emit function calls with an empty call_id - #4560

Closed
ojassharma7 wants to merge 1 commit into
openai:mainfrom
ojassharma7:fix/issue-4553
Closed

Chat Completions streaming can emit function calls with an empty call_id#4560
ojassharma7 wants to merge 1 commit into
openai:mainfrom
ojassharma7:fix/issue-4553

Conversation

@ojassharma7

Copy link
Copy Markdown
Contributor

Fixes #4553.

What changed

  • src/agents/models/chatcmpl_stream_handler.py
  • tests/models/test_openai_chatcompletions_stream.py

Verification

The project's own test suite was run before and after this change; it introduces no new test failures or lint violations.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@seratch seratch added the wontfix This will not be worked on label Aug 21, 2026
@seratch seratch closed this Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat Completions streaming can emit function calls with an empty call_id

2 participants