Skip to content

fix(telegram): clip mid-stream overflow instead of splitting (#48648) - #51736

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-2c9d618e
Jun 24, 2026
Merged

fix(telegram): clip mid-stream overflow instead of splitting (#48648)#51736
teknium1 merged 1 commit into
mainfrom
hermes/hermes-2c9d618e

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Telegram streamed replies that grow past 4096 chars no longer spawn an infinite nested-reply duplication loop.

Root cause: edit_message's overflow split ran on every streamed edit (finalize=False included). Splitting moves the active message ID to a continuation, so the next accumulated-token edit re-splits the full text — looping once per token after the limit is hit.

Changes

  • plugins/platforms/telegram/adapter.py: gate _edit_overflow_split on finalize. Mid-stream, truncate to a single preview message via new _truncate_stream_overflow_preview helper (keeps editing the same ID). Fixes both the pre-flight path and the reactive message_too_long catch. Full content is still split-and-delivered on finalize=True.
  • tests/gateway/test_telegram_format.py: flip the existing continuation-split test to finalize=True (splitting is now finalize-only), add two mid-stream truncation tests.

Validation

Before After
7 growing oversized mid-stream edits N continuation messages (loop) 0 continuations, message_id stable
finalize=True splits splits, full content delivered (2 continuations)

Targeted tests: 4 passed. E2E (real edit_message, mocked bot): mid-stream continuation sends = 0, ID stays put, finalize delivers full content.

Credit

Salvaged from #50408 by @Tranquil-Flow (authorship preserved via rebase-merge). Closes #48648. Supersedes duplicate fixes #48663 (@liuhao1024, earliest submitter), #48718 (@kyssta-exe), #51266 (@RichardAtCT) — those targeted the pre-refactor path gateway/platforms/telegram.py, which no longer exists.

Infographic

Telegram stream overflow duplication loop fixed

@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-2c9d618e vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11175 on HEAD, 11173 on base (🆕 +2)

🆕 New issues (2):

Rule Count
unresolved-attribute 2
First entries
run_agent.py:2984: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`

✅ Fixed issues (1):

Rule Count
invalid-assignment 1
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`

Unchanged: 5899 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(telegram): Infinite streamed message duplication loop during 4096-char overflow

3 participants