Skip to content

fix(discord): dedup saturated mid-stream overflow previews to stop edit-rate-limit storms - #58912

Merged
teknium1 merged 1 commit into
NousResearch:mainfrom
srojk34:fix/discord-edit-overflow-dedup
Jul 5, 2026
Merged

fix(discord): dedup saturated mid-stream overflow previews to stop edit-rate-limit storms#58912
teknium1 merged 1 commit into
NousResearch:mainfrom
srojk34:fix/discord-edit-overflow-dedup

Conversation

@srojk34

@srojk34 srojk34 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

a0a3c716f fixed 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

  • 🐛 Bug fix (availability — same class as a0a3c716f)

Changes Made

  • plugins/platforms/discord/adapter.py:
    • New 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 on finalize=True and when content shrinks back under the cap. Applied to both the pre-flight and reactive-after-50035 truncation paths, mirroring a0a3c716f exactly.
  • tests/gateway/test_discord_edit_message_overflow.py: new TestSaturatedPreviewDedup class — one test mirroring Telegram's exact growth-through-a-chunk-boundary scenario, one confirming shrink-back-under-cap correctly clears stale dedup state

How to Test

pytest tests/gateway/test_discord_edit_message_overflow.py tests/gateway/test_discord_slash_commands.py tests/gateway/test_discord_document_handling.py tests/gateway/test_discord_free_response.py -v

Mutation-verified: the main dedup test fails against the pre-fix code (3 edit calls instead of 1 for identical saturated previews).

Checklist

  • Contributing Guide read | Conventional Commits | No duplicate PR found (searched discord edit_message overflow preview dedup, discord flood-control edit storm saturated, discord _last_overflow_preview)
  • Scoped to this one adapter | Tests added | Platform: macOS
  • Docs — N/A | Cross-platform — N/A (pure Python state tracking)

…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.
@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins platform/discord Discord bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages P2 Medium — degraded but workaround exists labels Jul 5, 2026
@teknium1
teknium1 merged commit 2e2212b into NousResearch:main Jul 5, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists platform/discord Discord 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.

3 participants