Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions livekit-agents/livekit/agents/voice/agent_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4531,6 +4531,10 @@ def _on_false_interruption() -> None:
and audio_output.can_pause
and not self._paused_speech.handle.done()
):
if self._audio_recognition is not None:
# the interrupting turn is discarded on resume; clear it fully so its
# speech anchors don't leak into the next real user turn
self._audio_recognition._clear_user_turn()
self._session._update_agent_state(
self._paused_speech.agent_state,
otel_context=self._paused_speech.handle._agent_turn_context,
Expand Down
25 changes: 25 additions & 0 deletions tests/test_false_interruption_resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,28 @@ async def test_resume_is_immediate_when_no_turn_decision_is_open(

assert [name for name, _ in events] == ["resume"]
assert events[0][1] - t0 == pytest.approx(FALSE_INTERRUPTION_TIMEOUT, abs=0.1)


async def test_resume_discards_the_stale_recognition_turn(
monkeypatch: pytest.MonkeyPatch,
) -> None:
# a VAD-only turn that never commits is dropped by the resume; its speech anchors must not
# survive into the next real utterance's started_speaking_at (#7063)
monkeypatch.setenv("LIVEKIT_API_KEY", "k")
monkeypatch.setenv("LIVEKIT_API_SECRET", "s")

session = _session()
activity, _ = _paused_activity(session)

t0 = time.time()
activity.on_end_of_speech(None)
recognition = _recognition(activity, last_speaking_time=t0 - VAD_MIN_SILENCE)
recognition._speech_start_time = t0 - 1.0
recognition._vad_speech_started = True
activity._audio_recognition = recognition

await asyncio.sleep(FALSE_INTERRUPTION_TIMEOUT + 0.2)
await session.aclose()

assert recognition._speech_start_time is None
assert recognition._vad_speech_started is False