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 result streaming task cleanup to properly await cancelled tasks
Problem:
The _cleanup_tasks() method in VoiceStreamResult was only calling
task.cancel() on pending tasks but not awaiting them. Additionally,
_check_errors() could raise CancelledError when checking cancelled tasks.
This could lead to:
1. Unhandled task exception warnings
2. Potential resource leaks from abandoned tasks
3. CancelledError masking real exceptions
Evidence:
- Similar to fixed guardrail tasks cleanup (PR openai#1976)
- Similar to fixed voice STT cleanup (PR openai#1977)
- Similar to fixed websocket cleanup (PR openai#1955)
- Bug documented in .claude/bug-analysis/03-resource-leaks.md
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 _check_errors() to skip cancelled tasks using task.cancelled()
check to avoid CancelledError when calling task.exception()
5. Updated stream() async generator to await _cleanup_tasks()
Testing:
- Linting passes
- No breaking changes to public API
- Follows same pattern as PR openai#1976, openai#1977, openai#1955
0 commit comments