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.
|
Independent DGX Spark validation for this PR. Test environment:
Baseline reproduction:
Validation results with this PR:
The baseline issue was reproducible on this machine, and the tested PR head corrected it without a regression in these five API paths. |
fulvius31
added a commit
to fulvius31/ds4
that referenced
this pull request
Jul 24, 2026
…ez#524) server: when thinking mode is on and the model never emits </think> (typically truncated at max_tokens mid-thought), surface the whole text as unfinished reasoning with empty content instead of letting it leak into content — applied to both the DSML and GLM tool-call parse paths (upstream antirez#524, adapted to the split parser). Verified live: /v1/messages now returns a thinking block plus empty text for the truncated case; closed-thinking responses are unchanged. cuda: treat every model range as accessible when the HMM direct path is active (upstream antirez#158, the is_cached hunk only). The PR's full-model prefetch half is deliberately not ported: prefetching a model larger than RAM would thrash the page cache on the SSD-streaming Spark boxes. Dormant in current configs; single-token identity exact. Reviewed against the queue: antirez#497 already fixed here (b715001), antirez#472 superseded by the newer bounded-reserve design, antirez#513 not reachable (expert tiles ship disabled for iq2-down), antirez#460/antirez#528/antirez#504 deferred as future work. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.