Skip to content

fix(bedrock): guard _chunk_bytes_to_sse against None in stream decoder - #1976

Open
chauvuusvn wants to merge 2 commits into
anthropics:mainfrom
chauvuusvn:fix/bedrock-stream-null-bytes-guard
Open

chauvuusvn wants to merge 2 commits into
anthropics:mainfrom
chauvuusvn:fix/bedrock-stream-null-bytes-guard

Conversation

@chauvuusvn

Copy link
Copy Markdown

Fixes #1975

Summary

In anthropic.lib.bedrock._stream_decoder._chunk_bytes_to_sse, raw.decode() was called without checking if raw is None or non-bytes. When AWS Bedrock stream parser receives an event with empty or missing "bytes", chunk.get("bytes") returns None, raising AttributeError: 'NoneType' object has no attribute 'decode' and crashing the stream.

Fix

  • Guard _chunk_bytes_to_sse against None and non-bytes instances.
  • Add regression unit test test_chunk_bytes_to_sse_drops_none_and_non_bytes to tests/lib/test_bedrock.py.

…m decoder

- Add falsy guard at chunk bytes extraction site to drop None and empty bytes
- Restore clean bytes signature for _chunk_bytes_to_sse without pyright ignores
- Add regression test for empty and null bytes frames in bedrock eventstream

This branch has not been deployed

No deployments
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

1 participant