← Back to PRs

#17254: fix(discord): intercept text-based slash commands instead of forwarding to agent (#16433)

by robbyczgw-cla open 2026-02-15 15:35 View on GitHub →
channel: discord size: XS experienced-contributor
## Problem When a user types `/reset`, `/new`, `/status`, etc. as plain text in Discord (instead of using the slash command picker), the message is forwarded to the agent session as regular text. The agent then interprets it creatively — potentially resetting workspaces, deleting files, or other destructive actions. Fixes #16433 ## Solution Add a preflight check in `preflightDiscordMessage()` that detects text-based slash commands using the existing `hasControlCommand()` function and drops them before they reach the agent. Proper Discord slash command interactions (via the interaction system) are unaffected. ## Changes - `src/discord/monitor/message-handler.preflight.ts` — 8 lines: check `hasControlCommand(baseText, params.cfg)` after text resolution, return `null` with verbose logging if matched - Adjusted the preflight behavior to preserve legitimate status-reply flow (including `responsePrefix`) so `/status` handling still sends the expected prefixed response ## Testing Existing Discord tests pass. The check uses the same `hasControlCommand` function that other channels rely on for slash command detection. ## Local Validation - `pnpm build` ✅ - `pnpm check` (oxlint) ✅ - Relevant test suites pass ✅ ## Contribution Checklist - [x] Focused scope — single fix per PR - [x] Clear "what" + "why" in description - [x] AI-assisted (Codex/Claude) — reviewed and tested by human - [x] Local validation run (`pnpm build && pnpm check`) *AI-assisted (Claude). Reviewed by human. <!-- greptile_comment --> <h3>Greptile Summary</h3> Intercepts text-based slash commands (e.g. `/reset`, `/new`) in Discord guild channels so they are dropped before reaching the agent, preventing unintended destructive actions. DMs are excluded from interception so `/status` and `/help` continue to work. Also fixes a consistency gap in `createInboundDebouncer` where the non-debounced flush path was missing error handling. - **Slash command interception**: Added `hasControlCommand()` check gated by `!isDirectMessage` in `preflightDiscordMessage()`, placed after text resolution but before channel activity recording - **Debounce error handling**: Wrapped the non-debounced `onFlush` path in try/catch with `onError` callback, matching the existing pattern in `flushBuffer` - Both changes are low-risk: the interception uses an existing detection function with strict command matching, and all production debouncer callers already provide `onError` handlers <h3>Confidence Score: 5/5</h3> - This PR is safe to merge — both changes are minimal, defensive, and use existing well-tested functions. - Score of 5 reflects: (1) the preflight interception uses the existing `hasControlCommand()` function that other channels already rely on, (2) the `!isDirectMessage` guard correctly preserves DM command handling, (3) the debounce error handling fix mirrors an existing pattern already present in the same file, and (4) all production callers already provide the `onError` callback. The changes are well-scoped and introduce no new behavior beyond the intended fix. - No files require special attention. <sub>Last reviewed commit: 97e0a57</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs