fix(telegram): keep chunk markers outside code fences (#48517) - #50010
Merged
Conversation
When truncate_message appends a (N/M) chunk indicator to a chunk that had to close an in-progress fenced code block, the marker lands on the closing fence line (``` \(1/2\) after MarkdownV2 escaping). Telegram does not treat that as a clean closing fence and rejects the MarkdownV2, falling back to plain text. Move the indicator onto its own line right after the closing fence at all three legacy-send call sites. Fixes #48517
Contributor
🔎 Lint report:
|
This was referenced Jul 30, 2026
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.
Summary
Telegram code-fenced replies that get split mid-fence no longer fall back to broken plain text. When
truncate_message()appended a(N/M)chunk indicator to a chunk that had to close an in-progress fenced code block, the marker landed on the closing-fence line —``` \(1/2\)after MarkdownV2 escaping. Telegram doesn't treat that as a clean closing fence, rejects the MarkdownV2, and degrades the whole chunk to plain text. The fix moves the indicator onto its own line right after the closing fence.Salvages #48517 by @whoislikemiha, reconstructed onto current
main(the Telegram adapter moved fromgateway/platforms/telegram.pytoplugins/platforms/telegram/adapter.pysince the PR). Authorship preserved.Closes #48517.
Changes
plugins/platforms/telegram/adapter.py: new_separate_chunk_indicator_from_fence()helper; applied at all three legacy-send call sites (initial chunking,_edit_overflow_splitfinalize, and the markdown retry path).tests/gateway/test_telegram_format.py: asserts no sent chunk has a(N/M)marker fused to a```fence line.Validation
(1/2)on one line → MarkdownV2 rejected → plain text161/161 tests pass across
tests/gateway/test_telegram_format.py+tests/gateway/test_telegram_rich_messages.py.Infographic