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

オープン
#14,786 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

@1AbdullahButt がすでに取り組んでいます。

2026年11月12日 から。

  • #14787 @1AbdullahButt による — オープン

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C#
スター
28.8k
フォーク
4.9k
平均マージ
2日 17時間
マージ済み PR(30日)
48

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/semantic-kernel のほかの issue

microsoft/semantic-kernel の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。