Skip to content

fix(voice): preserve transcript flush during session close - #6843

Draft
IanCollection wants to merge 3 commits into
livekit:mainfrom
IanCollection:agent/preserve-close-transcript-flush
Draft

fix(voice): preserve transcript flush during session close#6843
IanCollection wants to merge 3 commits into
livekit:mainfrom
IanCollection:agent/preserve-close-transcript-flush

Conversation

@IanCollection

Copy link
Copy Markdown

What changed

  • distinguish the transcript flush explicitly started by normal AgentSession close from ordinary commit/EOU tasks
  • drain that close-owned commit and its resulting EOU task instead of cancelling them
  • keep the remaining audio-recognition teardown cancellation-safe and surface close-flush failures after cleanup

Why

Normal session close starts _commit_user_turn(...) with session_close_transcript_timeout and immediately closes the activity. AudioRecognition._aclose() then cancelled the same commit task (and its EOU task), so an interim/final transcript still being flushed could never reach conversation history.

Only the exact tasks owned by normal session close are preserved. Public commits, handoff teardown, and error-close tasks retain the existing cancellation behavior. If outer cancellation arrives, cleanup is reaped before CancelledError is propagated.

Impact

The last user utterance can finish committing during normal session shutdown, so session_close_transcript_timeout again provides its intended transcript-capture behavior without broadening waits on unrelated close paths.

Validation

  • fail-before regression: a real AgentSession close emitted no final transcript/history item for a pending interim transcript
  • direct assertions cover both agent chat context and session history, exactly once
  • cancellation cleanup, ordinary-task cancellation, and close-owned child-error regressions included
  • pytest tests/test_audio_recognition_aclose.py tests/test_agent_session.py --unit -q — 92 passed
  • handoff selection — 13 passed
  • Ruff check and format check passed
  • mypy (livekit.agents) — 206 files passed

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


ian seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants