fix(voice): attribute provider terminal failures safely
This commit is contained in:
@@ -118,6 +118,7 @@ NUMERIC_FIELDS = frozenset({
|
||||
"generated_bytes", "queued_bytes", "reserved_bytes", "credit_bytes", "discarded_bytes",
|
||||
"chunk_bytes", "lock_wait_ms", "backlog_bytes", "peak_backlog_bytes",
|
||||
"received_elapsed_ms", "terminal_completed", "terminal_cancelled", "terminal_limited",
|
||||
"terminal_failed", "terminal_incomplete", "terminal_tool_calls", "terminal_output_items",
|
||||
"authority_ms", "emit_ms", "queued_controls",
|
||||
"cancellation_type_match", "cancellation_code_match", "cancellation_param_match", "cancellation_profile_2_1_shimmer",
|
||||
"transport_limit_bytes", "transport_limit_messages", "occupancy_count", "limit_count", "occupancy_bytes", "limit_bytes", "transport_bytes", "transport_messages",
|
||||
@@ -162,3 +163,28 @@ def protocol_reason(exc):
|
||||
def terminal_failed(code):
|
||||
return code.startswith("LIVE_") or code in (
|
||||
"SEARCH_TIMEOUT", "SEARCH_SATURATED", "DEPENDENCY_UNAVAILABLE", "SEARCH_CANCELLED")
|
||||
|
||||
|
||||
def terminal_failure_reason(response):
|
||||
"""Classify structured terminal details without retaining provider text."""
|
||||
status = response.get("status")
|
||||
details = response.get("status_details")
|
||||
if isinstance(details, dict):
|
||||
error = details.get("error")
|
||||
if status == "failed" and isinstance(error, dict):
|
||||
code = error.get("code")
|
||||
if isinstance(code, str):
|
||||
reason = {
|
||||
"server_error": "PROVIDER_RESPONSE_SERVER_ERROR",
|
||||
"rate_limit_exceeded": "PROVIDER_RESPONSE_RATE_LIMIT",
|
||||
"insufficient_quota": "PROVIDER_RESPONSE_QUOTA",
|
||||
}.get(code)
|
||||
if reason:
|
||||
return reason
|
||||
if status == "incomplete" and details.get("reason") == "content_filter":
|
||||
return "PROVIDER_RESPONSE_CONTENT_FILTER"
|
||||
if status == "failed":
|
||||
return "PROVIDER_RESPONSE_FAILED"
|
||||
if status == "incomplete":
|
||||
return "PROVIDER_RESPONSE_INCOMPLETE"
|
||||
return "PROVIDER_RESPONSE_UNEXPECTED_STATUS"
|
||||
|
||||
Reference in New Issue
Block a user