fix(telegram): apply MarkdownV2 entity safety trim to streaming chunks#446
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
visyat
approved these changes
May 4, 2026
This was referenced May 29, 2026
patrick-chinchill
added a commit
to Chinchill-AI/chat-sdk-python
that referenced
this pull request
May 29, 2026
Alpha sync starter for upstream chat@4.29.0 (release commit 6581d31, May 18 2026). Upstream skipped tagging chat@4.27.0 and chat@4.28.0; chat@4.29.0 is the next real tag. - Bumps version → 0.4.29a1 - Bumps UPSTREAM_PARITY → "4.29.0" - Updates README, CLAUDE.md, CHANGELOG with in-flight status and full porting plan Pre-audit (this session's scoping subagents) found two items already done in 0.4.27 — no work needed: - vercel/chat#446 (Telegram MarkdownV2 streaming-chunk safety trim) — PR #89 helpers cover it - vercel/chat#475 (private → protected internals) — Python _underscore convention already provides this Detailed scope, design issues (#109 chat/ai, #110 Messenger), and open questions in CHANGELOG entry. Tracking issue: #98.
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.
summary
streaming chunks under 4096 chars bypassed
trimToMarkdownV2SafeBoundarybecause the guard only ran on length-overflow truncation. during LLM streaming, intermediate edits with unclosed entity markers (e.g._All timestamps are *UTC*mid-sentence) were sent directly to Telegram and rejected withBad Request: can't parse entitiesthe fix applies the safety trim universally for MarkdownV2 messages and makes the trim fence-aware so code blocks with literal
*/_characters don't trigger false-positive strippingtrimToMarkdownV2SafeBoundarywhen text is under the limit (not just on overflow)findUnescapedPositionsOutsideCodehelper that skips markers inside fenced/inline code