← Back to PRs

#18935: fix(agents): suppress reasoning blocks from channel delivery

by BinHPdev open 2026-02-17 06:08 View on GitHub →
channel: mattermost agents size: M
## 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