Repository navigation
fix(anthropic): preserve reasoning fallback with empty thinking blocks - #32105
jesco-absolut wants to merge 5 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR fixes a dropped-text regression that occurred when a provider streaming backend emitted a single LiteLLM chunk carrying both
Confidence Score: 5/5Safe to merge — the change is contained within the experimental pass-through adapter layer, all modified code paths are covered by the new and updated tests, and no existing assertions were weakened. The logic in
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py | Refactored _CombinedChunkSplitter._split to handle two distinct cases: (1) mixed reasoning+response payloads in a single chunk (no finish_reason required) and (2) content+finish_reason. New helper statics are clean. _is_combined is no longer called by _split but remains defined — now dead production code. |
| litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py | Fixes two independent elif branches for thinking_blocks and reasoning_content into a single elif isinstance(choice, StreamingChoices): block with a nested if/elif fallthrough, so an empty thinking_blocks=[] no longer hides a co-present reasoning_content. |
| tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_streaming_iterator_combined_chunk.py | Updated test_split_clears_reasoning_and_thinking_on_finish_chunk to expect the new 3-chunk split (reasoning → content → finish). Formatting-only changes elsewhere; no coverage is weakened. |
| tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_streaming_iterator_first_delta.py | Adds 4 new integration-style tests covering mixed chunk splitting (sync/async), empty thinking_blocks fallthrough, and redacted_thinking + reasoning_content coexistence. New _thinking_deltas helper. No existing assertions changed. |
Reviews (3): Last reviewed commit: "fix(anthropic): align reasoning stream f..." | Re-trigger Greptile
31e984f to
227e3e6
Compare
Merging this PR will not alter performance
|
227e3e6 to
6caf2c3
Compare
f0b1b5e to
0d7217c
Compare
e3fb8b1 to
02422da
Compare
TLDR
Problem this solves
How it solves it
User Flow
Before, an Anthropic-compatible client can lose reasoning while streaming
POST http://localhost:4000/v1/messageswithstream=trueto a reasoning backendAfter, the same request preserves that reasoning
POST http://localhost:4000/v1/messageswithstream=trueto the same reasoning backendRelevant issues
Related to #30765 and #29441, following #31022. #35289 already merged the mixed-payload stream splitting behavior, so this PR only covers the remaining reasoning fallback
Validation
Rebased onto
mainat2d896d57f28de591fe7a6c1fe360788ee47ee4ddon October 10. The rebase follows the adapter and unit-test directory moves and preserves the content-block method's compatibility aliasThe helper now reads typed fields and builds immutable reasoning values, satisfying the current lint and type gates without suppressions or higher limits
These are local unit and static checks, not real-provider end-to-end proof
Pre-Submission checklist
Type
Bug Fix
Test
Caveats
Low
Final Attestation