fix(responses): preserve combined reasoning and content - #36329
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile SummaryThe PR expands each chat-completion chunk into ordered Responses API events shared by synchronous and asynchronous iteration.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/responses/litellm_completion_transformation/streaming_iterator.py | Introduces shared ordered event expansion, centralized sequence numbering, distinct output-index allocation, and complete reasoning-summary lifecycle handling. |
| tests/test_litellm/responses/litellm_completion_transformation/test_reasoning_content_transformation.py | Adds sync and async coverage for mixed reasoning/content streams, lifecycle ordering, sequence numbers, and completed-output alignment. |
| tests/test_litellm/responses/litellm_completion_transformation/test_litellm_completion_responses.py | Adds coverage ensuring reasoning items use the summary-part lifecycle and emit it only once. |
| tests/test_litellm/responses/litellm_completion_transformation/test_tool_call_streaming_transformation.py | Extends tool-stream lifecycle coverage for the revised event-expansion behavior. |
Reviews (6): Last reviewed commit: "test(responses): isolate reasoning tool ..." | Re-trigger Greptile
|
@greptileai Please re-review the current head for lifecycle ordering, output indexes, and emitted sequence numbers. |
|
@greptileai Please re-review current head. Sequence numbers now serialize through Pydantic output, with mapped sync, async, and tool-stream regressions |
Credit PR BerriAI#32777 for identifying the missing lifecycle event
|
@greptileai Please re-review current head, including the reasoning summary part lifecycle event credited to PR #32777 |
|
The failing responses-caching-types shard reproduces known global state contamination; both reported normalization tests pass locally. Please rerun that job |
|
@greptileai Please re-review current head, including the reasoning summary part lifecycle event credited to PR #32777 |
|
@greptileai Please re-review current head, including the reasoning summary part lifecycle event credited to PR #32777 |
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a developer's stream omits text and opens reasoning incompletely
POST https://litellm-domain/v1/responseswithstream: true,reasoning.effort: high, and a required marker in the inputresponse.reasoning_summary_text.deltawithoutresponse.reasoning_summary_part.addedresponse.output_text.deltavalues and receiveA begin middle end, whileresponse.output_text.donecontainsMARKER_ALPHA begin middle endAfter: the same stream opens reasoning and preserves all visible text
POST https://litellm-domain/v1/responseswithstream: true,reasoning.effort: high, and the same required marker in the inputresponse.reasoning_summary_part.added, thenresponse.reasoning_summary_text.deltaresponse.output_text.deltavalues and receiveMARKER_ALPHA begin middle end, which matchesresponse.output_text.doneRelevant issues
Fixes #36327
Related to #27492, #25216, #30014, #32777, and #33938
Linear ticket
Pre-Submission checklist
Delays in PR merge?
If this PR is delayed, I will ask the LiteLLM team in Slack #pr-review
Screenshots / Proof of Fix
The proxy hostname and response IDs are redacted. Both deployments used the same model route, request, and provider credentials. All requests used the live DeepInfra API without mocks
Request used for every proxy trial
Before
Source revision
065bf83f0cac68d052b2a7f5ca8e3a1b764a2ec1, LiteLLM1.94.1A direct DeepInfra control streamed the complete answer. Its final Chat Completions chunk contained both payloads
{ "delta": { "content": "MARKER_ALPHA begin middle end", "reasoning_content": " reasoning visible." }, "finish_reason": "stop" }The proxy lost the text prefix in three of four trials. The terminal done event remained complete in all trials
After
The live provider proof was captured at original fix commit
ecf52e0feee53f010d918b5a01ec2c6f4ad8cfda. The deployed lifecycle repair commit43dd8496c306f433035a1e652546addef9f4aeacpreserves that behavior while correcting event orderingThree live proxy trials returned HTTP 200. Each trial emitted reasoning before text. Each incremental text stream contained the complete marker and matched the terminal done event
Type
Bug Fix
Changes
Focused verification at original PR commit
ecf52e0feee53f010d918b5a01ec2c6f4ad8cfda:Focused verification at current head
9d109c717ef05ed6bdff8ebb7d6937e35f05ea48:Final Attestation