diff --git a/services/ai_voice_runtime_service/app.py b/services/ai_voice_runtime_service/app.py index 284d035..a037024 100644 --- a/services/ai_voice_runtime_service/app.py +++ b/services/ai_voice_runtime_service/app.py @@ -1335,6 +1335,27 @@ def _process_voice_ai_turn_sync( payload: VoiceAITurnIn, *, auto_handoff: bool, +) -> VoiceAITurnDecisionOut: + last_exc: Exception | None = None + for attempt in range(2): + try: + return _process_voice_ai_turn_sync_once(session_id, payload, auto_handoff=auto_handoff) + except HTTPException as exc: + if attempt == 0 and exc.status_code == 502 and "deadlock detected" in str(exc.detail).lower(): + logging.getLogger(__name__).warning("voice_turn_deadlock_retry session_id=%s", session_id) + last_exc = exc + continue + raise + if last_exc is not None: + raise last_exc + raise RuntimeError("unreachable") + + +def _process_voice_ai_turn_sync_once( + session_id: str, + payload: VoiceAITurnIn, + *, + auto_handoff: bool, ) -> VoiceAITurnDecisionOut: session = get_session() voice_session = None