fix(chat): preserve text around stray think-close after a complete block - #4191
Open
skyzhao1223 wants to merge 1 commit into
Open
fix(chat): preserve text around stray think-close after a complete block#4191skyzhao1223 wants to merge 1 commit into
skyzhao1223 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Description
stripThinkTags(used byMessageText,autoTitle,getLastAssistantTextandturnCopyto clean AI replies before rendering) had a destructive bug: its MiniMax step deleted everything up to the first orphaned closing think tag, even when the message contained a complete<thinking>…</thinking>block plus a stray trailing close.Example:
START <thinking>secret</thinking> MIDDLE </thinking> ENDwas stripped to" END", silently losing the legitimateSTARTandMIDDLEtext from the rendered message. That combination (a balanced block followed by a leftover close tag from concatenated tool-call output) is exactly the case Step 4 was documented to handle by removing "just the tags".This fix:
Related Issues
No existing issue tracked this; discovered during code review of
thinkTagFilter.ts.Type of Change
fix— Bug fix (non-breaking change which fixes an issue)feat— New feature (non-breaking change which adds functionality)perf— Performance improvementrefactor— Code restructuring (no behavior change)docs— Documentation updateAtomic PR Checklist (Rule 1)
<type>(<scope>): <subject>(English)Local Checks (Rule 3)
bun run format— formatting passesbun run lint— no lint errors (skip if no.ts/.tsxchanged)bunx tsc --noEmit— no type errors (skip if no.ts/.tsxchanged)bunx vitest run— tests passbun run i18n:types+node scripts/check-i18n.js) — only ifsrc/renderer/,locales/, orsrc/common/config/i18n/changed; N/A otherwiseRuntime Verification
Screenshots
N/A (pure string-processing change, covered by unit tests).
Additional Context
tests/unit/renderer/utils/thinkTagFilter.test.tsfor both the "complete block + stray close" and the standalone-orphan-close cases." END"for the input above, the new one returns"START MIDDLE END".bunx tsc --noEmitlocally reports one pre-existing error (Cannot find module 'mermaid') that also occurs on a clean checkout ofmain— it is an environment/dependency issue unrelated to this change.