Merge pull request #3581 from pipecat-ai/filipi/open_ai_audio_duration

Fixed race condition in OpenAIRealtimeLLMService
This commit is contained in:
Filipi da Silva Fuchter
2026-01-28 07:42:35 -05:00
committed by GitHub
2 changed files with 9 additions and 0 deletions

1
changelog/3581.fixed.md Normal file
View File

@@ -0,0 +1 @@
- Fixed race condition in `OpenAIRealtimeLLMService` that could cause an error when truncating the conversation.

View File

@@ -599,6 +599,14 @@ class OpenAIRealtimeLLMService(LLMService):
# note: ttfb is faster by 1/2 RTT than ttfb as measured for other services, since we're getting
# this event from the server
await self.stop_ttfb_metrics()
if self._current_audio_response and self._current_audio_response.item_id != evt.item_id:
logger.warning(
f"Received a new audio delta for an already completed audio response before receiving the BotStoppedSpeakingFrame."
)
logger.debug("Forcing previous audio response to None")
self._current_audio_response = None
if not self._current_audio_response:
self._current_audio_response = CurrentAudioResponse(
item_id=evt.item_id,