From eb40971d4c3d0094c84a3441c4ab5aa70ac17efe Mon Sep 17 00:00:00 2001 From: Eyejoker Date: Mon, 30 Mar 2026 00:14:47 +0900 Subject: [PATCH] fix: prevent duplicate final message when progress already shows the same text When intermediate text was displayed as a progress message and the final result had the same content, both the progress message and a separate final message were sent to Discord. Now detects when the progress message already shows the final text and finalizes in-place without sending a duplicate. --- src/message-turn-controller.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/message-turn-controller.ts b/src/message-turn-controller.ts index 7cc95a3..e2b1428 100644 --- a/src/message-turn-controller.ts +++ b/src/message-turn-controller.ts @@ -264,14 +264,16 @@ export class MessageTurnController { // Final arrived — flush any buffered progress that isn't the same text, // then discard the pending buffer so it never shows up. if (text) { - if (this.lastIntermediateText && text === this.lastIntermediateText) { - // Already sent as intermediate — skip duplicate, just finalize - this.lastIntermediateText = null; + // If the progress message already shows the same text as the final + // result, finalize it in-place instead of sending a duplicate message. + const alreadyVisible = + this.progressMessageId && + this.latestProgressText === text; + if (alreadyVisible) { await this.finalizeProgressMessage(); this.visiblePhase = toVisiblePhase(phase); this.latestProgressTextForFinal = null; } else { - this.lastIntermediateText = null; await this.flushPendingProgress(text); await this.finalizeProgressMessage(); await this.deliverFinalText(text);