Playback still happen for late response.create (after the timeout of its corresponding generate_reply)
Bug Description
According to https://deepwiki.com/search/after-failed-to-generate-a-rep_2136620f-4226-4394-96f6-b0867e3fd25b?mode=deep, the timeout of generate_reply does not trigger response.cancel to stop response.create and thus openai request pipeline triggered by generate_reply still keep running even though internal generate_reply timed out happened. In this situation, late response.created (after the timeout of its corresponding generate_reply) won't resolve any future, and thus no SpeechHandle is ever wired up to consume the audio events generated by the timeouted generate_reply, which should lead to no playback for it.
However, when I try to trigger "failed to generate a reply: generate_reply timed out." through reducing the default timeout of the corresponding source code from 10 to 0.01 in livekit/plugins/openai/realtime/realtime_model.py and then implementing await agent_session.generate_reply(). Playback for the timeouted generate_reply does happen after the late response.created(after the timeout)
Expected Behavior
Playback should not happen for late response.create (after the timeout of its corresponding generate_reply)
Reproduction Steps
1. Reduce the default timeout of the corresponding source code from 10 to 0.01 in `livekit/plugins/openai/realtime/realtime_model.py`
2. Use openai realtime model with openai.realtime.RealtimeModel(
model="gpt-realtime",
voice="marin",
turn_detection=ServerVad(
type="server_vad"
prefix_padding_ms=300,
silence_duration_ms=500,
threshold=0.5,
create_response=False,
interrupt_response=False,
),
temperature=0.6,
input_audio_noise_reduction=NOT_GIVEN
),
input_audio_transcription=AudioTranscription(language=lang, model="whisper-1"),
max_session_duration=55 * 60,
)
3. Implement `await agent_session.generate_reply()`
Operating System
Linus, MacOS
Models Used
"gpt-realtime"
Package Versions
"livekit~=1.1",
"livekit-agents[azure,openai,turn-detector,silero,elevenlabs]==1.6.0",
"livekit-api~=1.1",
"livekit-plugins-noise-cancellation~=0.2.0"
Session/Room/Call IDs
No response
Proposed Solution
May be offer developer a choice to stop response.create when the timeout of generate_reply happen to ensure its corresponding playback not happen. I have mentioned here:
https://github.com/livekit/agents/issues/6223
Additional Context
``
Screenshots and Recordings
No response
duplicates #6223