Skip to content

fix: streaming message length overflow + Telegram error handling#1783

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

fix: streaming message length overflow + Telegram error handling#1783
teknium1 merged 1 commit intomainfrom
hermes/hermes-e2084cc7

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

When a streamed response grows past Telegram's 4096-char limit (or Discord's 2000, etc.), editMessageText fails with MESSAGE_TOO_LONG and 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 against adapter.MAX_MESSAGE_LENGTH before each edit. When the text exceeds the safe limit:

  1. Finalizes the current message at a clean line break (or at the limit if no good break exists)
  2. Resets _message_id so the next edit sends a fresh message
  3. Continues streaming into the new message

Works for all platforms — reads the adapter's MAX_MESSAGE_LENGTH at runtime (Telegram 4096, Discord 2000, Slack 39000, etc.).

Safety net: Telegram adapter

If editMessageText still hits MESSAGE_TOO_LONG (e.g. markdown formatting expanding the text), the adapter truncates and returns success=True instead of killing the stream.

Files changed

  • gateway/stream_consumer.py — Overflow split loop in run()
  • gateway/platforms/telegram.pyMESSAGE_TOO_LONG handler in edit_message()

Test plan

  • 1035 gateway + streaming tests pass
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.
@teknium1 teknium1 force-pushed the hermes/hermes-e2084cc7 branch from 1822356 to eebdb47 Compare March 17, 2026 18:00
@teknium1 teknium1 merged commit 2fa33dd into main Mar 17, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant