2025-07-21 19:31:21,679] ERROR livekit.plugins.ope...
# ask-ai
s
2025-07-21 193121,679] ERROR livekit.plugins.openai: failed to handle event Traceback (most recent call last): File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 759, in _recv_task self._handle_response_audio_delta( File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 1341, in _handle_response_audio_delta item_generation.audio_ch.send_nowait( File "/opt/venv/lib/python3.12/site-packages/livekit/agents/utils/aio/channel.py", line 95, in send_nowait raise ChanClosed livekit.agents.utils.aio.channel.ChanClosed [2025-07-21 193121,679] ERROR livekit.plugins.openai: failed to handle event Traceback (most recent call last): File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 759, in _recv_task self._handle_response_audio_delta( File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 1341, in _handle_response_audio_delta item_generation.audio_ch.send_nowait( File "/opt/venv/lib/python3.12/site-packages/livekit/agents/utils/aio/channel.py", line 95, in send_nowait raise ChanClosed livekit.agents.utils.aio.channel.ChanClosed [2025-07-21 193122,697] ERROR livekit.plugins.openai: failed to handle event Traceback (most recent call last): File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 759, in _recv_task self._handle_response_audio_delta( File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 1341, in _handle_response_audio_delta item_generation.audio_ch.send_nowait( File "/opt/venv/lib/python3.12/site-packages/livekit/agents/utils/aio/channel.py", line 95, in send_nowait raise ChanClosed livekit.agents.utils.aio.channel.ChanClosed [2025-07-21 193122,697] ERROR livekit.plugins.openai: failed to handle event Traceback (most recent call last): File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 759, in _recv_task self._handle_response_audio_delta( File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 1341, in _handle_response_audio_delta item_generation.audio_ch.send_nowait( File "/opt/venv/lib/python3.12/site-packages/livekit/agents/utils/aio/channel.py", line 95, in send_nowait raise ChanClosed livekit.agents.utils.aio.channel.ChanClosed [2025-07-21 193123,051] ERROR livekit.plugins.openai: failed to handle event Traceback (most recent call last): File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 759, in _recv_task self._handle_response_audio_delta( File "/opt/venv/lib/python3.12/site-packages/livekit/plugins/openai/realtime/realtime_model.py", line 1341, in _handle_response_audio_delta
t
Thanks for reaching out, Rhythm. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
ChanClosed
exception occurs when attempting to send data to a channel that has already been closed. This is common in scenarios where the audio channel is closed due to session completion, teardown, or race conditions where audio data arrives after the channel is closed. To handle this exception, use one of the following patterns: • Suppress the Exception: Wrap the
send_nowait
call with
contextlib.suppress()
to gracefully ignore the exception:
Copy code
with contextlib.suppress(utils.aio.channel.ChanClosed):
    audio_ch.send_nowait(data)
• Check Channel State: Verify the channel is not closed before sending:
Copy code
if not audio_ch.closed:
    audio_ch.send_nowait(data)
• Handle with Logging: Catch the exception and log or break out of the processing loop as needed:
Copy code
try:
    audio_ch.send_nowait(data)
except utils.aio.channel.ChanClosed:
    logger.warning("audio channel closed, exiting loop")
    break
These approaches are used throughout the LiveKit agents codebase to handle this scenario safely and prevent unhandled exceptions. Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime...