Skip to content

fix(telegram): keep MarkdownV2 on flood finalize edits - #69642

Open
rsk-731 wants to merge 1 commit into
NousResearch:mainfrom
rsk-731:fix/telegram-flood-mdv2-plain-fallback
Open

fix(telegram): keep MarkdownV2 on flood finalize edits#69642
rsk-731 wants to merge 1 commit into
NousResearch:mainfrom
rsk-731:fix/telegram-flood-mdv2-plain-fallback

Conversation

@rsk-731

@rsk-731 rsk-731 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Telegram finalize edits treated flood control / RetryAfter like a MarkdownV2 parse failure and fell back to plain text.
  • That made final replies look unrendered after rate limits (common when streaming/progress spam trips flood control).
  • Flood errors now re-raise into the existing wait/retry path; short floods retry still as MarkdownV2; plain fallback stays for real parse failures only.
  • Added regression tests in tests/gateway/test_telegram_format.py.

Root cause

In TelegramAdapter.edit_message(finalize=True), the MarkdownV2 edit_message_text except-block stripped formatting on any error, including:
Flood control exceeded. Retry in N seconds

Test plan

  • pytest tests/gateway/test_telegram_format.py::TestEditMessageStreamingSafety -q
  • pytest tests/gateway/test_telegram_final_delivery.py::test_telegram_long_flood_result_keeps_retry_after -q
  • Manual: enable TG streaming, trip a short flood, confirm finalize still has bold/code (or clean flood fallback send with MarkdownV2), not stripped plain

Notes

Operational mitigation still useful on busy bots: keep Telegram tool_progress / streaming quiet to avoid flooding the Bot API.

Flood control / RetryAfter was treated like a MarkdownV2 parse failure
during finalize edits, so the adapter stripped formatting and fell back
to plain text. Users then saw unrendered final replies after rate limits.

Re-raise flood errors into the existing wait/retry path, retry short
floods still as MarkdownV2, and reserve plain fallback for real parse
failures only.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins platform/telegram Telegram bot adapter duplicate This issue or pull request already exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #52933: both preserve MarkdownV2 for transient Telegram flood-control errors instead of treating them as parse failures. #52933 is the broader open repair for the same final/overflow edit policy.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for isolating the normal finalized-edit failure: current main still catches every MarkdownV2 edit error and strips formatting (plugins/platforms/telegram/adapter.py:4768-4790).

Problems

  • The overflow change does not actually enter the existing edit retry handler. The preflight path returns _edit_overflow_split(...) directly (plugins/platforms/telegram/adapter.py:4734-4738); that helper catches the reraised error and returns a generic failure without retry_after (plugins/platforms/telegram/adapter.py:4969-4980). The proposed overflow re-raise therefore avoids the immediate plain fallback but neither retries as MarkdownV2 nor preserves Telegram's requested delay.
  • The new tests cover normal finalized edits only. Add coverage for the overflow first-chunk flood path, which currently has the parallel plain fallback at plugins/platforms/telegram/adapter.py:4944-4962.

Suggested changes

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades 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.

3 participants