fix: warn and bail in reset_conversation when no context exists

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.
This commit is contained in:
Paul Kompfner
2026-04-27 16:16:44 -04:00
parent 191bdc733f
commit dabca70744

View File

@@ -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()