fix(telegram): split long messages and sanitize markdown instead of truncating#141
Merged
xlabtg merged 3 commits intoxlabtg:mainfrom Apr 5, 2026
Merged
fix(telegram): split long messages and sanitize markdown instead of truncating#141xlabtg merged 3 commits intoxlabtg:mainfrom
xlabtg merged 3 commits intoxlabtg:mainfrom
Conversation
Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: xlabtg#137
…runcating Fixes xlabtg#137 Root causes addressed: 1. Long responses (>4096 chars) were truncated with "..." — now split into multiple parts at natural break points (paragraph, line, word boundaries) while avoiding splits inside fenced code blocks. 2. Empty fenced code blocks rendered as blank rectangles in Telegram — now removed before sending. 3. Unclosed code fences caused Telegram to misrender the rest of the message — now auto-closed with a warning log entry. 4. 4+-backtick fences unsupported by Telegram — normalized to ```. New files: - src/telegram/message-splitter.ts — splitMessageForTelegram() - src/telegram/sanitize-markdown.ts — sanitizeMarkdownForTelegram() - src/telegram/__tests__/message-splitter.test.ts (10 tests) - src/telegram/__tests__/sanitize-markdown.test.ts (13 tests) Modified files: - src/telegram/handlers.ts — use split+sanitize instead of truncation - src/agent/tools/telegram/messaging/send-message.ts — apply sanitization - src/agent/tools/telegram/messaging/edit-message.ts — apply sanitization - src/telegram/__tests__/handlers.test.ts — update truncation test for new behaviour Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
📊 Context and tokens usage:Claude Sonnet 4.6:
Total input tokens: 88.8K + 5.0M cached Claude Haiku 4.5:
Total input tokens: 69.4K + 560.7K cached 🤖 Models used:
📎 Log file uploaded as Gist (1708KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
Author
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
This reverts commit e176fb3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #137
Root Causes & Fixes
1. Truncated responses (Priority 🔴)
Root cause:
handlers.tssimply sliced messages longer thanmax_message_length(default 4096) with"...", discarding all content after the limit.Fix: Replaced truncation with
splitMessageForTelegram()— a new utility that splits at natural break points (paragraph → line → word boundary) while avoiding cuts inside fenced code blocks. Each part is sent as a separate message.2. Empty rectangles / broken formatting (Priority 🔴)
Root cause: Empty fenced code blocks (
```python\n```) render as blank rectangles in Telegram. Unclosed fences cause everything after them to be misrendered.Fix: New
sanitizeMarkdownForTelegram()utility (applied before every send):```when fence count is odd```New Files
src/telegram/message-splitter.tssplitMessageForTelegram(text, maxLength?)src/telegram/sanitize-markdown.tssanitizeMarkdownForTelegram(text)src/telegram/__tests__/message-splitter.test.tssrc/telegram/__tests__/sanitize-markdown.test.tsModified Files
src/telegram/handlers.tssrc/agent/tools/telegram/messaging/send-message.tssrc/agent/tools/telegram/messaging/edit-message.tssrc/telegram/__tests__/handlers.test.tsTest Results
All 23 new tests pass. All 50 existing
handlers.test.tstests pass. Pre-existing failures (@teleton-agent/sdkpackage unbuilt, schema version mismatch) are unrelated to this PR.Backward Compatibility
sanitizeMarkdownForTelegramis a no-op on well-formed markdown.max_message_lengthconfig option continues to control the per-part limit.This PR was created automatically by the AI issue solver