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

Aperta
#1,975 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@chauvuusvn ci sta già lavorando.

Dal 5/10/2026.

  • #1976 di @chauvuusvn — aperta
  • #1996 di @iosayin — chiusa senza merge

Valutazione

Difficoltà
1/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
aws, python
Ambito
backend

Direzione di ricerca

Start with anthropic/lib/bedrock/_stream_decoder.py, especially _chunk_bytes_to_sse and _parse_message_from_event; the issue provides a direct reproduction by passing None. Check the existing stream decoder tests and run the relevant tests. Done means empty or missing chunk bytes no longer crash and are dropped as described; a linked pull request is already open.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

In anthropic.lib.bedrock._stream_decoder._chunk_bytes_to_sse(raw: bytes), raw.decode() is called unconditionally on line 72:

def _chunk_bytes_to_sse(raw: bytes) -> ServerSentEvent | None:
    decoded = raw.decode()

In _parse_message_from_event, _chunk_bytes_to_sse is invoked with chunk.get("bytes"):

chunk = parsed_response.get("chunk")
if not chunk:
    return None

return _chunk_bytes_to_sse(chunk.get("bytes"))

When AWS Bedrock sends an empty chunk frame, a control payload, or a chunk dictionary where the "bytes" key is missing or None (e.g. chunk = {"bytes": None} or chunk = {}), chunk.get("bytes") evaluates to None.

Passing None to _chunk_bytes_to_sse raises AttributeError: 'NoneType' object has no attribute 'decode', immediately crashing the active Bedrock stream.

To Reproduce
from anthropic.lib.bedrock._stream_decoder import _chunk_bytes_to_sse

_chunk_bytes_to_sse(None)
# Traceback (most recent call last):
#   File ".../anthropic/lib/bedrock/_stream_decoder.py", line 72, in _chunk_bytes_to_sse
#     decoded = raw.decode()
# AttributeError: 'NoneType' object has no attribute 'decode'
Expected Behavior

_chunk_bytes_to_sse should safely guard against None or non-bytes payloads and return None (dropping the empty frame) rather than crashing with an AttributeError.

Lingua principale
Python
Stelle
4.1k
Fork
915
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anthropics/anthropic-sdk-python

Tutte le issue di anthropics/anthropic-sdk-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.