fix(telegram): always apply MarkdownV2 formatting on edit_message - #42423
Closed
ToBAIaeS wants to merge 1 commit into
Closed
fix(telegram): always apply MarkdownV2 formatting on edit_message#42423ToBAIaeS wants to merge 1 commit into
ToBAIaeS wants to merge 1 commit into
Conversation
Collaborator
ToBAIaeS
force-pushed
the
fix/telegram-edit-message-markdownv2
branch
from
June 8, 2026 22:50
4b228a5 to
e6e0aba
Compare
Previously, edit_message(finalize=False) sent content as plain text without parse_mode=MarkdownV2, while edit_message(finalize=True) and send() both applied MarkdownV2 formatting. This caused tool progress edits to replace a correctly formatted message with raw markdown text, breaking code blocks, headers, bold, and other formatting in the Telegram chat. The fix always applies format_message() + parse_mode=MARKDOWN_V2 regardless of the finalize flag, with the same fallback to plain text on parse errors. Added logging for the fallback case (previously silent). Fixes: NousResearch#25710 (related)
ToBAIaeS
force-pushed
the
fix/telegram-edit-message-markdownv2
branch
from
June 8, 2026 23:05
e6e0aba to
78c7e22
Compare
Author
|
Thanks @alt-glitch for the pointer! #42421 addresses Bug 1 (the
Both are independent of the |
Author
|
Closing in favor of a new focused PR for the remaining bugs (code-block escaping issues). Bug 1 (edit_message finalize) is already fixed by #42421. |
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.
Update
Bug 1 (
edit_message(finalize=False)skips MarkdownV2) is now fixed by #42421 (merged). This PR now focuses on the two remaining bugs that weren't addressed:Bug 2: Incomplete escaping inside fenced code blocks and inline code (still present)
format_message()step 1 (_protect_fenced) and step 2 (inline code) only escaped\and`inside code content. Per the Telegram MarkdownV2 spec, all 12 special characters must be escaped inside<pre>/<code>too:Unescaped
#in shell comments,!in output,-in flags, etc. causedCan't parse entities: character '#' is reservederrors from the Telegram API. The fallback (plain text, previously unlogged) then replaced the formatted message with raw text.Fix:
_protect_fenced()and_protect_inline()now use_escape_mdv2()to escape all 12 MarkdownV2 special characters inside code blocks and inline code.Bug 3: Triple-backticks in terminal commands break code-block detection (still present)
When a terminal command contains
```sequences (e.g.gh pr edit --bodywith code examples), the non-greedy regex([\s\S]*?)informat_message()matches the inner```as a closing fence, splitting the outer bash code block into multiple fragments. Content between the fragments (### Bug 2: ...) is left unprotected and rendered as raw markdown.Fix:
run.py_bash_blockconstruction now escapes inner```sequences before wrapping in the outer fenced block.Testing
Verified on a live Hermes gateway (3 profiles, Telegram DM):
#comments → renders correctly ✅#,!,-,+,.→ all escaped and preserved ✅sequences → single code block ✅