fix(streaming): propagate message_delta.container into final Message#1444
Open
abhicris wants to merge 2 commits intoanthropics:mainfrom
Open
fix(streaming): propagate message_delta.container into final Message#1444abhicris wants to merge 2 commits intoanthropics:mainfrom
abhicris wants to merge 2 commits intoanthropics:mainfrom
Conversation
…ror (closes anthropics#1430) The 'Streaming is required' ValueError pointed at https://github.com/anthropics/anthropic-sdk-python#long-requests, a README heading removed in 0e40921. The same project already references the canonical location for this guidance — https://docs.anthropic.com/en/api/errors#long-requests — from src/anthropic/_exceptions.py:90 (the timeout error). Adopt the same URL here so users hitting either path land on the same page.
…loses anthropics#1424) The non-beta streaming aggregator at lib/streaming/_messages.py merges stop_reason / stop_sequence / usage from `message_delta`, but drops `delta.container`. The result: with `code_execution_20260120` (or any container-backed tool) the `Message` returned by `stream.get_final_message()` has `container=None`, even though the SSE stream did carry it on the `message_delta` event. The next request then fails: anthropic.BadRequestError: 400 - container_id is required when there are pending tool uses generated by code execution with tools. The beta path already does the right thing (lib/streaming/_beta_messages.py:537 assigns `current_snapshot.container = event.delta.container`). This PR mirrors that single line in the non-beta path so both paths surface the container id consistently. `+1` line of fix, `+50` lines of regression test that constructs a synthetic `RawMessageDeltaEvent` with a `Container`, calls `accumulate_event` directly, and asserts `snapshot.container.id` is set (plus the existing `stop_reason` / `usage.output_tokens` merges still work).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1424.
Bug
The non-beta streaming aggregator in `lib/streaming/_messages.py` merges `stop_reason`, `stop_sequence`, and `usage` from the `message_delta` SSE event, but drops `delta.container`. With `code_execution_20260120` (or any container-backed tool), `stream.get_final_message().container` is therefore `None`, even though the SSE stream did carry the container info on the `message_delta` event.
The next request then fails:
```
anthropic.BadRequestError: 400 - container_id is required when there are pending tool uses generated by code execution with tools.
```
Fix
The beta path already does the right thing — `lib/streaming/_beta_messages.py:537` assigns `current_snapshot.container = event.delta.container`. This PR mirrors that single line in the non-beta path so both paths surface the container id consistently.
```diff
elif event.type == "message_delta":
```
Test
New regression test `test_message_delta_propagates_container_to_snapshot` constructs a synthetic `RawMessageDeltaEvent` with a `Container`, calls `accumulate_event` directly, and asserts `snapshot.container.id` is set (plus the existing `stop_reason` / `usage.output_tokens` merges still work).
Diff size
`+58 / -0` (1 line of fix + 1 comment block + 50-line regression test). No public-API change; affects only what the streaming aggregator preserves on the final `Message`.
Contributed by kcolbchain.