feat(channels): adopt Telegram Bot API 10.1 rich-text formatting and fix guest-mode escaping#6604
Merged
Merged
Conversation
…fix guest-mode escaping Guest-mode responses (TelegramChannel::flush_chunks) now format through the same markdown_to_telegram renderer used by regular messages and send with parse_mode="MarkdownV2" instead of an unconverted "HTML" call, which previously either broke Telegram's HTML parser or rendered literal Markdown to guest users. TelegramRenderer now prefixes every line of a multi-line blockquote with ">" (previously only the first line was quoted), and nested blockquotes flatten to a single level instead of accumulating an unescaped ">>", which Telegram's MarkdownV2 grammar rejects outright (400 can't parse entities, dropping the whole message). A nesting-depth cap (MAX_BLOCKQUOTE_NESTING_DEPTH = 512, same pattern as MAX_CHUNK_DEPTH from #6595) bounds tracked-mark memory for adversarially deep input. Adds TelegramConfig.expandable_blockquote_min_lines (default 10): blockquotes at or above the threshold render as Bot API 10.1's expandable (collapsed-by-default) form; 0 disables it unconditionally. Wired into --init and --migrate-config. Also wires TelegramConfig.guest_mode/.bot_to_bot into create_channel — these fields were previously accepted but never threaded into the TelegramChannel builder, so Guest Mode and Bot-to-Bot were unreachable in a running agent even with both enabled. Fixes a latent crash this exposed: the Guest Mode proxy's TcpListener was never set non-blocking before handing it to tokio, which panics on recent tokio versions. Closes #6541
bug-ops
enabled auto-merge (squash)
July 20, 2026 18:53
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
TelegramChannel::flush_chunks) now format through the samemarkdown_to_telegramrenderer used by regular messages, sendingparse_mode = "MarkdownV2"instead of an unconverted"HTML"call that previously either broke Telegram's HTML parser or rendered literal Markdown to guest users.TelegramRenderernow prefixes every line of a multi-line blockquote with>(previously only the first line was quoted). Nested blockquotes flatten to a single>-per-level instead of accumulating an unescaped>>, which Telegram's MarkdownV2 grammar rejects outright (400 can't parse entities, dropping the whole message). AMAX_BLOCKQUOTE_NESTING_DEPTH = 512cap (same pattern asMAX_CHUNK_DEPTHfrom fix(index,core): add depth-cap guards against unbounded recursion DoS #6595) bounds tracked-mark memory for adversarially deep input.TelegramConfig.expandable_blockquote_min_lines(default10): blockquotes at or above the threshold render as Bot API 10.1's expandable (collapsed-by-default) form;0disables it unconditionally. Wired into--initand--migrate-config.TelegramConfig.guest_mode/.bot_to_botintocreate_channel— these fields were previously accepted but never threaded into theTelegramChannelbuilder, so Guest Mode and Bot-to-Bot were unreachable in a running agent even with both enabled (found during review; scope expanded with user approval since otherwise this PR's own guest-mode fix could never be live-verified).TcpListenerwas never set non-blocking before being handed to tokio, which panics on recent tokio versions the first timeguest_mode = trueis actually reached.specs/007-channels/007-1-telegram-guest-mode.mdand correctsspecs/007-channels/007-3-telegram-rich-text.md§10's nested-blockquote edge case (the originally-specified "cumulative depth" approach was invalid MarkdownV2; flattening is correct).book/src/guides/telegram.md.Closes #6541
Test plan
cargo nextest run— zeph-channels, zeph-config, zeph, zeph-core all green (4543/4543 in the final developer run; reviewer independently re-ran and confirmed 4396 passed/0 failed/14 skipped)cargo test --doc— passingcargo +nightly fmt --check— cleancargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warnings— clean (independently re-run by reviewer)gitleaks protect --staged— no leaksmin_lines,min_lines = 0disables expandable, nested-blockquote flattening (depth 20 and depth 600-over-cap), special chars inside a blockquote line,create_channelwiring ofguest_mode/bot_to_botfrom configmarkdown.rs/telegram.rssuites pass unchanged (no weakened assertions — diffed to confirm)migrate_telegram_expandable_blockquote_config) has dedicated behavioral tests (append/noop-no-section/noop-already-present/idempotent).local/testing/playbooks/telegram.mdbut not yet run against a live bot; tracked as a follow-up live-verification step, not blocking merge given the extensive unit coverage and doc-confirmed MarkdownV2 grammar checks performed during review