From dabca707442fdb1a17d226490c2e10baed28b4af Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Mon, 27 Apr 2026 16:16:44 -0400 Subject: [PATCH] fix: warn and bail in reset_conversation when no context exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reset_conversation is part of the public AWSNovaSonicLLMService API and is also called internally from the receive-task error handler. Previously it captured `self._context` (typed `LLMContext | None`) and unconditionally passed it to `_handle_context`, which expects a real context — silently doing the wrong thing if no initial context had been received yet. Treat that as developer error: log a warning and return early. Nothing to preserve means nothing to reset. --- src/pipecat/services/aws/nova_sonic/llm.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pipecat/services/aws/nova_sonic/llm.py b/src/pipecat/services/aws/nova_sonic/llm.py index 71a80e444..d3396cef2 100644 --- a/src/pipecat/services/aws/nova_sonic/llm.py +++ b/src/pipecat/services/aws/nova_sonic/llm.py @@ -501,12 +501,18 @@ class AWSNovaSonicLLMService(LLMService): service, and reconnects with the preserved context. """ logger.debug("Resetting conversation") - if self._assistant_is_responding: - self._assistant_is_responding = False - await self._report_assistant_response_ended() # Grab context to carry through disconnect/reconnect context = self._context + if context is None: + logger.warning( + "reset_conversation called before an initial context was received; nothing to reset" + ) + return + + if self._assistant_is_responding: + self._assistant_is_responding = False + await self._report_assistant_response_ended() await self._disconnect() await self._start_connecting()