Bug: _chunk_bytes_to_sse raises AttributeError when chunk.get('bytes') is None in Bedrock stream decoder
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Python
- 星标
- 4.1k
- 派生
- 915
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
anthropics/anthropic-sdk-python 的其他 Issue
-
beta_tool validation errors reach the model as "Invalid arguments for function X" with no detail可能已有人在做 @mangeshraut712 于 32 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
anthropics/anthropic-sdk-python#2033 · 3 条评论 ·
-
`AnthropicBedrock` 2.x sends `anthropic_version: 2026-10-21`, which Bedrock rejects for Claude Sonnet 4.5, Opus 4.5 and Opus 4.6可能已有人在做 @charan-rathore 于 36 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
anthropics/anthropic-sdk-python#2031 · 1 条评论 ·
-
Three symlink tests in test_agent_toolset.py are missing the needs_symlinks marker可能已有人在做 @okxint 于 82 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 92/100
anthropics/anthropic-sdk-python#1915 · 3 条评论 ·
-
Messages.parse (and AsyncMessages.parse) don't take cache_control?可能已有人在做 @AlphaFDE 于 86 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
anthropics/anthropic-sdk-python#1907 · 2 条评论 ·
-
Windows: os.fchmod in credential write-back bricks the OAuth refresh token可能已有人在做 @OllieinCanada 于 99 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
anthropics/anthropic-sdk-python#1868 · 1 条评论 ·
查看 anthropics/anthropic-sdk-python 的全部 Issue
相似的 Issue
-
bug harness
难度 2/5 1-3 小时 新手友好度 72/100
mruangutai/harness#2687 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
modal-labs/modal-client#4158 ·
-
good first issue
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 72/100
The-Swarm-Corporation/swarms-rs#168 ·
维护者通常 1 天内回复
-
[BUG] SMTP listener now binds to EMAIL_PORT instead of 2525 since the gunicorn switch 5.0.3-ls373未关闭
难度 2/5 1-3 小时 新手友好度 72/100
linuxserver/docker-healthchecks#137 · 1 条评论 ·