← Back to PRs

#5982: fix: sanitize model reasoning blocks from Discord output

by Ambar-13 open 2026-02-01 05:13 View on GitHub →
channel: discord size: S
**Description:** ## Problem Models like Gemini 3 Pro, Kimi K2.5, and Grok emit internal reasoning blocks (`<think>...</think>`, `Thought:...`) which were being sent to Discord verbatim, leaking chain-of-thought and causing stalled outputs during tool calls. ## Solution Sanitizes assistant output at the Discord provider boundary (`send.shared.ts`), removing reasoning-only blocks while preserving user-facing responses. ## Testing - Added comprehensive test suite with 9 test cases - All tests passing - Handles multiple reasoning formats (Gemini, Grok, DeepSeek, Kimi) Fixes #5946 <h2>**Comment not updated to current version**</h2> <!-- greptile_comment --> <h6>Greptile Overview</h6> <h6>Greptile Summary</h6> This PR adds a Discord-boundary sanitizer (`sanitizeModelOutput`) in `src/discord/send.shared.ts` to strip common “reasoning” formats (e.g., `<think>…</think>`, `Thought:` blocks, and bracket/paren markers) before chunking/sending messages, aiming to prevent chain-of-thought leakage and tool-call stalls. It also adds a standalone `test-sanitizer.js` script with several example cases. Main concerns are around edge-case behavior: `sendDiscordText` now throws when sanitization removes everything (which can turn “reasoning-only” outputs into hard send failures), and the `Thought:` regex doesn’t behave consistently at the beginning of the string due to missing multiline anchoring. Additionally, the provided tests are not integrated into the repo’s Vitest suite, so they won’t run in CI by default. <h3>Confidence Score: 3/5</h3> - This PR is likely safe to merge after addressing a couple edge-case behavior issues. - Core change is localized to Discord send boundary and is conceptually straightforward, but there are a few behavior gaps: (1) sending can now hard-fail if output is fully sanitized away, and (2) the `Thought:` removal regex doesn’t match start-of-string as intended. The added tests are not wired into CI, so correctness relies on manual execution unless converted to Vitest. - src/discord/send.shared.ts; test-sanitizer.js <!-- greptile_other_comments_section --> <!-- /greptile_comment —>

Most Similar PRs