Python: drop hosted MCP calls when reasoning is stripped#6210
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds handling for a replay scenario where reasoning content is stripped (when not using service-side storage) by also dropping the paired hosted-MCP tool call/result to avoid emitting invalid item sequences to the OpenAI API.
Changes:
- Add a unit test that asserts hosted-MCP call/result are dropped when paired reasoning is stripped (no service-side storage).
- Update
_prepare_message_for_openaito detect “reasoning will be dropped” and skip serializingmcp_callaccordingly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/packages/openai/tests/openai/test_openai_chat_client.py | Adds regression test for dropping hosted-MCP call/result when reasoning is stripped. |
| python/packages/openai/agent_framework_openai/_chat_client.py | Drops mcp_call when reasoning is stripped without storage to prevent invalid payloads. |
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
moonbox3
left a comment
There was a problem hiding this comment.
Please check the failing tests as well.
b20225e to
67f2890
Compare
|
Rebased this branch onto latest Local validation:
I also checked the failed GitHub Actions job. The failing cases are the Docker shell-tool tests, and the failure is from pulling Those tests do not touch the OpenAI message serialization path changed in this PR. I did not change Docker-related code. One local note: running the full |
67f2890 to
207e60c
Compare
|
Follow-up pushed in Changes:
I checked the Validation: |
Motivation and Context
Fixes #6074.
When OpenAI Responses history is replayed without service-side storage, the client strips text_reasoning because replaying standalone reasoning items is rejected by the API. Hosted MCP calls from the same model output were still kept, which can leave the request with a bare mcp_call after its paired reasoning item has been removed.
Description
This change treats that stateless replay path as an all-or-nothing pair for hosted MCP items. If a message contains reasoning that will be stripped, hosted MCP call/result contents in the same message are skipped too. Any later unmatched MCP result marker is then dropped by the existing coalescing logic.
The existing behavior for hosted MCP calls without reasoning is unchanged, and storage-backed continuation still strips server-issued MCP items as before.
A regression test covers a reasoning plus hosted MCP call/result history and verifies that the prepared input does not contain a bare reasoning, mcp_call, or function_call_output item.
Contribution Checklist