Skip to content

fix(telegram): aggregate split text messages before dispatching#1674

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-f685e964
Mar 17, 2026
Merged

fix(telegram): aggregate split text messages before dispatching#1674
teknium1 merged 1 commit intomainfrom
hermes/hermes-f685e964

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

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:

  1. First chunk → starts the agent
  2. Second chunk → interrupts the running agent or queues as a separate turn
  3. Agent only sees partial input

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 period
  • Timer resets on each new chunk so all parts arrive before dispatch
  • Configurable via HERMES_TELEGRAM_TEXT_BATCH_DELAY_SECONDS env 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.

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.
@teknium1 teknium1 merged commit d156942 into main Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant