Skip to content

fix(telegram): apply MarkdownV2 entity safety trim to streaming chunks#446

Merged
dancer merged 1 commit into
mainfrom
josh/telegram-streaming-fix
May 4, 2026
Merged

fix(telegram): apply MarkdownV2 entity safety trim to streaming chunks#446
dancer merged 1 commit into
mainfrom
josh/telegram-streaming-fix

Conversation

@dancer
Copy link
Copy Markdown
Collaborator

@dancer dancer commented May 4, 2026

summary

streaming chunks under 4096 chars bypassed trimToMarkdownV2SafeBoundary because 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 with Bad Request: can't parse entities

the 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 stripping

  • apply trimToMarkdownV2SafeBoundary when text is under the limit (not just on overflow)
  • add findUnescapedPositionsOutsideCode helper that skips markers inside fenced/inline code
  • no effect on plain-text messages or other adapters

@dancer dancer requested a review from a team as a code owner May 4, 2026 20:51
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview, Comment, Open in v0 May 4, 2026 8:52pm
chat-sdk-nextjs-chat Ready Ready Preview, Comment, Open in v0 May 4, 2026 8:52pm

@dancer dancer merged commit f46a6fb into main May 4, 2026
13 checks passed
@dancer dancer deleted the josh/telegram-streaming-fix branch May 4, 2026 21:00
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants