From 9dae6bc70bcd241482a83cbc8c2271463dbbca25 Mon Sep 17 00:00:00 2001 From: yucheng-berri <293926326+yucheng-berri@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:56:00 -0700 Subject: [PATCH] test(streaming): a merged reasoning stream cut mid reasoning now fails Main's think tag test expected a stream that ends mid reasoning without a finish reason to finish with a closed think block. With this PR that stream fails, so the case moves to its own test that expects MidStreamFallbackError with the open think block as the partial content --- .../test_streaming_handler.py | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/unit/litellm_core_utils/test_streaming_handler.py b/tests/unit/litellm_core_utils/test_streaming_handler.py index ca5f9c5a63f..e3201263a3c 100644 --- a/tests/unit/litellm_core_utils/test_streaming_handler.py +++ b/tests/unit/litellm_core_utils/test_streaming_handler.py @@ -576,11 +576,6 @@ _GET_WEATHER_CALL: Final = { "abcd", 0, ), - ( - (_stream_chunk({"reasoning_content": "Still thinking"}),), - "Still thinking", - 0, - ), ( (_stream_chunk({"content": "hi"}), _stream_chunk({}, "stop")), "hi", @@ -592,7 +587,6 @@ _GET_WEATHER_CALL: Final = { "reasoning_then_function_call", "reasoning_cut_by_length", "reasoning_after_answer", - "stream_ends_mid_reasoning", "answer_without_reasoning", ], ) @@ -626,6 +620,26 @@ async def test_merged_reasoning_stream_keeps_think_tags_balanced( ) +@pytest.mark.asyncio +@pytest.mark.parametrize("sync_mode", [True, False]) +async def test_merged_reasoning_stream_cut_mid_reasoning_fails_instead_of_closing_the_think_block( + logging_obj: Logging, sync_mode: bool +) -> None: + response: Final = CustomStreamWrapper( + completion_stream=ModelResponseListIterator( + model_responses=[_stream_chunk({"reasoning_content": "Still thinking"})] + ), + model="deepseek-reasoner", + logging_obj=logging_obj, + ) + response.merge_reasoning_content_in_choices = True + + with pytest.raises(MidStreamFallbackError) as excinfo: + await _collect(response, sync_mode) + + assert excinfo.value.generated_content == "Still thinking" + + def test_strip_sse_data_from_chunk(): """Test the static method that strips 'data: ' prefix from SSE chunks""" # Test with string inputs