fix(streaming): support trailing-strings mode and error handling in non-beta messages - #1930
Christian-Sidak wants to merge 2 commits into
Conversation
…havior The non-beta `accumulate_event` in `_messages.py` was not passing request headers to the partial JSON parser, so it could not activate `trailing-strings` mode for the `fine-grained-tool-streaming-2025-05-14` beta when used through the standard messages endpoint. It also lacked the error handling added to the beta path. This change adds `request_headers` to `accumulate_event`, threads the headers from both sync and async `MessageStream`, and mirrors the conditional `partial_mode="trailing-strings"` and `ValueError` handling already present in `_beta_messages.py`. Fixes anthropics#1925 Signed-off-by: Christian-Sidak <61099993+Christian-Sidak@users.noreply.github.com>
0ee0358 to
70af7d5
Compare
|
Thanks for bringing the standard messages path in line with the beta path. One scope issue before calling this
Could you either remove the |
00200200
left a comment
There was a problem hiding this comment.
Found a blocking import mismatch in the new code and tests.
This repository imports the renamed client as httpx2, but the PR uses httpx.Headers at src/anthropic/lib/streaming/_messages.py:448 and throughout the new tests. Because of that:
python -m pytest -q -n0 tests/lib/streaming/test_messages.pyfails with 4NameError: name 'httpx' is not definedfailures.- mypy reports
src/anthropic/lib/streaming/_messages.py:448: error: Name "httpx" is not defined.
Please use httpx2.Headers consistently (or import the correct alias) before merging. The focused tests pass after that import mismatch is corrected; the current PR head is not green locally.
Co-Authored-By: Christian Sidak <csidak@gmail.com>
|
Fixed in abe59d6:
|
Summary\n\nThe non-beta
accumulate_eventin_messages.pywas missing two features that_beta_messages.pyalready had:\n\n- Support forpartial_mode="trailing-strings"when thefine-grained-tool-streaming-2025-05-14beta header is present. Without this, incomplete trailing strings in streaming tool inputs were silently dropped from intermediate snapshots rather than preserved as partial values.\n- AValueErrorwith a helpful message when the partial JSON is genuinely invalid, consistent with the beta path.\n\nThis PR addsrequest_headerstoaccumulate_event, threads the headers from both sync and asyncMessageStream.__stream__, and mirrors the conditional logic already in_beta_messages.py. This is a standard/beta streaming parity fix.\n\n## Test plan\n\n- [x] All existing streaming tests pass (tests/lib/streaming/)\n- [x] NewTestAccumulateEventtests cover: complete JSON with and without headers, trailing-strings mode activated by the beta header, and ValueError raised for invalid JSON in both modes