fix(discord): dedup saturated mid-stream overflow previews to stop edit-rate-limit storms - #58912
Merged
teknium1 merged 1 commit intoJul 5, 2026
Conversation
…it-rate-limit storms a0a3c71 fixed the exact same failure mode for Telegram (NousResearch#58563): post-NousResearch#48648, oversized mid-stream edits truncate to a one-message preview instead of splitting. Once a long streamed reply grows past that cap, every subsequent progressive edit truncates to the SAME preview text — re-sending an identical edit every tick still counts against the platform's edit rate limit for the rest of the stream. Discord's edit_message() has the identical architecture (mid-stream truncate-in-place, both pre-flight and reactive-after-50035 truncation paths) and this file's own docstring already calls out "the Telegram NousResearch#48648 lesson" it's built on — but the saturated-preview dedup fix itself was never ported over. Fix: track the last truncated preview per (chat_id, message_id), mirroring a0a3c71 exactly. Skip the edit call when the new truncation is identical; still deliver when the visible content actually changes (e.g. the chunk-count marker crosses (1/2) -> (1/3) as the stream grows). State clears on finalize and when content shrinks back under the cap, so dedup can never mask a real edit.
4 tasks
This was referenced Jul 30, 2026
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 does this PR do?
a0a3c716ffixed this exact failure mode for Telegram today (#58563): post-#48648, oversized mid-stream edits truncate to a one-message preview instead of splitting (splitting mid-stream would move the edit target to a continuation and loop forever). Once a long streamed reply grows past that cap, every subsequent progressive edit truncates to the same preview text — re-sending an identical edit every stream tick still counts against the platform's edit rate limit for the rest of the stream, which can trip flood control and hang final delivery.Discord's
edit_message()(plugins/platforms/discord/adapter.py) has the identical architecture — mid-stream truncate-in-place, with both a pre-flight truncation path and a reactive-after-50035 truncation path — and this file's own docstring already explicitly calls out "the Telegram #48648 lesson" it's built on. But the saturated-preview dedup fix itself was never ported over from Telegram to Discord.Related Issue
No filed issue — found via direct comparison with today's Telegram fix (#58563) after noticing the shared "#48648 lesson" architecture.
Type of Change
a0a3c716f)Changes Made
plugins/platforms/discord/adapter.py:self._last_overflow_preview: Dict[tuple, str] = {}tracking the last truncated preview per(chat_id, message_id)edit_message(): skip the API call when a new truncation is identical to the last one sent; still deliver when the visible content actually changes (e.g. the chunk-count marker crosses(1/2)→(1/3)as the stream grows); state clears onfinalize=Trueand when content shrinks back under the cap. Applied to both the pre-flight and reactive-after-50035 truncation paths, mirroringa0a3c716fexactly.tests/gateway/test_discord_edit_message_overflow.py: newTestSaturatedPreviewDedupclass — one test mirroring Telegram's exact growth-through-a-chunk-boundary scenario, one confirming shrink-back-under-cap correctly clears stale dedup stateHow to Test
Mutation-verified: the main dedup test fails against the pre-fix code (3 edit calls instead of 1 for identical saturated previews).
Checklist
discord edit_message overflow preview dedup,discord flood-control edit storm saturated,discord _last_overflow_preview)