Skip to content

fix(discord): handle character limits and maintain typing status#323

Open
Andyi955 wants to merge 5 commits intosipeed:mainfrom
Andyi955:fix/discord-message-limit
Open

fix(discord): handle character limits and maintain typing status#323
Andyi955 wants to merge 5 commits intosipeed:mainfrom
Andyi955:fix/discord-message-limit

Conversation

@Andyi955
Copy link

Overview

This PR improves the reliability and user experience of the Discord channel by fixing 400 errors caused by message length limits and ensuring the bot's activity status is accurately reflected during processing.

Key Changes

Discord Message Handling

  • Rune-Based Message Splitting: Replaced the previous byte-based splitting logic with a more robust rune-based system. This ensures that the bot stays strictly within Discord's 2000-character limit regardless of multi-byte characters (emojis, etc.) while preserving the integrity of Markdown code blocks.
  • Chunk Delivery: Added a reliable multi-chunk delivery system that ensures long responses are broken into coherent segments rather than being cut off.

User Experience Improvements

  • Persistent Typing Heartbeat: Implemented a background routine to maintain the "Bot is typing..." indicator during long-running tasks. This prevents the status from timing out while the agent is iterating through tools or performing complex reasoning, providing better feedback to the user.
  • Threshold Notification: Softened the memory threshold warning message to be more user-friendly.

Tool Stability

  • Improved Path Validation: Updated the safety guard logic in pkg/tools/shell.go to correctly handle scoped package names (e.g. @mastra/core) during command execution. This fixes a bug where legitimate npm commands were incorrectly flagged as path traversal attempts.

Technical Details

  • Modified Components:
    • pkg/channels/discord.go: Logic for message chunking and typing status synchronization.
    • pkg/tools/shell.go: Refined regex for safe path validation.
    • pkg/agent/loop.go: Updated notification messaging.

Verification

  • Successfully tested with responses over 4000 characters via Discord.
  • Verified that the typing indicator remains active throughout the entire agent loop duration.
  • Confirmed that commands using modern package management syntax are correctly allowed while system security remains intact.

@Andyi955 Andyi955 force-pushed the fix/discord-message-limit branch from 5a1b392 to 9161279 Compare February 16, 2026 18:14
@Leeaandrob
Copy link
Collaborator

@Zepan Discord character limit handling and auto-split, plus typing indicator improvements. PR #143 (merged) already addressed message splitting — this PR improves on that implementation.

Recommendation: Merge. Solid UX improvement for Discord users. +194/-95 is reasonable scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants