fix(gateway): apply MarkdownV2 formatting on Telegram progress message edits - #42421
Merged
Merged
Conversation
When a platform adapter sets REQUIRES_EDIT_FINALIZE=True (e.g. TelegramAdapter), tool progress edits now pass finalize=True so format_message() is applied before sending to the platform. Previously, the initial send() formatted the message correctly via MarkdownV2, but subsequent edit_message() calls skipped formatting (finalize=False), causing raw markdown (e.g. triple backticks for bash code blocks) to render as plain text on Telegram. Refs: #41955, #41732
…old handling When edit_message(finalize=True) fails with a MarkdownV2 parse error, the silent fallback previously sent raw content with escape sequences. Now it logs the error and strips markdown formatting via _strip_mdv2() for clean plain-text fallback. Also fixes _strip_mdv2 to handle standard markdown bold (\*\*text\*\*) before MarkdownV2 bold (\*text\*), preventing half-stripped asterisks. Refs: #41955, #41732
9 tasks
This was referenced Jun 10, 2026
9 tasks
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 tool-progress bubble edits now re-apply MarkdownV2 formatting instead of leaving raw markdown visible, and the MarkdownV2 edit fallback degrades to clean plain text instead of dumping escape sequences.
Root cause: progress edits call
edit_message()withfinalize=False(the default), which takes the plain-text branch and skipsformat_message(). The initialsend()formats correctly; subsequent edits did not — so markdown in a progress bubble rendered raw after the first tool update.Changes
gateway/run.py:_edit_progress_messagenow passesfinalize=Truefor adapters withREQUIRES_EDIT_FINALIZE(Telegram, DingTalk), routing edits through the same MarkdownV2 pipeline as the initial send. Zero effect on other platforms (flag defaults False).gateway/platforms/telegram.py: MarkdownV2 edit-failure fallback now strips markdown via_strip_mdv2()(so users see clean text, not\n/##/**) and logs the parse error;_strip_mdv2()also strips standard**bold**.scripts/release.py: AUTHOR_MAP entry for @ruangraung.Validation
finalize=False)format_message()applied,parse_mode=MARKDOWN_V2tests/gateway/test_telegram_format.pyedit_message)_strip_mdv2('a **bold** b')→a bold bRefs #41955, #41732. Complementary to #42420 (which restores truncated previews for terminal commands in default modes) — this fix keeps progress edits formatting-correct for verbose mode and any markdown progress content. Salvaged from #42308 onto current main; @ruangraung's commit authorship preserved.
Infographic