fix: streaming message length overflow + Telegram error handling#1783
Merged
fix: streaming message length overflow + Telegram error handling#1783
Conversation
Stream consumer now splits messages that exceed the platform's MAX_MESSAGE_LENGTH. When accumulated text grows past the safe limit, the current message is finalized and a new message is started for the overflow — same as how normal sends chunk long responses. Split point prefers line boundaries (rfind newline) for clean breaks. Works for all platforms (Telegram 4096, Discord 2000, etc.) by reading the adapter's MAX_MESSAGE_LENGTH at runtime. Also added a safety net in the Telegram adapter: if edit_message_text still hits MESSAGE_TOO_LONG (e.g. markdown formatting expansion), it truncates and returns success so the stream consumer doesn't die.
1822356 to
eebdb47
Compare
This was referenced Mar 18, 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.
Summary
When a streamed response grows past Telegram's 4096-char limit (or Discord's 2000, etc.),
editMessageTextfails withMESSAGE_TOO_LONGand the stream consumer treats it as an edit failure — killing streaming entirely. Normal sends chunk long responses, but streaming didn't.Fix: Stream consumer overflow splitting
The
run()loop now checks accumulated text againstadapter.MAX_MESSAGE_LENGTHbefore each edit. When the text exceeds the safe limit:_message_idso the next edit sends a fresh messageWorks for all platforms — reads the adapter's
MAX_MESSAGE_LENGTHat runtime (Telegram 4096, Discord 2000, Slack 39000, etc.).Safety net: Telegram adapter
If
editMessageTextstill hitsMESSAGE_TOO_LONG(e.g. markdown formatting expanding the text), the adapter truncates and returnssuccess=Trueinstead of killing the stream.Files changed
gateway/stream_consumer.py— Overflow split loop inrun()gateway/platforms/telegram.py—MESSAGE_TOO_LONGhandler inedit_message()Test plan