Repository navigation
python : Honor merge_mode when streaming function call arguments in ResponsesHostServe - #10259
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoNov 11, 2026
Conversation
pratik wayase (PratikWayase)
deployed
to
github-app-auth
November 11, 2026 06:17 — with
GitHub Actions
Active
pratik wayase (PratikWayase)
deployed
to
github-app-auth
November 11, 2026 06:17 — with
GitHub Actions
Active
pratik wayase (PratikWayase)
deployed
to
github-app-auth
November 11, 2026 06:17 — with
GitHub Actions
Active
pratik wayase (PratikWayase)
deployed
to
github-app-auth
November 11, 2026 06:19 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change that honors argument merge modes to prevent duplicated streamed JSON.
No open issues 🎉
What changed in this PR
Fixes #9980 by honoring Content.merge_mode when the hosting adapter assembles tool-call arguments, preventing replacement snapshots from duplicating streamed JSON.
Changes:
- Reuses existing merge handling for function-call and MCP arguments, emitting only nonempty deltas.
- Adds six regression tests covering snapshot reconciliation, divergent-snapshot failure, empty arguments, and non-streaming responses.
| File | Description |
|---|---|
python/packages/foundry_hosting/tests/test_responses.py |
Adds regression coverage for argument snapshot handling. |
python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py |
Applies merge-mode handling to function-call and MCP argument updates. |
Review effort: Balanced
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 11, 2026
This branch was successfully deployed
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.
Motivation & Context
This fixes the bug reported in #9980. When a model streams a tool call, its arguments
arrive as incremental fragments followed by one final complete snapshot. On the producer
side the fragments are marked
Content.merge_mode="append"and the snapshot is markedmerge_mode="replace"._OutputItemTracker.handleinagent_framework_foundry_hosting/_responses.pyignoredmerge_modeand appended every function call arguments update it saw. A streamed calltherefore reached the client with its arguments duplicated, for example
{"location":"Seattle"}{"location":"Seattle"}. That string is not valid JSON, so toolexecution downstream breaks even though the HTTP response reports success with a 200.
Text updates in the same class already handle this correctly. The arguments branch just
never went through that path.
Description & Review Guide
Major changes
function_callandmcp_server_tool_callbranches of_OutputItemTracker.handlenow pass the arguments string through the existing
_consume_text_updatehelperinstead of appending unconditionally:
append: appended as beforereplace: the buffer is replaced with the snapshot and only the part that was notstreamed yet is emitted as a delta. If the snapshot matches what was already
streamed, nothing extra goes out
_PublicResponseFailure, which surfaces as aresponse.failedevent, the samebehavior divergent text already has
merge_mode=None(legacy or single update) behaves exactly as beforelonger produces an empty
response.function_call_arguments.deltaevent_close()is untouched. It joins_accumulated, which now holds the final snapshotexactly once
Impact
function_callitem now carries its arguments exactly once, as valid JSONmerge_mode. Only the duplicated emission is removed. Requests without streaming reuse the same tracker, so they are covered as wellmcp_server_tool_callupdates withmerge_mode, so that hunk is defensive for now. Both branches stay symmetric so they cannot drift apartReviewer focus
_OutputItemTracker.handle, and whether reusing the existing text policy for arguments is the right approachTestStreamingintests/test_responses.py: an equal snapshot is not sent again, a snapshot that extends the fragments streams only the suffix, a stream that contains only a replace snapshot, a divergent snapshot fails the stream withresponse.failed, a call without arguments emits no empty delta, and the non streaming pathRelated Issue
Fixes #9980
AI Assistance
AI assistance details: this PR description was drafted with AI assistance. I reviewed and verified all of it before submitting.
Contribution Checklist
section documents a trivial change or repository automation exception
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after anylanguage prefix). A workflow keeps the label and title prefix in sync automatically