Skip to content

fix: prevent wait_for_idle cancellation from poisoning user turns - #6913

Open
Excelius-Wang wants to merge 1 commit into
livekit:mainfrom
Excelius-Wang:fix/shield-wait-for-idle
Open

fix: prevent wait_for_idle cancellation from poisoning user turns#6913
Excelius-Wang wants to merge 1 commit into
livekit:mainfrom
Excelius-Wang:fix/shield-wait-for-idle

Conversation

@Excelius-Wang

Copy link
Copy Markdown

Fixes #6911.

Summary

  • Shield the end-of-turn and user-turn-completion tasks observed by wait_for_idle().
  • Wait for a predecessor user-turn task without propagating cancellation in either direction.
  • Preserve non-cancellation exceptions raised by the predecessor.
  • Add regression tests for cancellation isolation and successor recovery.

Why

wait_for_idle() is an observer of SDK-owned tasks. Cancelling the observer currently cancels the task it is awaiting. A later user turn then awaits that cancelled predecessor and is cancelled before processing, so one observer cancellation can poison subsequent turns.

Testing

  • pytest tests/test_wait_for_idle_cancellation.py -q — 3 passed
  • pytest tests/test_tools.py --unit -q — 114 passed
  • ruff format --check livekit-agents/livekit/agents/voice/agent_activity.py tests/test_wait_for_idle_cancellation.py
  • ruff check livekit-agents/livekit/agents/voice/agent_activity.py tests/test_wait_for_idle_cancellation.py
  • mypy -p livekit.agents.voice.agent_activity

@Excelius-Wang
Excelius-Wang requested a review from a team as a code owner August 19, 2026 17:04

@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: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

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.

Cancelling a wait_for_idle caller can cancel in-flight user-turn work and poison subsequent turns

1 participant