server: surface unclosed thinking as reasoning_content, not content#524
Open
stefanwichmann wants to merge 1 commit into
Open
server: surface unclosed thinking as reasoning_content, not content#524stefanwichmann wants to merge 1 commit into
stefanwichmann wants to merge 1 commit into
Conversation
When thinking mode is on and generation stops before </think> (e.g. the response is truncated at max_tokens mid-thought), parse_generated_message_ex dumped the partial reasoning into content with an empty reasoning_content, so clients received raw chain-of-thought as the assistant's answer. Route the accumulated text to reasoning_content and leave content empty, matching what the live streaming classifier already does. This composes with the existing tool-call handling in the same branch: unclosed DSML is still treated as reasoning rather than executed. Adds a regression test (test_thinking_unclosed_is_reasoning_not_content). Fixes antirez#509.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #509.
Problem
When thinking mode is on and generation stops before
</think>(e.g. the response is truncated atmax_tokensmid-thought), the non-streaming path inparse_generated_message_exrouted the partial chain-of-thought intocontent(viasplit_reasoning_content) with an emptyreasoning_content. Clients received raw, unfinished CoT as if it were the assistant's final answer. The live streaming classifier already handles this correctly — only the blocking path was affected.Fix
In the
require_thinking_closed && !think_endbranch, treat the accumulated text as unfinished reasoning: surface it asreasoning_contentand leavecontentempty (stripping a leading<think>). Any DSML in that text is unclosed reasoning too, so it's deliberately not executed as a tool call — composing with the existing unclosed-think handling from #318.Testing
test_thinking_unclosed_is_reasoning_not_content../ds4_test --serverpasses.make cuda-sparkand validated live on a DGX Spark (GB10): truncated non-streaming responses now return emptycontent+ populatedreasoning_content; completed responses unchanged.Single file, +35/−3.