You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix voice STT task cleanup to properly await cancelled tasks
Problem:
The _cleanup_tasks() method in OpenAISTTTranscriptionSession was only calling
task.cancel() on pending tasks (listener, process_events, stream_audio, connection)
but not awaiting them. This could lead to:
1. Unhandled task exception warnings
2. Potential resource leaks (websocket connections, file descriptors)
3. Improper cleanup of background tasks
Evidence:
- Similar to recently fixed guardrail tasks cleanup (PR openai#1976)
- Similar to fixed websocket task cleanup (PR openai#1955)
- asyncio best practices require awaiting cancelled tasks
Solution:
1. Made _cleanup_tasks() async
2. Collect all real asyncio.Task objects that need to be awaited
3. Added await asyncio.gather() with return_exceptions=True to properly
collect exceptions from cancelled tasks
4. Updated close() method to await _cleanup_tasks()
Testing:
- All existing voice/STT tests pass (17 passed)
- Uses isinstance check to support mock objects in tests
- Follows the same pattern as PR openai#1976 and PR openai#1955
0 commit comments