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

Đang mở
#14,786 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@1AbdullahButt đang làm issue này rồi.

Từ ngày 12/11/2026.

  • #14787 của @1AbdullahButt — đang mở

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
20/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend-api-design

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C#
Star
28.8k
Fork
4.9k
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
48

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/semantic-kernel

Tất cả issue của microsoft/semantic-kernel

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.