Fix dropped Inkling reasoning at stream end - #31787
Conversation
|
/rerun-test test/registered/unit/parser/test_reasoning_parser.py |
|
Results for 🚀 |
There was a problem hiding this comment.
Code Review
This pull request adds a finish method to the reasoning parser to flush buffered reasoning when stream_reasoning=False and the stream ends before a control token closes the block, and includes a unit test to verify this behavior. The reviewer points out that the base class BaseReasoningFormatDetector suffers from the same issue and suggests updating its finish method to ensure consistent behavior across all reasoning detectors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Motivation
With
stream_reasoning=False, the Inkling reasoning detector buffers the thinking block into_pending_reasoningand only flushes it when a control/end token closes the block. When generation is cut mid-block (e.g.max_tokenstruncates a<|content_thinking|>block), the stream ends with no end token, so the buffered trace is dropped entirely — the whole reasoning disappears from the streamed response.The non-streaming
detect_and_parsepath already flushes_pending_reasoningat the end, butInklingDetectorhad nofinish()override, so at stream endparse_stream_end()fell through to the basefinish()(which only handles_force_nonempty_content/_in_reasoning, neither used by this detector) and emitted nothing.Modifications
InklingDetector.finish()to emit any buffered_pending_reasoning(when mid-reasoning understream_reasoning=False) and reset the detector's block state, mirroring the non-streaming flush.finish()surfaces the trailing reasoning (fails on the pre-fix code, passes after).Verified on a live server that BFCL live tool-calling accuracy is unchanged (
tool_parse_errors=0), i.e. the added stream-end flush does not perturb the tool-call path.CI States
Latest PR Test (Base): 🚫 Run #29753147981
Latest PR Test (Extra): ❌ Run #29753146335