fix(voice): prevent regex heuristic from overwriting LLM-extracted customer name

- 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
This commit is contained in:
Yera All
2026-04-08 01:06:08 +05:00
parent 6035c5d4d0
commit a47c09d465
+10 -20
View File
@@ -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",