Repository navigation
Description
Problem
When an agent writes narration text before making tool calls (e.g., "Let me check the recent conversation context to understand..."), this text is delivered to the Feishu streaming card and visible to the end user. This creates a confusing experience — the user sees internal reasoning that was not intended as part of the reply.
Before vs after
This behavior appeared after upgrading the gateway from 2026.3.13 to 2026.3.22. We suspect the fix in #36957 ("pre-tool text is preserved in live chat deltas/finals") changed the delivery semantics — previously, pre-tool text was silently dropped in Feishu cards; now it is retained and displayed.
The original fix was correct for the TUI/WebChat (where losing text was a bug), but for Feishu (and likely other messaging channels), showing pre-tool narration creates UX issues:
- Users see English "thinking out loud" text mixed into their native-language conversation
- Intermediate reasoning appears as part of the reply, making it feel unfinished or broken
- Users may think the model changed or something is misconfigured
Expected behavior
Pre-tool narration text should not be delivered to Feishu (and other messaging channels) as visible content. Only the final text — after all tool calls complete — should be sent.
Current workaround
Instructing the agent in AGENTS.md to never narrate before tool calls. This works but is fragile and suppresses narration that may be useful in other contexts (TUI, WebChat).
Proposed solution
A per-channel or global config option to suppress pre-tool text delivery to messaging channels. Something like:
{
channels: {
feishu: {
suppressPreToolText: true // only deliver final text after tool calls
}
}
}Or integrate with the existing blockStreamingBreak semantics:
"message_end"should naturally suppress pre-tool text by waiting for the full response
Related issues
- Suppress intermediate text output before tool calls in group channels #50989 — Suppress intermediate text output before tool calls in group channels (same root cause, different channel)
- Intermediate assistant text leaks to Mattermost channels as unthreaded messages during multi-step tool calls #45134 — Intermediate assistant text leaks to Mattermost channels
- [Bug]: TUI: streaming text still lost during tool calls despite #10704 fix (2026.3.2) #36957 — The fix that introduced pre-tool text retention in streaming
Environment
- Gateway:
2026.3.22 - Channel: Feishu (websocket mode, streaming cards enabled)
- Model: Claude (Anthropic API)
- Config: default
blockStreamingDefault(off), Feishustreaming: true,blockStreaming: true
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
kagura-chen commentedon Mar 24, 2026
Investigation — Root Cause Analysis
After tracing the code path, here is a detailed analysis.
The delivery pipeline for Feishu streaming cards
Key observation: Feishu explicitly sets
disableBlockStreaming: true(reply-dispatcher.ts:482) and usesonPartialReplyfor streaming instead. This meansonPartialReplyfires on everytext_deltaevent, not just final text.What happens with pre-tool text
text_deltaevents fire →onPartialReplyupdates streaming cardtext_deltaevents fire againmergeStreamingText()(streaming-card.ts:114) merges old + new textAdditionally,
buildEmbeddedRunPayloads()(payloads.ts) iterates over all entries inassistantTexts[], which includes both pre-tool and post-tool text segments.Why this wasn't visible before 2026.3.22
In
2026.3.13, the#36957fix ("pre-tool text is preserved in live chat deltas/finals") changed howassistantTextsaccumulates text. Before that fix, pre-tool text segments were dropped during streaming, soonPartialReplywould only fire for the final text block. After the fix, all text segments are retained — which is correct for TUI/WebChat but creates this UX issue for messaging channels.Possible solutions (in order of preference)
Per-channel
onPartialReplyfiltering: ThehandleMessageUpdatehandler could check a flag (e.g.,suppressPreToolPartials) and only emitonPartialReplyfor text in the final assistant message (i.e., after the last tool call). This requires knowing whether the current text will be followed by tool calls — which isn't known at streaming time.mergeStreamingTextreset on new assistant message: When a newmessage_startfires after a tool call, resetstreamTextin the Feishu dispatcher so the new text doesn't get concatenated with old pre-tool text. The streaming card would show only the latest text segment.Channel-level
suppressIntermediateTextconfig (as proposed in Suppress intermediate text output before tool calls in group channels #50989): Drop all text segments except the last one inbuildEmbeddedRunPayloadswhen configured. This would fix the final delivery but not the streaming preview.blockStreamingBreak: "message_end"as workaround: Setting this would delay text emission until the full message is complete. But since Feishu usesonPartialReply(not block streaming), this alone wouldn't help —onPartialReplystill fires during streaming regardless ofblockStreamingBreak.Current workaround
Instructing the agent to never write narration before tool calls (via AGENTS.md
"do not narrate routine tool calls"). Effective but fragile.Config-level workaround?
Setting
channels.feishu.streaming: falsewould disable the streaming card entirely and wait for the full reply. This would eliminate the pre-tool text preview issue, but also removes the real-time streaming experience. Not ideal.Environment
blockStreamingDefault: off (default)disableBlockStreaming: true (hardcoded in feishu reply-dispatcher)kagura-chen commentedon Mar 24, 2026
Correction: Root cause is NOT the 2026.3.22 upgrade
After further investigation with the user, the behavior was not present yesterday despite running the same gateway version (2026.3.22). The issue only started in today's session.
Reviewing the session JSONL confirms:
Revised root cause
The actual issue is that
onPartialReplyin the Feishu streaming card path faithfully renders alltext_deltaevents, including pre-tool narration. This has always been the case — but it only becomes a UX problem when the model writes significant amounts of narration text before tool calls.The original issue request remains valid: there should be a way for messaging channels to suppress intermediate text that precedes tool calls, regardless of whether the model chooses to narrate or not. But the #36957 attribution was incorrect — the pre-tool text was already being rendered in streaming cards before that fix.
Summary
steipete commentedon Apr 25, 2026
Closing this as implemented after Codex review.
Current
mainalready suppresses commentary/pre-tool assistant text before channel partial delivery, which prevents Feishu streaming cards from showing that narration.What I checked:
handleMessageUpdatereturns immediately when the resolved delivery phase iscommentary, before anyonPartialReplycallback can fire. That prevents pre-tool narration from reaching channel preview streams. (src/agents/pi-embedded-subscribe.handlers.messages.ts:471, 8f64cd3e4d83)handleMessageEndalso suppresses commentary-phase assistant messages from user-visible output, so commentary-only assistant messages are not emitted at message end either. (src/agents/pi-embedded-subscribe.handlers.messages.ts:624, 8f64cd3e4d83)onPartialReplypayloads for live card updates, so the core suppression above directly fixes the Feishu surface described in the issue. (extensions/feishu/src/reply-dispatcher.ts:495, 8f64cd3e4d83)onPartialReply, do not emit block replies, and do not populate stored assistant text. (src/agents/pi-embedded-subscribe.subscribe-embedded-pi-session.suppresses-commentary-phase-output.test.ts:10, 8f64cd3e4d83)text_endflushes are suppressed, including visible commentary text and textSignature-only phase metadata. (src/agents/pi-embedded-subscribe.handlers.messages.test.ts:414, 8f64cd3e4d83)So I’m closing this as already implemented rather than keeping a duplicate issue open.
Review notes: reviewed against 8f64cd3e4d83; fix evidence: commit 8f64cd3e4d83.