Repository navigation
Python: Merge a streaming item into only one matching item - #14787
Open
Muhammad Abdullah Butt (1AbdullahButt) wants to merge 1 commit into
Open
Muhammad Abdullah Butt (1AbdullahButt) wants to merge 1 commit into
Muhammad Abdullah Butt (1AbdullahButt) wants to merge 1 commit into
Conversation
_merge_items_lists kept looping after a successful add, so an incoming chunk item was added to every compatible item in the list and its text or arguments were duplicated. Stop at the first successful merge. Fixes microsoft#14786 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Muhammad Abdullah Butt (1AbdullahButt)
requested a review
from a team
as a code owner
November 12, 2026 12:20
Muhammad Abdullah Butt (1AbdullahButt)
deployed
to
github-app-auth
November 12, 2026 12:20 — with
GitHub Actions
Active
Copilot started reviewing on behalf of
Muhammad Abdullah Butt (1AbdullahButt)
November 12, 2026 12:20
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the change to prevent duplicate text during streaming-content merging.
No open issues 🎉
What changed in this PR
Fixes #14786 by ensuring Python streaming-content merging adds each incoming item to only the first compatible item, preventing duplicated text across matching items.
Changes:
- Stops the inner merge loop after the first successful addition.
- Adds a regression test confirming that only the first of two compatible text items receives the incoming text.
| File | Description |
|---|---|
python/tests/unit/contents/test_streaming_chat_message_content.py |
Adds regression coverage for merging into only one matching item. |
python/semantic_kernel/contents/streaming_content_mixin.py |
Breaks the loop after a successful merge to prevent duplicate additions. |
Review effort: Balanced
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 and Context
Fixes #14786.
When two streaming chunks are added,
StreamingContentMixin._merge_items_listsmerged each incoming item into every compatible item in the list. For example, a first chunk with two text parts plus a second chunk with"tail"gave['Part one. tail', 'Part two. tail'], so the text was duplicated.Description
The inner loop set
added = Trueafter a successfulitem + other_itembut kept iterating. It now breaks at the first successful merge, so each incoming item is merged into exactly one item, as the existing tests already assume for the single-item case.Added
test_scmc_add_merges_item_into_one_matching_item_onlytotests/unit/contents/test_streaming_chat_message_content.py. It fails before the change and passes after.Tested locally (Python 3.12, Windows):
test_streaming_chat_message_content.py,test_function_call_content.pyandtest_streaming_annotation_content.py: 82 passed, 0 failed. I ran them with--noconftest, so the 9 tests that need conftest fixtures (function_call) were not run.ruff checkandruff format --checkon both files passClaude Code wrote this change.
Contribution Checklist
🤖 Generated with Claude Code