Skip to content

fix: prevent duplicate messages during long response streaming#162

Closed
joshuaking42 wants to merge 1 commit intoopenabdev:mainfrom
joshuaking42:fix/streaming-duplicate-messages
Closed

fix: prevent duplicate messages during long response streaming#162
joshuaking42 wants to merge 1 commit intoopenabdev:mainfrom
joshuaking42:fix/streaming-duplicate-messages

Conversation

@joshuaking42
Copy link
Copy Markdown
Contributor

Problem

When a Discord response exceeds 1900 characters, the edit-streaming loop (which runs every 1.5s) re-splits the entire content and calls channel.say() for all overflow chunks on every tick. This causes the same content to be posted as new messages repeatedly — the 跳針 (broken record) effect.

Root cause

current_edit_msg was a single MessageId that got overwritten to the last say() result each tick:

  • Tick 1: content 2500 chars → edit msg with chunk1, say() chunk2 → current_edit_msg = chunk2
  • Tick 2: content 3000 chars → edit chunk2's msg with chunk1 (wrong!), say() chunk2 + chunk3 as new messages
  • Repeat every 1.5s → massive duplication

The final edit had the same issue — it didn't know about overflow messages created during streaming.

Fix

Replace current_edit_msg: MessageId with msg_ids: Vec<MessageId> to track all posted messages:

  • Chunks that already have a message → edit() in-place
  • New overflow chunks → say() once and push the ID
  • Final edit reuses msg_ids from the streaming task

Full content is visible during streaming, no truncation, no duplication.

The edit-streaming loop was re-splitting content every 1.5s tick and
calling channel.say() for all overflow chunks, creating duplicate
messages each tick. Fix by tracking posted message IDs in a Vec so
overflow chunks are only sent once, and existing messages are edited
in-place. The final edit also reuses these IDs instead of blindly
posting new messages.
@joshuaking42 joshuaking42 requested a review from thepagent as a code owner April 9, 2026 09:14
@masami-agent
Copy link
Copy Markdown
Contributor

Hi @joshuaking42, this PR overlaps with #135 which fixes the same duplicate message issue and has already been reviewed and approved. Would you be okay closing this one in favor of #135? Thanks 🙏

@saitama3292-onepunch
Copy link
Copy Markdown
Contributor

Closing in favor of #135 which addresses the same issue. Thanks for the heads up! 🙏

@chaodu-agent
Copy link
Copy Markdown
Collaborator

Closing — the duplicate message fix has been merged via #135. Thanks @joshuaking42 for the contribution and for being gracious about consolidating efforts! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants