You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Telegram: sendRichMessageDraft works but final message falls back to MarkdownV2 (expect_edits kills rich path) #46515
When Telegram rich messages are enabled and draft-based streaming is active, the sendRichMessageDraft preview renders correctly during streaming (user sees rich tables, formatting, etc.), but the final persistent message is sent as plain MarkdownV2 instead of via sendRichMessage.
Root Cause
In gateway/stream_consumer.py line 1535, when the final message is created after draft streaming completes (first real send, _message_id is None, finalize=True):
The expect_edits: True flag passes through to _should_attempt_rich() in gateway/platforms/telegram.py line 988:
andnot (metadataor {}).get("expect_edits")
This check DISABLES sendRichMessage for the final delivery, forcing a fallback to sendMessage with MarkdownV2. The user sees a beautiful rich table during the streaming preview, then it gets replaced by plain text.
Expected Behavior
When finalize=True and draft-based streaming was used (not edit-based), the expect_edits flag should be False since no further edits will be made. This would allow sendRichMessage to persist the same rich formatting shown in the draft preview.
Steps to Reproduce
Enable telegram.extra.rich_messages: true in config
Send a message to the bot that triggers a response with tables/lists
Watch the streaming draft — it renders as rich markdown ✅
When streaming completes, the final message is plain MarkdownV2 ❌
Evidence
Gateway log shows streamed=True previewed=False content_delivered=True — the normal final send is suppressed because the stream consumer already delivered content. But that delivery uses the expect_edits path which skips sendRichMessage. No errors appear in the logs because the sendRichMessage attempt is logged at debug level and expect_edits prevents the attempt entirely.
Environment
Hermes version: 0.16.0 (config v29)
python-telegram-bot: latest (Bot API 10.1 endpoints available)
macOS, Telegram Desktop
Reacted by shaggy2626, Dante Sparrås and Pedro Otalora
Hit this exact symptom today on main (commit 36ae95847). Confirming the root-cause analysis is correct and adding log evidence from my session.
What the user sees
I sent a ~2800-char reply containing a markdown pipe table and a few code fences. On Telegram the user only saw roughly the first 2-3 lines of the response — the rest vanished. The gateway log shows the response was 3463 chars and marked content_delivered=True. The user reported three separate times that the message was truncated; on resend it worked (when I kept the reply under ~2200 chars).
Gateway log evidence
2026-06-22 19:26:42,110 gateway.run: Suppressing normal final send for session agent:main:telegram:dm:7276844555:
final delivery already confirmed (streamed=True previewed=False content_delivered=True).
2026-06-22 19:26:42,110 gateway.run: response ready: platform=telegram chat=7276844555 time=90.3s
api_calls=5 response=3463 chars
Matches the signature in the original issue exactly. Preview shows table correctly; final persists as MarkdownV2.
Additional finding: MarkdownV2 parse failure during streaming is a secondary trigger
A few days earlier I hit a related failure mode that's probably the same root cause with a different symptom. Log excerpt from 2026-06-21 06:55:17:
gateway.platforms.telegram: [Telegram] MarkdownV2 parse failed, falling back to plain text:
Can't parse entities: character '.' is reserved and must be escaped with the preceding '\'
gateway.platforms.telegram: [Telegram] Telegram flood control on send (attempt 1/3),
retrying in 226.0s: Flood control exceeded. Retry in 226 seconds
MarkdownV2 parse fails on unescaped characters → fallback to plain-text edit
Flood control kicks in on the plain-text retry
content_delivered=True is set somewhere in the fallback chain
The "real" final sendMessage is suppressed by gateway/run.py
The fix proposed in #49452 (Option A — wire a send_rich_finalize so the final send uses sendMessage with rich param rather than editMessageText with MarkdownV2) would resolve this whole class.
Workaround for end users until merged
Keep individual Telegram replies under ~2200 chars and avoid markdown pipe tables. MarkdownV2 falls back to plain text for tables anyway, so tables buy you nothing in Telegram rendering today — use code fences for tabular data.
Repro recipe
telegram.extra.rich_messages: true (default)
Trigger a streaming reply that includes a markdown pipe table AND at least one inline period inside a code span or unescaped . in a bold/italic span
Watch the streaming draft — table renders ✅
Watch the finalize — table converts to bullet list, response truncates ❌
gateway.log shows content_delivered=True + a MarkdownV2 parse-failed warning within ~1s of finalize
Thanks for the precise root cause! Fixed on main by 0f22727 ("omit expect_edits on finalized draft sends"): the finalize send now passes expect_edits=not finalize (gateway/stream_consumer_transport.py), so _should_attempt_rich allows sendRichMessage for the final. Please reopen if a current build still falls back to MarkdownV2.
Triaged in the Telegram backlog sweep against origin/main @ 787ee80. If this still reproduces on a current build, reply with the version and steps and we'll reopen.
Activity
learhy commentedon Jun 22, 2026
Independent reproduction + additional evidence (session 2026-06-22)
Hit this exact symptom today on
main(commit36ae95847). Confirming the root-cause analysis is correct and adding log evidence from my session.What the user sees
I sent a ~2800-char reply containing a markdown pipe table and a few code fences. On Telegram the user only saw roughly the first 2-3 lines of the response — the rest vanished. The gateway log shows the response was 3463 chars and marked
content_delivered=True. The user reported three separate times that the message was truncated; on resend it worked (when I kept the reply under ~2200 chars).Gateway log evidence
Matches the signature in the original issue exactly. Preview shows table correctly; final persists as MarkdownV2.
Additional finding: MarkdownV2 parse failure during streaming is a secondary trigger
A few days earlier I hit a related failure mode that's probably the same root cause with a different symptom. Log excerpt from 2026-06-21 06:55:17:
Sequence in the streaming consumer appears to be:
editMessageTextwith MarkdownV2 (perprefers_fresh_final_streaming = Falseatgateway/platforms/telegram.py:1011-1023, see also [Telegram] Markdown pipe tables converted to bullet lists in streaming finalization #49452)content_delivered=Trueis set somewhere in the fallback chainsendMessageis suppressed bygateway/run.pyThe fix proposed in #49452 (Option A — wire a
send_rich_finalizeso the final send usessendMessagewith rich param rather thaneditMessageTextwith MarkdownV2) would resolve this whole class.Workaround for end users until merged
Keep individual Telegram replies under ~2200 chars and avoid markdown pipe tables. MarkdownV2 falls back to plain text for tables anyway, so tables buy you nothing in Telegram rendering today — use code fences for tabular data.
Repro recipe
telegram.extra.rich_messages: true(default)code spanor unescaped.in a bold/italic spangateway.logshowscontent_delivered=True+ a MarkdownV2 parse-failed warning within ~1s of finalizeAffected version:
36ae95847 feat(gateway): gate message timestamps behind opt-in (default off)onmain.Platform: Telegram Desktop (latest), python-telegram-bot v22.x, Bot API 10.1.
fix(telegram): allow legacy MarkdownV2 fallback for rich path on pre-…
teknium1 commentedon Nov 8, 2026
Thanks for the precise root cause! Fixed on main by 0f22727 ("omit expect_edits on finalized draft sends"): the finalize send now passes expect_edits=not finalize (gateway/stream_consumer_transport.py), so _should_attempt_rich allows sendRichMessage for the final. Please reopen if a current build still falls back to MarkdownV2.
Triaged in the Telegram backlog sweep against
origin/main@ 787ee80. If this still reproduces on a current build, reply with the version and steps and we'll reopen.