Skip to content

fix: await voice STT cleanup tasks#3688

Open
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/voice-stt-await-cancelled-tasks
Open

fix: await voice STT cleanup tasks#3688
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/voice-stt-await-cancelled-tasks

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

Summary

  • Make voice STT task cleanup await cancelled background tasks with asyncio.gather(..., return_exceptions=True).
  • Rescan task fields during cleanup so tasks spawned while the connection task unwinds are also cancelled and awaited.
  • Add a regression test proving close() waits for cancelled background task finalizers.

Why

OpenAISTTTranscriptionSession.close() previously cancelled listener, event processor, audio stream, and connection tasks without awaiting them. That could leave background exceptions and cleanup finalizers unobserved, especially around websocket shutdown. While validating the fix, the existing error-event path also exposed a race where _process_events_task can be created while _connection_task is unwinding; the cleanup loop now catches that too.

Tests

  • uv run --extra voice pytest tests/voice/test_openai_stt.py::test_close_awaits_cancelled_background_tasks
  • uv run --extra voice pytest -vv tests/voice/test_openai_stt.py::test_session_error_event
  • uv run --extra voice pytest tests/voice/test_openai_stt.py
  • uv run ruff check src/agents/voice/models/openai_stt.py tests/voice/test_openai_stt.py

@seratch seratch changed the title Await voice STT cleanup tasks fix: await voice STT cleanup tasks Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants