Skip to content

fix(discord): split-and-deliver oversized edits instead of silent truncation - #23703

Closed
AhmetArif0 wants to merge 1 commit into
NousResearch:mainfrom
AhmetArif0:fix/discord-edit-overflow-split
Closed

fix(discord): split-and-deliver oversized edits instead of silent truncation#23703
AhmetArif0 wants to merge 1 commit into
NousResearch:mainfrom
AhmetArif0:fix/discord-edit-overflow-split

Conversation

@AhmetArif0

Copy link
Copy Markdown
Contributor

Problem

DiscordAdapter.edit_message silently truncated messages that exceeded
the 2000-character limit:

if len(formatted) > self.MAX_MESSAGE_LENGTH:
    formatted = formatted[:self.MAX_MESSAGE_LENGTH - 3] + "..."
await msg.edit(content=formatted)
return SendResult(success=True, message_id=message_id)  # lies: tail was dropped

stream_consumer received success=True and assumed the full content
was on screen. Any streaming response that grew past 2000 chars had its
tail permanently dropped with no error surfaced to the user or the
gateway.

Fix

Replace the truncation with _edit_overflow_split(), mirroring the
same contract Telegram's overflow split established in PR #23576:

  1. Edit the original message with chunk 1 (so the message stays
    in-thread and doesn't flash as "deleted + new").
  2. Send remaining chunks as reply continuations to the previous
    chunk, so the user sees a contiguous threaded block.
  3. Return SendResult(success=True, message_id=<last-chunk-id>, continuation_message_ids=(...)).

stream_consumer already handles continuation_message_ids
(line 1172) — it updates _message_id to the last continuation so
subsequent edits target the most recent visible message.

Behavior

Scenario Before After
Edit ≤ 2000 chars Edit in place ✅ Edit in place ✅
Edit > 2000 chars Silent truncation with "..." Split and deliver all chunks ✅
First-chunk edit fails (real error) Logged, success=False Logged, success=False
First-chunk "not modified" N/A Continue to send continuations ✅
Continuation send fails N/A Best-effort: deliver what succeeded, log warning ✅

Checklist

  • No new imports required (List, Any already imported from typing)
  • truncate_message inherited from BasePlatformAdapter (same as send_message uses)
  • to_reference(fail_if_not_exists=False) — same pattern as send_message's reply threading
  • stream_consumer already consumes continuation_message_ids — no consumer changes needed
  • No competitor PRs targeting this path

…ncation

Discord's edit_message silently truncated messages exceeding 2000 chars
with "..." and returned success=True, causing stream_consumer to believe
the full content had been delivered.

Replace the truncation with _edit_overflow_split(): edits the original
message with the first chunk, then sends remaining chunks as threaded
replies so the user sees a contiguous block. Returns
continuation_message_ids so stream_consumer can keep editing the most
recent visible message — the same contract Telegram's overflow split
established in the base SendResult.
@teknium1

Copy link
Copy Markdown
Contributor

Fixed on main via #55592 (commit af5cea0). You identified this same Discord edit_message truncation bug first (May 11) — credited and co-authored on the merged commit alongside #27961. The merged version gates the split on finalize to avoid the #48648 mid-stream duplication loop. Thanks!

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/discord Discord bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants