Skip to content

fix(stream_consumer): use truncate_message for overflow splitting - #6816

Closed
dangelo352 wants to merge 1 commit into
NousResearch:mainfrom
dangelo352:fix/stream-consumer-truncation
Closed

fix(stream_consumer): use truncate_message for overflow splitting#6816
dangelo352 wants to merge 1 commit into
NousResearch:mainfrom
dangelo352:fix/stream-consumer-truncation

Conversation

@dangelo352

Copy link
Copy Markdown
Contributor

Bug

Long streamed messages were silently cut off on Telegram when exceeding ~3900 characters.

Root cause

The overflow split loop in stream_consumer.py required self._message_id is not None to enter, but on the first streamed message _message_id starts as None. The loop never ran, so text over the safe limit was passed unsplit to Telegram, which rejected it with 'message too long' and broke streaming silently.

Fix

Replace the broken manual split with self.adapter.truncate_message() — the same helper the non-streaming path already uses. Properly splits on word/newline boundaries, preserves code fences, and adds chunk indicators like (1/3). Each overflow chunk is sent as a new threaded message via the new _send_new_chunk() helper.

File

gateway/stream_consumer.py

Test

Send any request that produces a response over ~3900 chars to Telegram. Before: silent cut-off. After: clean split into (1/2), (2/2) etc.

The overflow split loop required self._message_id is not None to run,
but on the first streamed message self._message_id starts as None.
This caused text exceeding ~3900 chars to be passed unsplit to Telegram,
which rejected it with 'message too long' and broke streaming silently.

Replace the broken manual split with self.adapter.truncate_message()
(same helper the non-streaming path uses), which properly splits on
word/newline boundaries, preserves code fences, and adds chunk indicators
like (1/3). Each overflow chunk is sent as a new threaded message.

Add _send_new_chunk() helper to send each overflow chunk as a new
message threaded to the previous one for clean grouping.
teknium1 pushed a commit that referenced this pull request Apr 9, 2026
The overflow split loop required _message_id to be set, but on the
first streamed message (or after a segment break) _message_id is None.
Oversized text fell through to _send_or_edit → adapter.send(), which
split internally — but subsequent edits hit Telegram's 'message too
long' and were silently truncated with '…', cutting off the response.

Add a new code path for the _message_id is None case that uses
truncate_message() (same as the non-streaming path) to split with
proper word/code-fence boundaries and chunk indicators. Each chunk
is sent as a new message via _send_new_chunk().

Properly handles got_done (returns immediately after sending chunks
instead of continuing into an infinite loop) and got_segment_break.

Original cherry-picked from PR #6816 by dangelo352.

Fixes silent message truncation on Telegram for long streamed responses.
teknium1 pushed a commit that referenced this pull request Apr 9, 2026
The overflow split loop required _message_id to be set, but on the
first streamed message (or after a segment break) _message_id is None.
Oversized text fell through to _send_or_edit → adapter.send(), which
split internally — but subsequent edits hit Telegram's 'message too
long' and were silently truncated with '…', cutting off the response.

Add a new code path for the _message_id is None case that uses
truncate_message() (same as the non-streaming path) to split with
proper word/code-fence boundaries and chunk indicators. Each chunk
is sent as a new message via _send_new_chunk().

Properly handles got_done (returns immediately after sending chunks
instead of continuing into an infinite loop) and got_segment_break.

Original cherry-picked from PR #6816 by dangelo352.

Fixes silent message truncation on Telegram for long streamed responses.
@teknium1

teknium1 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #6828. Your commit was cherry-picked onto current main with your authorship preserved in git log. The fix was adjusted to preserve the existing while loop for the existing-message case, fix a continue that would skip got_done handling (infinite loop), and drop a broken regex. Thanks for catching this!

@teknium1 teknium1 closed this Apr 9, 2026
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
The overflow split loop required _message_id to be set, but on the
first streamed message (or after a segment break) _message_id is None.
Oversized text fell through to _send_or_edit → adapter.send(), which
split internally — but subsequent edits hit Telegram's 'message too
long' and were silently truncated with '…', cutting off the response.

Add a new code path for the _message_id is None case that uses
truncate_message() (same as the non-streaming path) to split with
proper word/code-fence boundaries and chunk indicators. Each chunk
is sent as a new message via _send_new_chunk().

Properly handles got_done (returns immediately after sending chunks
instead of continuing into an infinite loop) and got_segment_break.

Original cherry-picked from PR NousResearch#6816 by dangelo352.

Fixes silent message truncation on Telegram for long streamed responses.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
The overflow split loop required _message_id to be set, but on the
first streamed message (or after a segment break) _message_id is None.
Oversized text fell through to _send_or_edit → adapter.send(), which
split internally — but subsequent edits hit Telegram's 'message too
long' and were silently truncated with '…', cutting off the response.

Add a new code path for the _message_id is None case that uses
truncate_message() (same as the non-streaming path) to split with
proper word/code-fence boundaries and chunk indicators. Each chunk
is sent as a new message via _send_new_chunk().

Properly handles got_done (returns immediately after sending chunks
instead of continuing into an infinite loop) and got_segment_break.

Original cherry-picked from PR NousResearch#6816 by dangelo352.

Fixes silent message truncation on Telegram for long streamed responses.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
The overflow split loop required _message_id to be set, but on the
first streamed message (or after a segment break) _message_id is None.
Oversized text fell through to _send_or_edit → adapter.send(), which
split internally — but subsequent edits hit Telegram's 'message too
long' and were silently truncated with '…', cutting off the response.

Add a new code path for the _message_id is None case that uses
truncate_message() (same as the non-streaming path) to split with
proper word/code-fence boundaries and chunk indicators. Each chunk
is sent as a new message via _send_new_chunk().

Properly handles got_done (returns immediately after sending chunks
instead of continuing into an infinite loop) and got_segment_break.

Original cherry-picked from PR NousResearch#6816 by dangelo352.

Fixes silent message truncation on Telegram for long streamed responses.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
The overflow split loop required _message_id to be set, but on the
first streamed message (or after a segment break) _message_id is None.
Oversized text fell through to _send_or_edit → adapter.send(), which
split internally — but subsequent edits hit Telegram's 'message too
long' and were silently truncated with '…', cutting off the response.

Add a new code path for the _message_id is None case that uses
truncate_message() (same as the non-streaming path) to split with
proper word/code-fence boundaries and chunk indicators. Each chunk
is sent as a new message via _send_new_chunk().

Properly handles got_done (returns immediately after sending chunks
instead of continuing into an infinite loop) and got_segment_break.

Original cherry-picked from PR NousResearch#6816 by dangelo352.

Fixes silent message truncation on Telegram for long streamed responses.
skappafrost pushed a commit to skappafrost/hermes-agent that referenced this pull request Aug 15, 2026
The overflow split loop required _message_id to be set, but on the
first streamed message (or after a segment break) _message_id is None.
Oversized text fell through to _send_or_edit → adapter.send(), which
split internally — but subsequent edits hit Telegram's 'message too
long' and were silently truncated with '…', cutting off the response.

Add a new code path for the _message_id is None case that uses
truncate_message() (same as the non-streaming path) to split with
proper word/code-fence boundaries and chunk indicators. Each chunk
is sent as a new message via _send_new_chunk().

Properly handles got_done (returns immediately after sending chunks
instead of continuing into an infinite loop) and got_segment_break.

Original cherry-picked from PR NousResearch#6816 by dangelo352.

Fixes silent message truncation on Telegram for long streamed responses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants