From d1abf43dfee0b04053a048edd876513621e45aeb Mon Sep 17 00:00:00 2001 From: Lucas Wang Date: Tue, 21 Oct 2025 12:57:01 +0800 Subject: [PATCH 1/3] fix: Remove trailing commas causing tuple assignment in response cancellation (#1952) --- src/agents/realtime/openai_realtime.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agents/realtime/openai_realtime.py b/src/agents/realtime/openai_realtime.py index 50aaf3c4b..ce28114c9 100644 --- a/src/agents/realtime/openai_realtime.py +++ b/src/agents/realtime/openai_realtime.py @@ -431,7 +431,7 @@ async def _send_interrupt(self, event: RealtimeModelSendInterrupt) -> None: and session.audio is not None and session.audio.input is not None and session.audio.input.turn_detection is not None - and session.audio.input.turn_detection.interrupt_response is True, + and session.audio.input.turn_detection.interrupt_response is True ) if not automatic_response_cancellation_enabled: await self._cancel_response() @@ -616,7 +616,7 @@ async def _handle_ws_event(self, event: dict[str, Any]): and session.audio is not None and session.audio.input is not None and session.audio.input.turn_detection is not None - and session.audio.input.turn_detection.interrupt_response is True, + and session.audio.input.turn_detection.interrupt_response is True ) if not automatic_response_cancellation_enabled: await self._cancel_response() From e47a14ff7346b269ca5d8d0dc85dbd7baa09e527 Mon Sep 17 00:00:00 2001 From: Lucas Wang Date: Tue, 21 Oct 2025 13:41:44 +0800 Subject: [PATCH 2/3] fix: await cancelled websocket task to prevent resource leak (#1955) --- src/agents/realtime/openai_realtime.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/agents/realtime/openai_realtime.py b/src/agents/realtime/openai_realtime.py index ce28114c9..8612c36c8 100644 --- a/src/agents/realtime/openai_realtime.py +++ b/src/agents/realtime/openai_realtime.py @@ -516,6 +516,10 @@ async def close(self) -> None: self._websocket = None if self._websocket_task: self._websocket_task.cancel() + try: + await self._websocket_task + except asyncio.CancelledError: + pass self._websocket_task = None async def _cancel_response(self) -> None: From 9db9c01b91cf50d844f20f435483b184f94046e6 Mon Sep 17 00:00:00 2001 From: Lucas Wang Date: Tue, 21 Oct 2025 13:42:00 +0800 Subject: [PATCH 3/3] fix: prevent race condition in listener iteration (#1956) --- src/agents/realtime/openai_realtime.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/agents/realtime/openai_realtime.py b/src/agents/realtime/openai_realtime.py index 8612c36c8..04a227ac8 100644 --- a/src/agents/realtime/openai_realtime.py +++ b/src/agents/realtime/openai_realtime.py @@ -266,7 +266,8 @@ def remove_listener(self, listener: RealtimeModelListener) -> None: async def _emit_event(self, event: RealtimeModelEvent) -> None: """Emit an event to the listeners.""" - for listener in self._listeners: + # Copy list to avoid modification during iteration + for listener in list(self._listeners): await listener.on_event(event) async def _listen_for_messages(self):