Skip to content

fix(bedrock): guard _chunk_bytes_to_sse against None or non-bytes payloads (#1975) - #1996

Closed
iosayin wants to merge 1 commit into
anthropics:mainfrom
iosayin:fix/1975-bedrock-stream-none-chunk
Closed

iosayin wants to merge 1 commit into
anthropics:mainfrom
iosayin:fix/1975-bedrock-stream-none-chunk

Conversation

@iosayin

@iosayin iosayin commented Oct 7, 2026

Copy link
Copy Markdown

Summary

Guards _chunk_bytes_to_sse in anthropic.lib.bedrock._stream_decoder against None or non-bytes payloads.

When AWS Bedrock sends an empty chunk frame, a control payload, or a chunk dictionary where chunk.get("bytes") is None (e.g. chunk = {"bytes": None} or chunk = {}), _chunk_bytes_to_sse previously called raw.decode() unconditionally, resulting in AttributeError: 'NoneType' object has no attribute 'decode'.

With this change, _chunk_bytes_to_sse safely returns None to drop non-bytes or empty payloads without crashing the active stream.

Closes #1975

@iosayin
iosayin requested a review from a team as a code owner October 7, 2026 00:12
@chauvuusvn

Copy link
Copy Markdown

Note that PR #1976 was already submitted on Oct 5 with regression test coverage to resolve #1975 prior to this PR. Please coordinate or consolidate review on #1976 to avoid duplicate PR overhead for the maintainers.

@iosayin

iosayin commented Oct 14, 2026

Copy link
Copy Markdown
Author

Thanks for flagging, @chauvuusvn. Closing in favor of #1976, which was opened earlier for #1975 and already includes a regression test.

@iosayin iosayin closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: _chunk_bytes_to_sse raises AttributeError when chunk.get('bytes') is None in Bedrock stream decoder

2 participants