Skip to content

Commit 191bf3c

Browse files
committed
Remove unnecessary type checks in voice task cleanup
Simplified the cleanup logic by removing isinstance checks for asyncio.Task. All tasks are created through asyncio.create_task(), so these type checks are unnecessary. This makes the code cleaner and avoids test-specific workarounds in production code, following the same pattern as PR openai#1976.
1 parent 3f49877 commit 191bf3c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/agents/voice/models/openai_stt.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,23 +331,19 @@ async def _cleanup_tasks(self) -> None:
331331

332332
if self._listener_task and not self._listener_task.done():
333333
self._listener_task.cancel()
334-
if isinstance(self._listener_task, asyncio.Task):
335-
tasks.append(self._listener_task)
334+
tasks.append(self._listener_task)
336335

337336
if self._process_events_task and not self._process_events_task.done():
338337
self._process_events_task.cancel()
339-
if isinstance(self._process_events_task, asyncio.Task):
340-
tasks.append(self._process_events_task)
338+
tasks.append(self._process_events_task)
341339

342340
if self._stream_audio_task and not self._stream_audio_task.done():
343341
self._stream_audio_task.cancel()
344-
if isinstance(self._stream_audio_task, asyncio.Task):
345-
tasks.append(self._stream_audio_task)
342+
tasks.append(self._stream_audio_task)
346343

347344
if self._connection_task and not self._connection_task.done():
348345
self._connection_task.cancel()
349-
if isinstance(self._connection_task, asyncio.Task):
350-
tasks.append(self._connection_task)
346+
tasks.append(self._connection_task)
351347

352348
# Wait for all cancelled tasks to complete and collect exceptions
353349
if tasks:

0 commit comments

Comments
 (0)