Skip to content

fix(voice): complete AgentTask teardown after handoff failures - #6842

Draft
IanCollection wants to merge 1 commit into
livekit:mainfrom
IanCollection:agent/fix-agent-task-inactive-event
Draft

fix(voice): complete AgentTask teardown after handoff failures#6842
IanCollection wants to merge 1 commit into
livekit:mainfrom
IanCollection:agent/fix-agent-task-inactive-event

Conversation

@IanCollection

Copy link
Copy Markdown

What changed

  • guarantee an AgentTask signals inactivity across setup, wait, and handoff teardown failures
  • make AgentActivity.aclose() retryable when teardown raises partway through
  • have session close retry the current task activity before walking back to its parent

Why

AgentSession waits for an active AgentTask to become inactive before it can continue closing. The event was set only after asynchronous handoff cleanup. If activity close or parent resume raised (including cancellation during setup), the signal was skipped and session shutdown could wait forever. A failed activity close also marked the activity closed before cleanup completed, preventing a later retry.

The inactive signal now covers the full handoff lifecycle, while teardown errors still propagate. A partially failed activity close rolls back its completed flag under the close lock so session shutdown can retry it.

Impact

Session shutdown no longer deadlocks after an AgentTask handoff failure, and partially closed child activities can finish releasing their resources.

Validation

  • fail-before regression: AgentSession.aclose() timed out after an injected task-activity close failure
  • fail-before regression: cancellation during task activity setup left session close waiting
  • pytest tests/test_agent_task_close_race.py tests/test_nested_agent_task.py --unit -q — 5 passed
  • broader AgentSession/AgentTask selection — 86 passed
  • Ruff check and format check passed
  • mypy passed for the changed voice modules

@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