From d488bfdda7ab30498d8db668226b88e7cac44717 Mon Sep 17 00:00:00 2001 From: Bentlybro Date: Mon, 2 Feb 2026 14:11:13 +0000 Subject: [PATCH] fix(backend): Handle StreamHeartbeat in CoPilot stream handler StreamHeartbeat chunks were being yielded from tool execution (to keep SSE connections alive during long-running operations) but the main stream_chat_completion handler had no case for them in its elif chain. They fell through to the 'Unknown chunk type' error path, generating Sentry errors (AUTOGPT-SERVER-7JA). Fix: Add StreamHeartbeat to the elif chain and yield it through so it reaches the route handler which calls to_sse() on it, producing the expected SSE comment format (': heartbeat'). --- autogpt_platform/backend/backend/api/features/chat/service.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autogpt_platform/backend/backend/api/features/chat/service.py b/autogpt_platform/backend/backend/api/features/chat/service.py index bcd6856503..ea6b05d1c8 100644 --- a/autogpt_platform/backend/backend/api/features/chat/service.py +++ b/autogpt_platform/backend/backend/api/features/chat/service.py @@ -607,6 +607,9 @@ async def stream_chat_completion( total_tokens=chunk.totalTokens, ) ) + elif isinstance(chunk, StreamHeartbeat): + # Pass through heartbeat to keep SSE connection alive + yield chunk else: logger.error(f"Unknown chunk type: {type(chunk)}", exc_info=True)