fix(voice): wait for end-of-turn task when waiting for user inactivity#5792
Merged
Conversation
The end-of-turn task belongs to both the user and the agent: it's part of the user turn and may spawn a new agent speech handle. Previously it was only awaited in the wait_for_agent branch, so callers waiting only on user inactivity could return while an EOU was still pending, and a fast user-silence flip could race a new speech handle being created.
chenghao-mou
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_wait_for_inactiveonly awaited the end-of-turn task in thewait_for_agentbranch. But EOU belongs to both:_user_silence_eventcan be set as soon as VAD/STT detects silence, while the EOU task is still running to confirm the turn boundary. A caller passingwait_for_user=True, wait_for_agent=Falsecould return mid-EOU.user_active=Falsewhile EOU was racing to create new agent work.Fix the race introduced in #5492 that may break the AsyncToolset reply deliver that the tool updates created while EOU is active, and then created two agent replies in parallel.