anthropics / anthropics/claude-agent-sdk-python
max_buffer_size and import byte limits count characters instead of UTF-8 bytes
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 1.3k
- PR 合并指标
- PR 指标待抓取
描述
### Summary
Several limits documented and reported as byte limits use `len(str)`, which counts Unicode code points rather than encoded UTF-8 bytes.
### Affected code
- `src/claude_agent_sdk/_internal/transport/subprocess_cli.py:68-90` — `_LineFramer`
- `src/claude_agent_sdk/_internal/transport/subprocess_cli.py:800-808` — stderr buffering
- `src/claude_agent_sdk/_internal/transport/subprocess_cli.py:970-987` — stdout message guard
- `src/claude_agent_sdk/_internal/session_import.py:128-142` — import batching
### Current behavior
The framer increments `pending_len` with `len(chunk)`, and completed lines are checked with `len(line)`. Error messages describe the result as bytes. Session import similarly says it flushes at 1 MiB of line bytes but increments with `len(line)`.
For multibyte UTF-8 text, the actual byte count can be significantly larger. A string of emoji, for example, occupies about four UTF-8 bytes per Python character.
### Why this matters
- `max_buffer_size` does not enforce the promised wire/memory boundary.
- A nominal 1 MiB configuration can accept roughly 4 MiB of UTF-8 content before rejection.
- stderr partial-line buffers and SessionStore append batches can grow well beyond their intended byte thresholds.
- Operators relying on these settings for memory protection receive misleading error measurements.
### Expected behavior
A setting and error described as bytes should count encoded bytes consistently.
### Possible fix
The most robust approach is to frame raw bytes and decode complete lines afterward. Alternatively, maintain an exact incremental UTF-8 byte count alongside text chunks and use `len(line.encode("utf-8"))` for completed lines.
Tests should use multibyte input immediately below and above the configured byte boundary, including chunk splits across Unicode content.
### Environment
- Repository revision: current `main` audit at SDK version 0.2.128
- Bundled CLI version: 2.1.220
- Python test suite: 1,291 passed, 5 skipped
- Ruff and mypy: clean
I searched the existing issues and pull requests using the affected symbols and behavior before filing this.
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。