fix: prevent duplicate messages for long replies (>1900 chars)#179
Closed
masami-agent wants to merge 3 commits intoopenabdev:mainfrom
Closed
fix: prevent duplicate messages for long replies (>1900 chars)#179masami-agent wants to merge 3 commits intoopenabdev:mainfrom
masami-agent wants to merge 3 commits intoopenabdev:mainfrom
Conversation
During streaming, truncate content at 1900 chars with '…' instead of splitting into multiple messages via channel.say(). The final edit after streaming completes handles proper multi-chunk delivery. Previously both the streaming task and final edit independently called channel.say() for overflow chunks, causing duplicates. Closes openabdev#81
content[..1900] can panic if 1900 falls inside a multi-byte UTF-8 character (e.g. CJK, emoji). Walk back to the nearest char boundary.
Discord's 2000-char limit is Unicode characters, not bytes. CJK chars are 3 bytes each, so byte-based limits truncate far too early and as_bytes().chunks() corrupts multi-byte characters. - discord.rs: streaming truncation uses chars().count() / chars().take() - format.rs: split_message uses char count for all boundary checks, hard-split iterates chars instead of byte chunks
Contributor
Author
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
Fixes the duplicate message bug when agent replies exceed 1900 characters.
Closes #81
Before (current main)
The edit-streaming task splits long content into chunks via
channel.say(), and the final edit does the same independently — resulting in duplicate overflow messages.After (this PR)
…— this is a live preview, not the final output.split_message()after streaming completes.Clean separation of responsibilities, no orphaned messages, no duplication.
Changes
src/discord.rsApproach
Option A from the issue: truncate during streaming, let final edit handle chunking. Same approach as the community fix in PR #53 by @ruan330.