fix: strip all reasoning blocks in removeReasoningContent, not just the first - #243
Open
Ayush7614 wants to merge 1 commit into
Open
fix: strip all reasoning blocks in removeReasoningContent, not just the first#243Ayush7614 wants to merge 1 commit into
Ayush7614 wants to merge 1 commit into
Conversation
…he first removeReasoningContent only removed the first complete thinking… response block and ignored unterminated blocks. A model can emit several reasoning spans across one turn, and a stream cut off mid-reasoning leaves an unterminated block — both cases leaked reasoning into the token count and, potentially, the prompt sent to the model. Now: - strips every complete thinking… response block (global replace) - strips a trailing unterminated thinking block - applies the same treatment to the DeepSeek <|channel|>analysis…final format Adds a test suite covering single/multiple/unterminated blocks for both formats, plus extractReasoningFromMessage edge cases.
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.
What
removeReasoningContent(used byuseTokensCountto compute what gets sent to the model) only removed the first completethinking… responseblock and completely ignored unterminated blocks:thinking…block with no closing tag — it was never removed at all.Both cases meant reasoning content leaked into the token count and, potentially, into the prompt sent to the model.
Fix
thinking… responseblock (global replace) instead of the first match.thinking…block.<|channel|>analysis<|message|>…<|start|>assistant<|channel|>final<|message|>format.Verification
web-app/src/utils/__tests__/reasoning.test.ts, 12 tests) covering single / multiple / unterminated blocks for both formats plusextractReasoningFromMessageedge cases.tsc -bclean,eslint0 errors, fullutilssuite 67/67 pass.