@@ -678,6 +678,48 @@ def fake_time_func():
678678 await session .close ()
679679
680680
681+ @pytest .mark .asyncio
682+ async def test_wait_for_event_raises_builtin_timeout_error_on_real_clock () -> None :
683+ """The asyncio timeout inside _wait_for_event must surface as the builtin TimeoutError.
684+
685+ On Python 3.10 asyncio.wait_for raises asyncio.TimeoutError, a different class from
686+ the builtin; the callers only catch the builtin. This test uses the real clock so the
687+ asyncio timeout path runs, unlike the deadline test that patches monotonic.
688+ """
689+ queue : asyncio .Queue [dict [str , str ]] = asyncio .Queue ()
690+
691+ with pytest .raises (TimeoutError , match = "Timeout waiting for event" ):
692+ await _wait_for_event (queue , ["session.created" ], timeout = 0.01 )
693+
694+
695+ @pytest .mark .asyncio
696+ async def test_real_clock_session_creation_timeout_is_wrapped (monkeypatch : pytest .MonkeyPatch ):
697+ """A session.created that never arrives is reported as STTWebsocketConnectionError
698+ when the timeout comes from asyncio.wait_for rather than the patched deadline clock.
699+ """
700+ monkeypatch .setattr ("agents.voice.models.openai_stt.SESSION_CREATION_TIMEOUT" , 0.01 )
701+ mock_ws = create_mock_websocket ([])
702+
703+ with patch ("websockets.connect" , return_value = mock_ws ):
704+ audio_input = await StreamedAudioInputFactory .get (count = 2 )
705+ session = OpenAISTTTranscriptionSession (
706+ input = audio_input ,
707+ client = create_mock_openai_client (),
708+ model = "whisper-1" ,
709+ settings = STTModelSettings (),
710+ trace_include_sensitive_data = False ,
711+ trace_include_sensitive_audio_data = False ,
712+ )
713+
714+ with pytest .raises (STTWebsocketConnectionError ) as exc_info :
715+ async for _ in session .transcribe_turns ():
716+ pass
717+
718+ assert "Timeout waiting for transcription_session.created event" in str (exc_info .value )
719+
720+ await session .close ()
721+
722+
681723@pytest .mark .asyncio
682724async def test_session_error_event (monkeypatch : pytest .MonkeyPatch ):
683725 """
0 commit comments