From a47c09d4656f2a88e33dc683a3947767e3a697dc Mon Sep 17 00:00:00 2001 From: Yera All Date: Wed, 8 Apr 2026 01:06:08 +0500 Subject: [PATCH] fix(voice): prevent regex heuristic from overwriting LLM-extracted customer name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Block old _voice_downstream_name_update from overwriting name_obtained status unless user explicitly says 'меня зовут X' (explicit_candidate only) - Move _persist_voice_name_state to run AFTER LLM extraction, not before, so LLM always gets a chance to override the regex result - Fixes bug where phrases like 'можешь назвать их' were incorrectly captured as customer name, overwriting the real name --- services/ai_orchestrator_service/voice.py | 30 ++++++++--------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/services/ai_orchestrator_service/voice.py b/services/ai_orchestrator_service/voice.py index 58b4f50..2ff607f 100644 --- a/services/ai_orchestrator_service/voice.py +++ b/services/ai_orchestrator_service/voice.py @@ -712,9 +712,7 @@ def _voice_downstream_name_update( action = "provide" if not name_value else "confirm" candidate = candidate or name_value elif status == "name_obtained": - if candidate and candidate_key and candidate_key != current_key and ( - _voice_has_name_correction(transcript_text) or explicit_candidate is not None - ): + if explicit_candidate and candidate_key and candidate_key != current_key: action = "correct" else: if explicit_candidate: @@ -1934,15 +1932,6 @@ def turn_voice_session(session_id: str, payload: VoiceAITurnIn) -> VoiceAITurnDe if finalized_name: name_update["value"] = finalized_name name_update["resolved_at"] = now - _persist_voice_name_state( - session, - voice_session=voice_session, - status=name_update["status"], - value=name_update["value"], - source=name_update["source"], - resolved_at=name_update["resolved_at"], - ) - kb_results = app._kb_search( session, payload.transcript_text, @@ -1978,14 +1967,15 @@ def turn_voice_session(session_id: str, payload: VoiceAITurnIn) -> VoiceAITurnDe ) if finalized_name: name_update["value"] = finalized_name - _persist_voice_name_state( - session, - voice_session=voice_session, - status=name_update["status"], - value=name_update["value"], - source=name_update["source"], - resolved_at=name_update["resolved_at"], - ) + + _persist_voice_name_state( + session, + voice_session=voice_session, + status=name_update["status"], + value=name_update["value"], + source=name_update["source"], + resolved_at=name_update["resolved_at"], + ) decision_metadata = _voice_name_metadata( language=voice_session.voice_start_language or ai_session.language or "ru",