Fix dropped Inkling reasoning at stream end (#31787)

This commit is contained in:
Ke Bao
2026-07-20 23:23:15 +08:00
committed by GitHub
parent 7fc545b649
commit 5ab3d90b81
2 changed files with 32 additions and 0 deletions
@@ -249,6 +249,24 @@ class TestInklingDetector(CustomTestCase):
content += detector.parse_streaming_increment(chunk).normal_text
self.assertEqual(content, " worldnext", msg=f"chunks={chunks!r}")
def test_finish_flushes_reasoning_truncated_before_end_token(self):
"""Bug regression: with stream_reasoning=False the detector buffers the
thinking block and only flushes it on a control/end token. When
generation is cut mid-block (e.g. max_tokens) the stream ends with no
end token, so the buffered trace was dropped entirely; finish() must
emit it, matching the non-streaming detect_and_parse path."""
detector = InklingDetector(stream_reasoning=False)
source = "<|message_model|><|content_thinking|>truncated thinking"
streamed_reasoning = ""
for char in source:
streamed_reasoning += detector.parse_streaming_increment(
char
).reasoning_text
# The block never closed, so nothing surfaces mid-stream.
self.assertEqual(streamed_reasoning, "")
# finish() flushes the buffered trace instead of dropping it.
self.assertEqual(detector.finish().reasoning_text, "truncated thinking")
class TestKimiDetector(CustomTestCase):
def setUp(self):