From 2bc0f5f14a5c315f42afa3af2300dc6abb172ec1 Mon Sep 17 00:00:00 2001 From: viettranx Date: Fri, 27 Mar 2026 19:49:33 +0700 Subject: [PATCH] fix(telegram): prevent duplicate messages in groups when streaming disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When group_stream=false (default), channels implementing StreamingChannel still processed chunk events, creating stream messages alongside block replies — causing each intermediate message to appear twice. Gate the streaming handler on rc.Streaming so it only activates when streaming is actually enabled for the run. --- internal/channels/events.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/channels/events.go b/internal/channels/events.go index b261423f..f791ee1c 100644 --- a/internal/channels/events.go +++ b/internal/channels/events.go @@ -35,8 +35,11 @@ func (m *Manager) HandleAgentEvent(eventType, runID string, payload any) { ctx = store.WithTenantID(ctx, ta.TenantID()) } - // Forward to StreamingChannel - if sc, ok := ch.(StreamingChannel); ok { + // Forward to StreamingChannel (only when streaming is enabled for this run). + // Without this gate, channels that implement StreamingChannel but have streaming + // disabled (e.g. group_stream=false) would create stream messages AND emit + // block.reply outbound messages, causing duplicate delivery. + if sc, ok := ch.(StreamingChannel); ok && rc.Streaming { switch eventType { case protocol.AgentEventRunStarted: stream, err := sc.CreateStream(ctx, rc.ChatID, true)