[PR #223] fix: ignore a leading BOM in SSE streams #223

Open
opened 2026-10-31 22:02:26 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Comfy-Org/comfy-python-sdk/pull/223
Author: @allenflux
Created: 10/17/2026
Status: 🔄 Open

Base: main ← Head: fix-sse-leading-bom


📝 Commits (1)

  • 204f8ed fix: ignore a leading BOM in SSE streams

📊 Changes

4 files changed (+140 additions, -0 deletions)

View changed files

📝 CHANGELOG.md (+5 -0)
📝 src/comfy_low/sse.py (+5 -0)
📝 tests/conftest.py (+17 -0)
➕ tests/test_sse_bom.py (+113 -0)

📄 Description

A valid SSE stream can begin with one UTF-8 byte order mark. The decoder currently treats it as part of the first field name: an initial event: loses its event type, and an initial data: can lose the entire frame. The WHATWG parsing rules require removing one leading BOM.

Remove exactly one prefix on the shared decoder's first line, including when that line is a comment or blank. Later marks remain intact. Each HTTP connection already creates its own decoder, so the same rule applies after reconnecting.

The regressions cover decoder boundaries and real sync/async HTTP streams, splitting the BOM bytes and CRLF pairs across chunks. Reconnect tests verify that typed progress and terminal events survive both connections.

Validation on Python 3.12.11 / macOS:

  • New regressions reproduce the bug on the base: 9 failed, 12 passed; the focused new/existing suites pass after the fix (34 tests).
  • Full pytest -v: 1286 passed, 9 environment-gated live integration tests skipped.
  • Ruff lint/format, mypy src, codegen drift, public repository hygiene, wheel/sdist build, and twine check: pass.
  • Independent review found no required changes; 24 focused tests and 216 stream-boundary checks passed.

This protocol-conformance case was reproduced with the repository's local HTTP server. The Python 3.10–3.13 runtime matrix remains for CI. No version or dependency update is needed.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where a leading UTF-8 byte order mark in an event stream could prevent its first event or data field from being decoded correctly.
    • The fix also applies when a connection is re-established. Subsequent byte order marks elsewhere in the stream remain unchanged.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Comfy-Org/comfy-python-sdk/pull/223 **Author:** [@allenflux](https://github.com/allenflux) **Created:** 10/17/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-sse-leading-bom` --- ### 📝 Commits (1) - [`204f8ed`](https://github.com/Comfy-Org/comfy-python-sdk/commit/204f8ed1ce924e0d5554d50a0907a9fe266777b4) fix: ignore a leading BOM in SSE streams ### 📊 Changes **4 files changed** (+140 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+5 -0) 📝 `src/comfy_low/sse.py` (+5 -0) 📝 `tests/conftest.py` (+17 -0) ➕ `tests/test_sse_bom.py` (+113 -0) </details> ### 📄 Description A valid SSE stream can begin with one UTF-8 byte order mark. The decoder currently treats it as part of the first field name: an initial `event:` loses its event type, and an initial `data:` can lose the entire frame. The [WHATWG parsing rules](https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation) require removing one leading BOM. Remove exactly one prefix on the shared decoder's first line, including when that line is a comment or blank. Later marks remain intact. Each HTTP connection already creates its own decoder, so the same rule applies after reconnecting. The regressions cover decoder boundaries and real sync/async HTTP streams, splitting the BOM bytes and CRLF pairs across chunks. Reconnect tests verify that typed progress and terminal events survive both connections. Validation on Python 3.12.11 / macOS: - New regressions reproduce the bug on the base: 9 failed, 12 passed; the focused new/existing suites pass after the fix (34 tests). - Full `pytest -v`: 1286 passed, 9 environment-gated live integration tests skipped. - Ruff lint/format, `mypy src`, codegen drift, public repository hygiene, wheel/sdist build, and `twine check`: pass. - Independent review found no required changes; 24 focused tests and 216 stream-boundary checks passed. This protocol-conformance case was reproduced with the repository's local HTTP server. The Python 3.10–3.13 runtime matrix remains for CI. No version or dependency update is needed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed an issue where a leading UTF-8 byte order mark in an event stream could prevent its first event or data field from being decoded correctly. * The fix also applies when a connection is re-established. Subsequent byte order marks elsewhere in the stream remain unchanged. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Comfy-Org/comfy-python-sdk#223
No description provided.