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

Abierto
#14,786 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

@1AbdullahButt ya está trabajando en esto.

Desde el 12/11/2026.

  • #14787 de @1AbdullahButt — abierto

Evaluación

Dificultad
1/5
Tiempo estimado
Menos de una hora
Aptitud para principiantes
20/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C#
Estrellas
28.8k
Forks
4.9k
Merge medio
2 d 17 h
PR fusionados (30 d)
48

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/semantic-kernel

Todos los issues de microsoft/semantic-kernel

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.