Skip to content

Commit 7198e3c

Browse files
committed
Preserve exceptions from gather() during task cleanup
1 parent 7e4dfca commit 7198e3c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/agents/voice/result.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,16 @@ async def _cleanup_tasks(self):
270270

271271
# Wait for all cancelled tasks to complete and collect exceptions
272272
if tasks:
273-
await asyncio.gather(*tasks, return_exceptions=True)
273+
results = await asyncio.gather(*tasks, return_exceptions=True)
274+
# Check if any task failed with a real exception (not CancelledError)
275+
# This catches exceptions that occurred after _check_errors() but before cancellation
276+
if not self._stored_exception:
277+
for result in results:
278+
is_exception = isinstance(result, Exception)
279+
is_not_cancelled = not isinstance(result, asyncio.CancelledError)
280+
if is_exception and is_not_cancelled:
281+
self._stored_exception = result
282+
break
274283

275284
def _check_errors(self):
276285
"""Check for exceptions in completed tasks.

0 commit comments

Comments
 (0)