Skip to content

fix(telegram): strip raw markdown in MarkdownV2 fallback paths - #33304

Open
Vitalymt wants to merge 1 commit into
NousResearch:mainfrom
Vitalymt:fix/telegram-markdown-fallback
Open

fix(telegram): strip raw markdown in MarkdownV2 fallback paths#33304
Vitalymt wants to merge 1 commit into
NousResearch:mainfrom
Vitalymt:fix/telegram-markdown-fallback

Conversation

@Vitalymt

Copy link
Copy Markdown

Problem

When Telegram rejects MarkdownV2 formatting in edit_message(), the fallback sends raw content with literal **bold** markers and no parse_mode. The send() method already handles this correctly by calling _strip_mdv2().

Root Cause

Two code paths in edit_message() send text=content without stripping markdown on fallback:

  1. MarkdownV2 parse failure: Falls back to raw content with no parse_mode
  2. Flood control retry: Retries with raw content and no parse_mode

Additionally, _strip_mdv2() didn't handle raw **bold** patterns — only the MarkdownV2-converted *bold*.

Fix

Three changes in gateway/platforms/telegram.py:

  1. _strip_mdv2(): Add regex to strip raw **bold** before the already-handled *bold*
  2. edit_message() MarkdownV2 fallback: Use _strip_mdv2(content) + parse_mode=None (matching send() behaviour)
  3. edit_message() flood-wait retry: Use already-formatted MarkdownV2 text, or fall back to _strip_mdv2()

Plus test update in tests/gateway/test_telegram_format.py.

Testing

All 101 tests in test_telegram_format.py pass.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for tracing the fallback paths. Current main already contains the parse-error fallback and raw-**bold** stripping from this PR's scope (plugins/platforms/telegram/adapter.py:318-321,4012-4036, introduced by f4531feee).

Problems

  • The short flood-control retry is still a live gap: after the initial formatted final edit raises RetryAfter, plugins/platforms/telegram/adapter.py:4085-4089 retries raw content without parse_mode.
  • The PR's test covers parse-error fallback only (tests/gateway/test_telegram_format.py:891-907), not that RetryAfter branch.

Suggested changes

  • Salvage the retry portion into plugins/platforms/telegram/adapter.py, preserving the finalized MarkdownV2 payload and parse mode on retry.
  • Add a RetryAfter regression test asserting the retry arguments.

This is an automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026

@GottZ GottZ left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Summary

Two PRs address the same Telegram MarkdownV2 fallback defect with effectively identical diffs: both strip raw **bold**, send plain text after parse failure, and preserve the formatted payload during flood-control retry. Current main already contains the stripping and parse-error fallback portions, leaving the RetryAfter path as the remaining gap.

Related pull requests

  • #33304 related — (+17/-4) — consolidate here, but revise before merge: despite the keep_open review on #33304, the diff is only partially applicable because main already contains the raw-**bold** stripping and parse-error fallback; retain the still-relevant formatted RetryAfter retry and add the requested regression test for its arguments.
  • #34570 [closed] duplicate — (+17/-4) — duplicate of #33304: its diff is effectively identical and does not add the missing RetryAfter regression test. Although closed, it remains relevant as corroboration of the same failure mode and is superseded by the earlier PR and its contributor review context.

Duplicates

#34570 duplicates #33304; both apply the same production and test changes.

Suggested consolidation

Merge #33304 only after rebasing it onto the current plugins/platforms/telegram/adapter.py implementation, narrowing it to the remaining RetryAfter fix, and adding the contributor-requested RetryAfter regression test; keep #34570 closed as a duplicate of #33304.

Complex graph

flowchart LR
    classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
    classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
    classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
    classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
    classDef best stroke-width:3px,stroke:#b45309
    classDef target stroke-width:3px,stroke:#4338ca
    subgraph Dup33304 ["PRs duplicating each other"]
        P33304["PR #33304 (open)"]
        P34570["PR #34570 (closed)"]
    end
    class P33304 open
    class P34570 closed
    class P33304 target
    click P33304 "https://github.com/NousResearch/hermes-agent/pull/33304"
    click P34570 "https://github.com/NousResearch/hermes-agent/pull/34570"
Loading

Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed or no verify verdict yet (state tag in the node label).

Cross-PR triage: Reviewed 2 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 7 kB of PR diffs, 2 kB of issue/PR text, 1 kB of discussion (2 comments), 1 verify verdict. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

@Vitalymt
Vitalymt force-pushed the fix/telegram-markdown-fallback branch from 51b3c64 to 408061f Compare July 28, 2026 08:27
When edit_message's MarkdownV2 fallback itself hits RetryAfter flood
control, the retry previously sent raw text=content (with literal **bold**
markers) instead of the already-stripped plain text from _strip_mdv2().

Track _last_sent_content through the formatted → fallback flow so the
RetryAfter retry always re-sends the correct content variant.

Regression test: 3-call sequence (formatted → RetryAfter → plain
fallback → RetryAfter → retry succeeds) verifying the retry uses
stripped plain text.

Addresses review feedback on PR NousResearch#33304.
@Vitalymt
Vitalymt force-pushed the fix/telegram-markdown-fallback branch from 408061f to 318732b Compare August 7, 2026 14:56
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 sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants