Skip to content

fix(telegram): keep chunk markers outside code fences (#48517) - #50010

Merged
teknium1 merged 1 commit into
mainfrom
salvage/telegram-chunk-fence-48517
Jun 21, 2026
Merged

fix(telegram): keep chunk markers outside code fences (#48517)#50010
teknium1 merged 1 commit into
mainfrom
salvage/telegram-chunk-fence-48517

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

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 from gateway/platforms/telegram.py to plugins/platforms/telegram/adapter.py since 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_split finalize, 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

Before After
Split inside fenced code block closing fence + (1/2) on one line → MarkdownV2 rejected → plain text indicator on its own line → fence stays valid

161/161 tests pass across tests/gateway/test_telegram_format.py + tests/gateway/test_telegram_rich_messages.py.

Infographic

telegram-chunk-fence-fix

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
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/telegram-chunk-fence-48517 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11281 on HEAD, 11281 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5915 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels Jun 21, 2026
@teknium1
teknium1 merged commit 796f618 into main Jun 21, 2026
35 checks passed
@teknium1
teknium1 deleted the salvage/telegram-chunk-fence-48517 branch June 21, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants