---
type: email
from: Copilot <notifications@github.com>
subject: Re: [openai/openai-agents-python] Fix: Properly await cancelled tasks

 in voice STT cleanup (PR #1977)
received: 2026-03-06 08:13:42
date_header: Wed, 22 Oct 2025 09:56:36 -0700
priority: normal
status: awaiting_approval
uid: 33469
---

## Email Content

**From:** Copilot <notifications@github.com>
**Subject:** Re: [openai/openai-agents-python] Fix: Properly await cancelled tasks

 in voice STT cleanup (PR #1977)
**Date:** Wed, 22 Oct 2025 09:56:36 -0700

### Body (preview)

@Copilot commented on this pull request.



## Pull Request Overview



This PR fixes a resource leak in `OpenAISTTTranscriptionSession` by ensuring cancelled tasks are properly awaited during cleanup. Previously, tasks were cancelled but not awaited, which could lead to unhandled task exception warnings and potential resource leaks.



**Key Changes:**

- Made `_cleanup_tasks()` async and added proper awaiting of cancelled tasks using `asyncio.gather()`

- Added validation in `Agent.__post_init__()` to check that each tool in the tools list is a valid Tool object

- Added comprehensive test coverage for the new tool validation



### Reviewed Changes



Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.



| File | Description |

| ---- | ----------- |

| `src/agents/voice/models/openai_stt.py` | Made `_cleanup_tasks()` async and added proper awaiting of cancelled tasks to prevent resource leaks |

| `src/agents/agent.py` | Added tool type validation in `__post_init__()` to raise UserError for invalid tool objects |

| `tests/test_agent_config.py` | Added test cases for tool validation covering raw functions, strings, and mixed valid/invalid tools |











---



<sub>**Tip:** Customize your code reviews with copilot-instructions.md. <a href="/openai/openai-agents-python/new/main/.github?filename=copilot-instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Create the file</a> or <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">learn how to get started</a>.</sub>



> @@ -246,6 +247,21 @@ def __post_init__(self):

         if not isinstance(self.tools, list):

             raise TypeError(f"Agent tools must be a list, got {type(self.tools).__name__}")

 

+        # Validate each tool is a valid Tool type

+        # Tool is a Union type, so we need to get

---

## Suggested Actions
- [ ] Reply
- [ ] Archive
- [ ] Escalate
