Skip to content

Commit d64ecfe

Browse files
committed
Remove unnecessary type check in guardrail cleanup
Simplified the cleanup logic by removing the isinstance check for asyncio.Task. Since _guardrail_tasks only contains real tasks created through asyncio.create_task(), this type check is unnecessary. This makes the code cleaner and avoids test-specific workarounds in production code.
1 parent 5e6feae commit d64ecfe

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/agents/realtime/session.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -752,19 +752,13 @@ async def _cleanup_guardrail_tasks(self) -> None:
752752
This ensures that any exceptions raised by the tasks are properly handled
753753
and prevents warnings about unhandled task exceptions.
754754
"""
755-
# Collect real asyncio.Task objects that need to be awaited
756-
real_tasks = []
757-
758755
for task in self._guardrail_tasks:
759756
if not task.done():
760757
task.cancel()
761-
# Only await real asyncio.Task objects (not mocks in tests)
762-
if isinstance(task, asyncio.Task):
763-
real_tasks.append(task)
764758

765-
# Wait for all real tasks to complete and collect any exceptions
766-
if real_tasks:
767-
await asyncio.gather(*real_tasks, return_exceptions=True)
759+
# Wait for all tasks to complete and collect any exceptions
760+
if self._guardrail_tasks:
761+
await asyncio.gather(*self._guardrail_tasks, return_exceptions=True)
768762

769763
self._guardrail_tasks.clear()
770764

0 commit comments

Comments
 (0)