fix(telegram): aggregate split text messages before dispatching#1674
Merged
fix(telegram): aggregate split text messages before dispatching#1674
Conversation
When a user sends a long message, Telegram clients split it into multiple updates that arrive within milliseconds of each other. Previously each chunk was dispatched independently — the first would start the agent, and subsequent chunks would interrupt or queue as separate turns, causing the agent to only see part of the message. Add text message batching to TelegramAdapter following the same pattern as the existing photo burst batching: - _enqueue_text_event() buffers text by session key, concatenating chunks that arrive in rapid succession - _flush_text_batch() dispatches the combined message after a 0.6s quiet period (configurable via HERMES_TELEGRAM_TEXT_BATCH_DELAY_SECONDS) - Timer resets on each new chunk, so all parts of a split arrive before the batch is dispatched Reported by NulledVector on Discord.
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 this PR does
Fixes the bug where Telegram splits a long user message into multiple updates and the agent only processes the first chunk.
The problem
When a user sends a message longer than ~4096 chars, Telegram clients split it into multiple messages that arrive as separate updates within milliseconds. Previously, each chunk was dispatched independently:
The fix
Add text message batching to
TelegramAdapter, following the exact same pattern as the existing photo burst batching:_enqueue_text_event()— buffers text by session key, concatenating chunks_flush_text_batch()— dispatches the combined message after a 0.6s quiet periodHERMES_TELEGRAM_TEXT_BATCH_DELAY_SECONDSenv var (default: 0.6s)Tests
5 new tests covering single message dispatch, 2-way and 3-way split aggregation, cross-chat isolation, and cleanup.
Reported by NulledVector on Discord.