Repository navigation
fix(runtime): drop intermediate monologue text blocks from visible delivery - #96969
SymbolStar wants to merge 2 commits into
Conversation
|
Thanks for the context here. I did a careful shell check against current Close: current main has a broader producer-owned phase fix that prevents this same interleaved reasoning/text leak before channel delivery, making this consumer-side heuristic unnecessary and unsafe. So I’m closing this as already implemented rather than keeping a duplicate issue open. Review detailsBest possible solution: Keep the current producer-owned phase classification and terminal delivery gate; do not retain a cross-provider consumer heuristic. Do we have a high-confidence way to reproduce the issue? No on current main: the historic interleaving shape is now producer-phase-tagged and delivery withholds it until classification; the prior defect remains source-reproducible from the branch's test shape. Is this the best way to solve the issue? No: the consumer ordering heuristic is not the best fix because it cannot distinguish legitimate visible interleaving; current main records that fact at the stream producer. Security review: Security review cleared: The diff adds no dependency, workflow, credential, permission, or supply-chain surface; its concern is output correctness rather than a new security mechanism. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against ebe9d38a5f92; fix evidence: commit 78b8f8cf6647, main fix timestamp 2026-08-17T14:47:58+05:30. |
…livery Providers like MiniMax-M3 via openai-completions emit internal monologue as plain `type: "text"` content blocks interleaved with native `type: "thinking"` blocks, without any phase metadata. The native reasoning seal in the streaming partitioner closes the open thought before each visible-text region but does not retroactively mark the preceding text region as commentary. Unphased extraction therefore joined every text block, leaking monologue prose to channel deliveries. This is the root cause behind openclaw#96849 (Discord main-session deliveries mix model thinking content into the visible reply for MiniMax-M3). The existing `stripReasoningTagsFromText` pipeline is a no-op because the monologue is plain prose without `<think>` tags. Fix in the shared text-extraction layer (used by all channel deliveries and history reads): an unphased text block is treated as intermediate monologue iff a later thinking block exists with another text block after it. That `text -> thinking -> text` pattern is the signature of provider-routed monologue. Models that emit a trailing reflective thinking block after their final answer (`text -> thinking`) keep their text untouched, and messages without thinking blocks are unaffected. Regression coverage in src/shared/chat-message-content.test.ts: - exact openclaw#96849 transcript shape -> only final text block delivered - text -> thinking only -> final text preserved - pure text-only content -> all text preserved Fixes openclaw#96849
…tractor (openclaw#96849) Reviewer clawsweeper (P1) noted the Discord main-session final delivery path flows through src/agents/embedded-agent-utils.ts `extractAssistantVisibleText` (invoked by embedded-agent-subscribe.handlers.messages), not the shared chat-message-content extractor patched in the initial commit. So the first fix did not close the leak on the actual delivery hot path. This commit: - Extracts the intermediate-monologue detection into a shared exported helper `isIntermediateMonologueTextBlock` in src/shared/chat-message-content.ts (avoiding duplication). - Reuses that helper inside embedded-agent-utils.ts `extractAssistantTextForPhase` so unphased text blocks matching the text -> thinking -> text signature are dropped before delivery. - Adds regression tests in src/agents/embedded-agent-utils.test.ts using the exact openclaw#96849 6-block MiniMax-M3 transcript, plus guards for the text -> thinking (post-answer reflection) and text-only shapes. Refs openclaw#96849
858496a to
fabcd9a
Compare
|
@clawsweeper re-review please — round 2 (fabcd9a) moves the fix onto the actual Discord main-session delivery path ( |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Gentle nudge — R2 fix (commit |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Fix Discord main-session replies leaking model thinking content for providers
like MiniMax-M3 via the openai-completions API.
The fix is in the shared assistant-text extraction layer
(
src/shared/chat-message-content.ts) rather than the Discord plugin, becausethe same root cause affects every channel that reads
extractAssistantVisibleText/
extractAssistantTextForPhase(Telegram, mirror writes, session transcripts).Discord just happens to be where #96849 was first observed.
Root Cause
MiniMax-M3 emits internal monologue as plain
type: "text"content blocksinterleaved with native
type: "thinking"blocks, with no phase metadata:[ { "type": "thinking", "thinking": "Gabe is asking me to confirm..." }, { "type": "thinking", "thinking": "Excellent! Key info..." }, { "type": "text", "text": "All done. Let me give Gabe a clean status update..." }, { "type": "thinking", "thinking": "Let me give Gabe a tight summary..." }, { "type": "thinking", "thinking": "Also, this message is the verification test..." }, { "type": "text", "text": "Done. Here's the final status: ..." } ]sealNativeReasoningBeforeText()inopenai-completions.tscloses the openthinking block when visible-text deltas begin, but it does not retroactively
mark the preceding text region as commentary. So
extractAssistantTextForPhasejoined every unphased text block, concatenating the monologue with the final
answer. The Discord
sanitizeAssistantVisibleText/stripReasoningTagsFromTextpipeline is a no-op here because the monologue text contains no
<think>tags.Isolated sessions are unaffected because cron
agentTurndoesn't use thestreaming subscription path — it reads payloads through a different lane that
doesn't depend on this extraction.
Fix
Heuristic in
extractAssistantTextForPhase: an unphasedtextblock atindex
iis treated as intermediate monologue iff there is athinkingblock at
j > iAND anothertextblock atk > j. Thattext → thinking → textshape is the smoking gun for provider-routed monologue — the modeltalked, thought again, then produced its real answer.
Properties:
text → thinkingonly (post-answer reflective thinking) → final text is preservedtextSignature.phase) → unchanged behaviorextractAssistantText(no-phase variant used byextractAssistantThinkingcallers etc.) is intentionally untouched — that helper is consumed by paths
that need the full text including monologue for replay/diagnostics
Real Behavior Proof
Targeted unit tests pass; full Discord/Telegram delivery suites unaffected.
Before (with the exact #96849 transcript shape): visible reply was
"All done. Let me give Gabe a clean status update...\nDone. Here's the final status: ...".After: visible reply is
"Done. Here's the final status: ...".Regression Test Plan
Added to
src/shared/chat-message-content.test.tsinside theextractAssistantVisibleTextdescribe block:drops unphased text blocks emitted before a later thinking block—uses the exact 6-block transcript from the issue body. Asserts the visible
text equals only the trailing
textblock (the final answer), never theearlier monologue text block.
keeps unphased final text even when a trailing thinking block follows—thinking → text → thinkingshape. Asserts the text block is preserved(post-answer reflective thinking must not drop the final answer).
keeps all text when no thinking blocks are present— pure text-onlycontent. Asserts joining behavior is unchanged when no thinking interleave
exists.
The 16 pre-existing tests in the file continue to pass, including:
Files Touched
src/shared/chat-message-content.ts— heuristic added insideextractAssistantTextForPhasesrc/shared/chat-message-content.test.ts— 3 regression testsFixes #96849
Update — round 2 (fabcd9a): fix on the actual delivery path
Thanks @clawsweeper for the P1 catch. You're right: the Discord main-session final delivery does not go through
src/shared/chat-message-content.tsextractAssistantTextForPhase. It goes throughsrc/agents/embedded-agent-utils.tsextractAssistantVisibleText, called fromsrc/agents/embedded-agent-subscribe.handlers.messages.ts. The first patch only closed the shared/history path — not the hot path.This round:
chat-message-content.tsinto a shared exportisIntermediateMonologueTextBlock(content, index, hasExplicitPhasedTextBlocks)— same heuristic (unphasedtextat indexiis monologue iff athinkingblock exists atj > iAND anothertextblock exists atk > j), no logic drift.embedded-agent-utils.tsextractAssistantTextForPhaseso the delivery-path extractor drops the same blocks the shared extractor drops. No duplication.src/agents/embedded-agent-utils.test.tsusing the exact 6-block MiniMax-M3 transcript from [Bug]: Discord plugin leaks model thinking content in main-session replies #96849, plus the two guard cases (text -> thinkingonly = keep; text-only = keep).Local vitest (delivery-path + shared extractor):
The new
#96849 delivery pathtest fails againstmainand passes with this commit — that's the delivery-layer proof that the leak is closed at the extractor called byembedded-agent-subscribe.handlers.messages.On the "Real behavior proof" workflow
That CI check is label-gated and needs live Discord runtime capture, which I don't have credentials for locally. Please retrigger / grant the label once you're satisfied with the delivery-path unit test, or point me at the exact fixture format if you'd like this reproduced through a mocked transport rig instead.