Skip to content

fix(discord): split oversized final edits, truncate mid-stream previews (#27881) - #55592

Merged
teknium1 merged 1 commit into
mainfrom
fix/discord-edit-overflow-split
Jun 30, 2026
Merged

fix(discord): split oversized final edits, truncate mid-stream previews (#27881)#55592
teknium1 merged 1 commit into
mainfrom
fix/discord-edit-overflow-split

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Discord streaming/tool-progress replies over 2,000 chars are now delivered in full instead of being silently clipped. DiscordAdapter.edit_message clipped any oversized formatted payload to [:1997] + "..." and returned success=True, so the stream consumer believed the whole reply landed and stopped — the user lost everything past the cap and perceived the agent as quitting mid-task (#27881).

Root cause: edit_message had no overflow handling. The SendResult split contract (continuation_message_ids, partial_overflow) and the stream consumer's split handling already existed for Telegram; Discord never used them.

Changes

  • plugins/platforms/discord/adapter.pyedit_message is overflow-aware, with a new _edit_overflow_split helper:
  • tests/gateway/test_discord_edit_message_overflow.py — 13 regression tests: happy path, mid-stream truncate-don't-split, final split byte-coverage + reply threading + last-id contract, first-chunk failure propagation, partial-delivery contract, reactive 50035 detection, and the length-error detector.

Validation

Before After
Streaming edit > 2000 chars clipped to , success=True preview truncated in place, no split, no loop
Final edit > 2000 chars clipped, tail lost split across edit + reply-threaded continuations, full text delivered
message_id after split n/a points at last visible chunk
Mid-stream re-split loop (#48648) would occur on a naive port structurally impossible (split gated on finalize)
  • 13/13 new tests pass; existing Discord send/reply/format + stream-consumer suites green (152 tests).
  • E2E: 7 streaming ticks over the cap created 0 continuations and kept the original edit target (no loop); finalize delivered all 3 chunks with the tail marker intact and message_id = last continuation.

Note: #27881's reporter symptom (turn ends after only stating intent) was the real root cause, fixed separately by merged #53943. This is the distinct silent-truncation defect those contributors correctly identified.

Credits: this fix was independently identified by @xxxigm (#27961) and @AhmetArif0 (#23703, earliest). Both are co-authored on the commit; their PRs predated the #48648 split-gating lesson, so this is a corrected, current-tree implementation of their finding.

Infographic

discord-edit-overflow-split

…ws (#27881)

DiscordAdapter.edit_message clipped any formatted payload over the 2,000-char
cap to [:1997]+"..." and returned success=True, so the stream consumer
believed the full reply landed and stopped — the user lost everything past the
boundary and perceived the agent as quitting mid-task.

edit_message is now overflow-aware, mirroring Telegram's proven contract:
- finalize=True: split-and-deliver via _edit_overflow_split — edit chunk 1 in
  place, send chunks 2..N as reply-threaded continuations, return the last
  visible id in message_id plus continuation_message_ids so the stream
  consumer keeps editing the most recent chunk and can clean them all up.
- finalize=False (mid-stream): truncate a one-message preview in place, never
  split. A mid-stream split moves the edit target to a continuation and the
  next accumulated-token tick re-splits, looping forever (the Telegram #48648
  lesson the original port predated).
- Reactive 50035 '2000 or fewer in length' on edit runs the same branch logic.
- Partial continuation failure still reports success with a partial_overflow
  raw_response so the consumer retries the tail instead of marking a clipped
  reply complete.

Co-authored-by: xxxigm <tuancanhnguyen706@gmail.com>
Co-authored-by: AhmetArif0 <147827411+AhmetArif0@users.noreply.github.com>
@teknium1
teknium1 merged commit af5cea0 into main Jun 30, 2026
31 checks passed
@teknium1
teknium1 deleted the fix/discord-edit-overflow-split branch June 30, 2026 10:49
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery 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 Jun 30, 2026
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 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.

2 participants