From f978702a6cc64ee064e3ccfec7c1acd06502da0e Mon Sep 17 00:00:00 2001 From: "a.arystanbek" Date: Sun, 30 Aug 2026 21:14:25 +0000 Subject: [PATCH] fix: retry voice turn once on Postgres deadlock instead of failing the call with a technical-error handoff --- services/ai_voice_runtime_service/app.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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