fix(discord): split oversized final edits, truncate mid-stream previews (#27881) - #55592
Merged
Conversation
…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>
This was referenced Jun 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.
Summary
Discord streaming/tool-progress replies over 2,000 chars are now delivered in full instead of being silently clipped.
DiscordAdapter.edit_messageclipped any oversized formatted payload to[:1997] + "..."and returnedsuccess=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_messagehad no overflow handling. TheSendResultsplit 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.py—edit_messageis overflow-aware, with a new_edit_overflow_splithelper:finalize=True→ split-and-deliver: edit chunk 1 in place (fence-awaretruncate_message,(1/N)indicators), send chunks 2..N as reply-threaded continuations. Returnsmessage_id= last visible chunk +continuation_message_idsso the 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 → infinite duplication. This is the Telegram fix(telegram): Infinite streamed message duplication loop during 4096-char overflow #48648 lesson the earlier port (fix(discord): split-and-deliver oversized edits instead of silent truncation (#27881) #27961 / fix(discord): split-and-deliver oversized edits instead of silent truncation #23703) predated and would have re-introduced.50035"2000 or fewer in length" on the edit runs the same branch logic (formatter inflation past the cap). A non-length 50035 (bad reply reference) is not treated as overflow.success=Truewith apartial_overflowraw_response so the consumer retries the tail rather than marking a clipped reply complete. Only a first-chunk edit failure returnssuccess=False.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
…,success=Truemessage_idafter splitfinalize)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