Skip to content

SSE drops UTF-8 characters split across transport chunks #62

Backlog

Description

@Yukikaze-1145146767

Problem

On main at aa08a54 (Python 3.12), both iter_sse() and aiter_sse() corrupt UTF-8 when the HTTP stream splits a code point across chunks. ASCII streams look fine, but Chinese text, accented characters, or emoji can turn into U+FFFD. This is an SDK-side decoding issue; no server is needed.

Offline reproduction

from io import BytesIO
from hanzoai import iter_sse

data = "data: 你好 é 🙂\n\n".encode()
print(next(iter_sse(BytesIO(data), chunk_size=1)).data)

Expected 你好 é 🙂; actual ������ �� ����.

Each chunk is decoded separately before buffering. A per-stream incremental UTF-8 decoder with the same replacement policy preserves split characters; flush it at EOF. Sync and async regression tests both failed on the original code and both passed after the change. A separate offline check split each sample at every byte boundary. AI-assisted; no live API was accessed.

Activity

  1. linear commented on Dec 5, 2026

    @linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions