fix: strip redundant thinking blocks from visible WS stream replies (#187) - #188
Open
singleGanghood wants to merge 1 commit into
Open
fix: strip redundant thinking blocks from visible WS stream replies (#187)#188singleGanghood wants to merge 1 commit into
singleGanghood wants to merge 1 commit into
Conversation
When a model reports reasoning through the dedicated reasoning stream AND also echoes <think>...</think> blocks into the visible text stream, the plugin forwarded both, producing nested <think> tags that leaked thinking content to WeCom users and duplicated visible text. - add resolveStreamVisibleText(): strip visible-stream thinking blocks only when a reasoning stream is present, preserving the official dynamic thinking stream behavior when the model writes thinking directly into the text stream - use it in finishThinkingStream, sendReasoningUpdate, sendVisibleUpdate, rotateStream and the passive markdown candidate - callback-inbound: parse out thinking blocks before final text resolution Fixes sunnoy#187
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.
Summary
Fixes #187 — model reasoning/thinking content leaked to WeCom users in WS streaming replies, and visible text was duplicated.
Root cause
OpenClaw can deliver thinking content through two independent channels:
onReasoningStream→state.reasoningText)<think>...</think>blocks echoed into the visible text stream (deliver→state.accumulatedText)When both channels carried thinking content (a common pattern with reasoning-capable models),
buildWsStreamContentproduced nested<think>tags like:The WeCom client then surfaced the inner thinking block as visible text and duplicated the visible reply.
Changes
wecom/ws-monitor.jsresolveStreamVisibleText(accumulatedText, reasoningText):<think>blocks echoed into the visible text stream are stripped (they are redundant — the reasoning is already reported via the reasoning stream).ws.e2e.test.js).finishThinkingStream,sendReasoningUpdate,sendVisibleUpdate,rotateStream, and the passive markdown candidate.wecom/callback-inbound.jsresolveCallbackFinalTextnow parses out thinking blocks (viaparseThinkingContent) before normalizing the final reply text, so thinking content never reaches users through the callback path either.Tests
tests/ws-monitor.think-leak.test.js:tests/callback-inbound.test.jsto assert thinking blocks are stripped from the final callback text./private/varsymlink) unrelated to this change.Verification
npm test: 321 pass / 2 fail (2 pre-existing environment failures)matches the official dynamic thinking stream behavior) still passes.