Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Assistant chat streams silently discard the first event when a
text/event-streamresponse starts with a UTF-8 byte order mark. The BOM remains attached to the initialdata:field, so the parser skips it. This affects bothchatandchat_completions, with synchronous and asynchronous clients. A leading BOM on[DONE]also causes the terminator to be skipped.Solution
Decode the four streaming responses with
utf-8-sigbefore iterating lines. This removes the single initial BOM, including when its bytes arrive in separate chunks, and preserves U+FEFF inside response text. It follows the SSE UTF-8 decoding contract.Type of Change
Test Plan
uv run --frozen pytest tests/unit/test_assistant_stream_encoding.py -q: 32 passed. These cover both client modes and endpoints, BOM split across bytes, Unicode and embedded U+FEFF, comments, empty streams and[DONE]. The same tests on unchanged main produce 12 failures and 20 passing controls.uv run --frozen mypy --strict pinecone/: passed for 202 source files.uv run --frozen ruff check .anduv run --frozen ruff format --check .: passed (717 files formatted).uv run --frozen pytest tests/unit --cov --cov-report=term-missing: 9,793 passed, 13 skipped, 8 failed. Unchanged main with the same environment and test scope produced 9,763 passed, 13 skipped, 6 failed. Six failures repeat in the complete main run: two Windows temporary-file sharing cases, three real-sleep timing assertions and the quota-starvation assertion. The other two async-sleep assertions also reproduce in an independent focused run on unchanged main, at approximately 47 ms against a 50 ms threshold. These paths are unchanged. The full suite is not green.Validation used Python 3.12 on Windows with the frozen dev dependencies and the compiled Rust extension. The full suite used process-local UTF-8 settings after the initial Windows GBK documentation-collection errors. No live Pinecone service, model execution or other platform was tested.
Note
Low Risk
Narrow change to SSE line decoding in assistant chat streams; behavior improves for BOM-prefixed responses and should be unchanged for streams without a leading BOM.
Overview
Fixes assistant SSE streaming when
text/event-streamresponses begin with a UTF-8 byte order mark (BOM). Without BOM-aware decoding, the firstdata:line (and sometimes[DONE]) failed prefix checks and was dropped, so callers lost the opening chunk.Sync and async clients now set
response.encoding = "utf-8-sig"before line iteration on all four stream helpers (chatandchat_completionsinpinecone/client/assistants.pyandpinecone/async_client/assistants.py). That strips only the leading BOM (including when split across chunks) while keeping U+FEFF inside message text.Adds
tests/unit/test_assistant_stream_encoding.pywith parametrized coverage for both APIs and clients (plain UTF-8, BOM, split BOM, comments, empty streams, and[DONE]variants).Reviewed by Cursor Bugbot for commit 4c20eb3. Bugbot is set up for automated code reviews on this repo. Configure here.