#18935: fix(agents): suppress reasoning blocks from channel delivery
channel: mattermost
agents
size: M
Cluster:
Telegram Message Handling Fixes
## Summary
- Suppress reasoning/thinking blocks from channel delivery (iMessage, Telegram, Discord, etc.) so internal chain-of-thought is never forwarded to end users.
## Root Cause
Two code paths injected reasoning text into channel delivery:
1. **Streaming path** (`handlers.messages.ts`): `shouldEmitReasoning` gated on `onBlockReply` being truthy — meaning reasoning was emitted *specifically when* a channel callback existed. This is backwards: reasoning should be suppressed when a channel callback is present.
2. **Final payload builder** (`payloads.ts`): Unconditionally pushed formatted reasoning into `replyItems` when `reasoningLevel === "on"`. This `replyItems` array feeds directly into channel delivery for all channels.
## Changes
- `src/agents/pi-embedded-subscribe.handlers.messages.ts`: Invert `onBlockReply &&` to `!onBlockReply &&` in `shouldEmitReasoning` condition, suppressing reasoning emission to channels while preserving non-channel behavior.
- `src/agents/pi-embedded-runner/run/payloads.ts`: Remove unconditional reasoning push to `replyItems` and clean up unused imports (`extractAssistantThinking`, `formatReasoningMessage`).
- `src/agents/pi-embedded-runner/run/payloads.reasoning.test.ts`: 2 tests verifying reasoning is not included in payloads and assistant answers still work normally.
## Test plan
- [x] `pnpm vitest run src/agents/pi-embedded-runner/` — 25 tests pass
- [ ] Verify reasoning blocks no longer appear as messages in iMessage/Telegram/Discord when `reasoningLevel: "on"`
Fix #18667
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes reasoning/thinking blocks leaking into channel messages (iMessage, Telegram, Discord) by suppressing them from two code paths:
- **Final payload builder** (`payloads.ts`): cleanly removed reasoning from `replyItems` array
- **Streaming path** (`handlers.messages.ts`): inverted condition but created contradictory logic where `maybeEmitReasoning()` still calls `onBlockReply` which no longer exists
Key issues:
- The streaming path fix has a logic bug where the condition requires `!onBlockReply` but then tries to call `onBlockReply?.()`, effectively disabling reasoning emission (achieves the goal but via confusing dead code)
- Existing test `emits-reasoning-as-separate-message-enabled.e2e.test.ts` expects the old behavior and will fail
- PR only ran `pi-embedded-runner/` tests, missing the failing test in `pi-embedded-subscribe`
<h3>Confidence Score: 2/5</h3>
- not safe to merge - has logic bug and failing test
- the streaming path contains contradictory logic (inverted condition but unchanged emission target) and an existing test will fail. while the goal is achieved (reasoning suppression), the implementation needs cleanup
- `src/agents/pi-embedded-subscribe.handlers.messages.ts` has contradictory logic, and `emits-reasoning-as-separate-message-enabled.e2e.test.ts` needs update
<sub>Last reviewed commit: 6c5b0c2</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#18187: fix: tool summaries silently dropped when reasoningLevel is stream
by ayanesakura · 2026-02-16
78.8%
#17694: fix(telegram): send reasoning before main text in stream mode
by ayanesakura · 2026-02-16
78.7%
#6685: fix: suppress thinking leak for Synthetic reasoning models
by AkiLetschne · 2026-02-01
78.2%
#17455: fix: strip content before orphan closing think tags
by jwt625 · 2026-02-15
76.6%
#13235: feat: stream reasoning_content via /v1/chat/completions SSE
by mode80 · 2026-02-10
76.5%
#17953: fix(telegram): prevent silent message loss and duplicate messages i...
by zuyan9 · 2026-02-16
75.0%
#10430: fix: remove Minimax from isReasoningTagProvider
by echoedinvoker · 2026-02-06
74.9%
#14977: fix(telegram): remove ack reaction after block-streamed replies
by Diaspar4u · 2026-02-12
74.8%
#19407: fix(agents): strip thinking blocks on cross-provider model switch (...
by lailoo · 2026-02-17
74.6%
#23462: fix: extract thinking blocks as fallback in extractTextFromChatContent
by nszhsl · 2026-02-22
74.4%