Python: Bug: streaming chunk merge adds an item to every matching item, duplicating text

Open
#14,786 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

@1AbdullahButt is already working on this.

Since Nov 12, 2026.

  • #14787 by @1AbdullahButt — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
20/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python

Research direction

The issue identifies semantic_kernel/contents/streaming_content_mixin.py and the regression test file tests/unit/contents/test_streaming_chat_message_content.py. Read _merge_items_lists and reproduce the example in the issue; done means the incoming item is merged into only one compatible item and the regression test passes. A linked pull request is already open.

Written by the indexing model from the issue text.

Description

python triage

Describe the bug

When two streaming chunks are added, StreamingContentMixin._merge_items_lists merges each incoming item into every compatible item in the list, not just the first one. The inner loop sets added = True after a successful item + other_item, but it doesn't break, so it keeps going and adds the same incoming item to every later item of the same type that accepts it.

https://github.com/microsoft/semantic-kernel/blob/25bd1bb67c38976bb13958783572efa57d3445d4/python/semantic_kernel/contents/streaming_content_mixin.py#L38-L51

This happens whenever a merged message holds two items of the same type that can both take the next chunk. One case is two StreamingTextContent items with the same choice_index, which the Google AI connector builds when a candidate has more than one text part (google_ai_chat_completion.py#L366-L376). Another is two FunctionCallContent items whose id/index don't tell them apart. Then the next chunk's text or arguments are copied into both.

To Reproduce

semantic-kernel 1.47.0. The file is the same on main (25bd1bb6).

from semantic_kernel.contents import AuthorRole, StreamingChatMessageContent, StreamingTextContent

c1 = StreamingChatMessageContent(role=AuthorRole.ASSISTANT, choice_index=0, items=[
    StreamingTextContent(choice_index=0, text="Part one. "),
    StreamingTextContent(choice_index=0, text="Part two. "),
])
c2 = StreamingChatMessageContent(role=AuthorRole.ASSISTANT, choice_index=0, items=[
    StreamingTextContent(choice_index=0, text="tail"),
])
print([i.text for i in (c1 + c2).items])

Output:

['Part one. tail', 'Part two. tail']

Expected behavior

The incoming item is merged into one item only, so the text isn't duplicated: ['Part one. tail', 'Part two. '].

Platform

  • Language: Python
  • Source: semantic-kernel 1.47.0 (pip) / main at 25bd1bb6
  • AI model: n/a (no model call needed)
  • IDE: n/a
  • OS: Windows 11, Python 3.12

Additional context

The fix is a break after added = True. I have it with a regression test in tests/unit/contents/test_streaming_chat_message_content.py and will open a PR.

Dominant language
C#
Stars
28.8k
Forks
4.9k
Avg merge
2d 17h
Merged PRs (30d)
48

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/semantic-kernel

All issues in microsoft/semantic-kernel

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.