fix(telegram): truncate mid-stream overflow instead of splitting - #48663
Closed
liuhao1024 wants to merge 2 commits into
Closed
fix(telegram): truncate mid-stream overflow instead of splitting#48663liuhao1024 wants to merge 2 commits into
liuhao1024 wants to merge 2 commits into
Conversation
When streamed content exceeds Telegram's 4096 UTF-16 code-unit limit, edit_message() unconditionally called _edit_overflow_split — even during streaming (finalize=False). The split spawns continuation messages and updates the active message_id; the next token edit carries the full accumulated text (still > limit), triggering another split, creating an infinite chain of duplicate replies. Fix: when finalize=False, truncate the preview to 4000 code-units (safe margin below 4096) and fall through to the normal edit path. The real split only fires on finalize=True (stream complete). Fixes NousResearch#48648
The PR changes mid-stream overflow from splitting into continuations to truncating the preview (to prevent infinite reply chains). Update the existing tests in test_telegram_format.py to match the new behavior: - finalize=False: truncate, no continuations - finalize=True: split into continuations with topic metadata
Contributor
|
Closing as superseded by #51736 (merged to |
This was referenced Jul 30, 2026
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.
What does this PR do?
Fixes an infinite message duplication loop in the Telegram adapter when streamed content exceeds the 4096 UTF-16 code-unit limit. During streaming (
finalize=False), the pre-flight overflow check unconditionally called_edit_overflow_split, which spawned continuation messages and updated the activemessage_id. On the next token, the full accumulated text (still > 4096) was edited to the new message, triggering another split — creating an infinite chain of duplicate replies.The fix: when
finalize=Falseand content exceeds the limit, truncate the preview to 4000 code-units (safe margin below 4096) and fall through to the normal edit path. The real split only happens whenfinalize=True(stream complete).Related Issue
Fixes #48648
Type of Change
Changes Made
gateway/platforms/telegram.py: Inedit_message(), whenfinalize=Falseand content exceedsMAX_MESSAGE_LENGTH, truncate to 4000 code-units instead of calling_edit_overflow_split. The split path is preserved forfinalize=True.tests/gateway/test_telegram_overflow_truncation.py: 3 regression tests — mid-stream truncation, finalize-True split, and under-limit passthrough.How to Test
python -m pytest tests/gateway/test_telegram_overflow_truncation.py -v— all 3 tests should passChecklist
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/ACode Intelligence
gateway/platforms/telegram.py::edit_message(callers: stream_consumer, gateway run.py)_edit_overflow_splitat L2804 handles chunked delivery on finalize; this fix defers to it