fix(gateway): format-then-chunk in Telegram overflow split - #43470
fix(gateway): format-then-chunk in Telegram overflow split#43470annguyenNous wants to merge 1 commit into
Conversation
_edit_overflow_split() chunked raw text first, then formatted each chunk with MarkdownV2. The escaping inflated each chunk past the 4096 UTF-16 limit, Telegram rejected every formatted attempt with MESSAGE_TOO_LONG, and the fallbacks delivered raw Markdown markers literally. Align with send() which formats first and then chunks the already- formatted text. Continuation chunks and fallback paths now strip MarkdownV2 escapes before sending as plain text. Fixes NousResearch#43441
Code Review: Single-chunk fallback re-formats already-formatted contentThanks for the PR! The format-then-chunk approach is correct — formatting raw text before chunking prevents MarkdownV2 escapes from inflating past However, there's a double-formatting issue in the single-chunk fallback path. When # Line 18: content is formatted once
formatted = self.format_message(content)
chunks = self.truncate_message(formatted, ...)
# Line 36: single-chunk fallback re-formats the ORIGINAL content
chunks = [content if not finalize else self.format_message(content)]
For MarkdownV2, Fix: Use if len(chunks) <= 1:
chunks = [formatted if finalize else content]This correctly reuses the already-formatted text when |
|
Closing as duplicate — #43458 (liuhao1024) covers the same format-before-chunk fix for the Telegram overflow split and is already under review. |
Fixes #43441
Problem
In Telegram bound/forum topics, final replies arrive showing raw Markdown markers literally. The root cause:
_edit_overflow_split()chunks raw text first, then formats each chunk with MarkdownV2. The escaping inflates each chunk past the 4096 limit, Telegram rejects every formatted attempt, and the fallback delivers raw markers.Fix
finalize=True: format content first, then chunk (matchingsend()order)(1/N)chunk indicators for MarkdownV2Testing
ast.parse()passesfinalize=Falsepath unchanged