From 1f76a93935813cd3d2addd99e8b0417ac4811dcd Mon Sep 17 00:00:00 2001 From: siddseethepalli Date: Thu, 2 Apr 2026 01:11:07 +0000 Subject: [PATCH] fix: guard against auxiliary message_complete clearing turn state Non-persisted message_complete events (call transcript, call completion) arrive without messageId and would still clear currentAssistantMessageId on the client, corrupting the main agent loop's daemonMessageId backfill. Skip the full turn-reset logic when message_complete lacks messageId while the main agent loop is active. This is the client-side defensive counterpart to the backend fix that threads messageId through persisted notifier events. Co-Authored-By: Claude Opus 4.6 (1M context) --- clients/shared/Features/Chat/ChatActionHandler.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clients/shared/Features/Chat/ChatActionHandler.swift b/clients/shared/Features/Chat/ChatActionHandler.swift index 31a630261f8..73a26268a2b 100644 --- a/clients/shared/Features/Chat/ChatActionHandler.swift +++ b/clients/shared/Features/Chat/ChatActionHandler.swift @@ -346,6 +346,15 @@ final class ChatActionHandler { private func handleMessageComplete(_ complete: MessageCompleteMessage, vm: ChatViewModel) { guard belongsToConversation(complete.conversationId) else { return } + // Auxiliary message_complete events (watch notifiers, call notifications) + // that lack a messageId should not reset the main agent turn state. + // Without this guard, a watch commentary/summary message_complete arriving + // mid-stream clears currentAssistantMessageId, causing the main agent + // loop's subsequent message_complete to set daemonMessageId on the wrong + // (newly created) message — breaking the LLM Context Inspector until restart. + if complete.messageId == nil && vm.isSending { + return + } // Flush any buffered streaming text before finalizing the message. vm.flushStreamingBuffer() vm.flushPartialOutputBuffer()