Fix stale state in user turn stop strategies between turns

Reset stop strategies at turn start (not just turn stop) so that late
transcriptions arriving between turns do not leave stale _text that
causes premature stops on the next turn. Also cancel pending timeout
tasks in reset() for both SpeechTimeout and TurnAnalyzer strategies.
This commit is contained in:
Mark Backman
2026-03-17 11:31:08 -04:00
parent f54b3c6884
commit 5000b040dd
5 changed files with 122 additions and 0 deletions

View File

@@ -64,6 +64,9 @@ class SpeechTimeoutUserTurnStopStrategy(BaseUserTurnStopStrategy):
self._vad_user_speaking = False
self._transcript_finalized = False
self._vad_stopped_time = None
if self._timeout_task:
await self.task_manager.cancel_task(self._timeout_task)
self._timeout_task = None
async def setup(self, task_manager: BaseTaskManager):
"""Initialize the strategy with the given task manager.

View File

@@ -68,6 +68,9 @@ class TurnAnalyzerUserTurnStopStrategy(BaseUserTurnStopStrategy):
self._vad_user_speaking = False
self._vad_stopped_time = None
self._transcript_finalized = False
if self._timeout_task:
await self.task_manager.cancel_task(self._timeout_task)
self._timeout_task = None
async def setup(self, task_manager: BaseTaskManager):
"""Initialize the strategy with the given task manager.

View File

@@ -256,6 +256,10 @@ class UserTurnController(BaseObject):
for s in self._user_turn_strategies.start or []:
await s.reset()
# Reset all user turn stop strategies to start fresh for the new turn.
for s in self._user_turn_strategies.stop or []:
await s.reset()
await self._call_event_handler("on_user_turn_started", strategy, params)
async def _trigger_user_turn_stop(