Skip to content

fix(voice): make commit_user_turn await turn processing - #7702

Open
lumina678 wants to merge 1 commit into
livekit:mainfrom
lumina678:fix/commit-user-turn-barrier
Open

lumina678 wants to merge 1 commit into
livekit:mainfrom
lumina678:fix/commit-user-turn-barrier

Conversation

@lumina678

@lumina678 lumina678 commented Oct 9, 2026 •

Copy link
Copy Markdown

Summary

  • keep the existing Future[str] API while making its completion a reliable turn-processing barrier
  • associate each manual commit with its own completion future instead of reading the latest shared task fields
  • bind that association only after transcript collection and carry it across end-of-turn retries
  • wait until the exact turn user message is committed to chat context before resolving when a reply is generated
  • settle rejected or abandoned turns explicitly while preserving skip_reply, caller-cancellation shielding, and current-turn error propagation

Why

commit_user_turn() currently resolves after end-of-turn handling is only scheduled. A caller that awaits it and immediately calls generate_reply() can therefore race the chat-context append and generate against stale history.

The barrier is scoped to the exact turn started by the call. Resumed speech can replace the end-of-turn task without cancelling the caller, an earlier automatic endpoint cannot capture the manual token, and a later unrelated turn cannot hijack the wait.

Tests

  • 16 focused regression tests for manual commit lifecycle and the chat-context barrier
  • explicit coverage for resumed speech, transcript-collection races, exact turn-task association, later-turn replacement, rejected turns, mode changes, skip_reply, cancellation, and failure propagation
  • 36 related tests pass across commit, EOU wait-span, and false-interruption suites
  • 167 broader audio-recognition and agent-session tests pass
  • make check passes, including formatting, lint, and mypy across 698 source files

Fixes #7585

Supersedes #7688, which I accidentally opened from my secondary GitHub account. This PR contains the same implementation, rebased on current main and consolidated into one clean commit under my primary account.

devin-ai-integration[bot]

This comment was marked as resolved.

@lumina678
lumina678 force-pushed the fix/commit-user-turn-barrier branch from ef25dc5 to 271a142 Compare October 10, 2026 03:30

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 new potential issues.

Devin Review

@lumina678
lumina678 force-pushed the fix/commit-user-turn-barrier branch from 271a142 to 8c52fbe Compare October 10, 2026 03:41
@lumina678
lumina678 force-pushed the fix/commit-user-turn-barrier branch from 8c52fbe to db8c530 Compare October 10, 2026 03:47
@bml1g12

bml1g12 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

This looks to be like it' should improve the commit user turn public API to behave like how most developers would assume (i.e. that awaiting it means the current turn is commited to chat context of the LLM for all subsequent calls) so sounds great to me.

I'm conscious that it is technically a breaking change in behaviour, so if the livekit maintainers think it's too radical, we could potentially have an optional flag on commit user turn that enables this behaviour and keep default behaviour same? Or vice versa, a flag to revert to old behaviour.

I say this as maybe in some situations, maybe devs would favour the current behaviour whereby it immediately resolves without waiting for the current turn chat context to be added? I'm not sure though if such a use case really exists, my company does not have, so don't treat this comment as a change request but more just a question to the maintainers about whether we can include an improvement in behaviour of this method if it changes the behaviour slightly

@lumina678

Copy link
Copy Markdown
Author

Thanks — that is a fair compatibility concern. This PR deliberately keeps the existing Future[str] API and only strengthens what its completion means: the exact manual turn has been accepted and, when applicable, its user message is in chat context. It still does not wait for reply generation, tool execution, or speech playout.

Keeping the old timing as the default would preserve the stale-history race from #7585, including the otherwise natural await commit_user_turn(skip_reply=True); generate_reply(...) sequence. I therefore avoided adding a flag without maintainer guidance, both to keep the public API small and because “commit” completing before the turn is committed is difficult to use safely.

If the maintainers consider the timing compatibility risk significant, I am happy to add an explicit compatibility option or adjust the default they prefer. Until then I would keep the barrier semantics in this PR rather than expanding the API speculatively.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return the SpeechHandle from commit_user_turn or ensure await session.commit_user_turn(...) commits to chat context on resolve

2 participants