fix(gateway): keep Telegram UTF-16 split points safe after natural break fallback - #11522
Closed
dwc1997 wants to merge 1 commit into
Closed
fix(gateway): keep Telegram UTF-16 split points safe after natural break fallback#11522dwc1997 wants to merge 1 commit into
dwc1997 wants to merge 1 commit into
Conversation
Collaborator
…tion Re-clamp custom-length split positions after newline/space fallback so Telegram chunks remain UTF-16 safe. Add a regression test to ensure emoji-heavy natural-break chunking always stays encodable and within limits.
dwc1997
force-pushed
the
fix/telegram-utf16-split-boundary
branch
from
May 1, 2026 03:35
fc5f423 to
6541b02
Compare
7 tasks
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.
Re-clamp custom-length split positions after newline/space fallback so Telegram chunks remain UTF-16 safe. Add a regression test to ensure emoji-heavy natural-break chunking always stays encodable and within limits.
What does this PR do?
This PR fixes a Telegram message chunking edge case in
truncate_messagewhenlen_fn=utf16_lenis used.After selecting a natural break (
\nor space), the final split point could drift from the original UTF-16-safe boundary logic. This change re-clamps the split point after natural-break adjustment to ensure every produced chunk remains valid under UTF-16 constraints and safely encodable.A regression test is also added to verify that emoji-heavy messages split by natural breaks remain UTF-16 safe and within configured limits.
Related Issue
Fixes #11467
Type of Change
Changes Made
gateway/platforms/base.py:BasePlatformAdapter.truncate_message(...), added a post-natural-break UTF-16 re-clamp step:_prefix_within_utf16_limit(...)_custom_unit_to_cp(...)when needed to avoid invalid/empty split pointstests/gateway/test_platform_base.py:test_natural_break_split_keeps_utf16_safe_boundariesutf-16-le) and UTF-16 length constraints for emoji-heavy contentHow to Test
python -m pytest -o addopts="-m 'not integration'" tests/gateway/test_platform_base.py -qtest_natural_break_split_keeps_utf16_safe_boundariespasses.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs