fix(voice): attribute provider terminal failures safely
This commit is contained in:
@@ -15,7 +15,7 @@ from app.modules.knowledge.langchain_tool import ToolContext, create_search_tool
|
||||
from app.modules.knowledge.service import SearchInput, authority, transaction
|
||||
from app.infrastructure.realtime import canonical_json, strict_json, ProviderProtocolError
|
||||
from app.modules.voice.settings import RuntimeSettings
|
||||
from app.modules.voice.diagnostics import diagnostic, protocol_reason, trace
|
||||
from app.modules.voice.diagnostics import diagnostic, protocol_reason, terminal_failure_reason, trace
|
||||
from app.modules.voice.serialization import bounded_json, json_size, bounded_json_digest
|
||||
|
||||
def identity():
|
||||
@@ -721,6 +721,8 @@ class VoiceRuntime:
|
||||
self.sync_failed("PROVIDER_TRANSPORT_LOST_DURING_SYNC",
|
||||
phase="provider_receive", exc=exc, turn=self.cleanup_owner())
|
||||
else:
|
||||
diagnostic(self.session_id, "provider_receive", "PROVIDER_TRANSPORT_LOST",
|
||||
exc=exc, code="LIVE_PROVIDER_UNAVAILABLE")
|
||||
self.fail("LIVE_PROVIDER_UNAVAILABLE")
|
||||
|
||||
async def _sender(self):
|
||||
@@ -1542,11 +1544,19 @@ class VoiceRuntime:
|
||||
return
|
||||
limited = bool(getattr(self.adapter, "token_limited", lambda _: False)(wire))
|
||||
if wire["status"] not in ("completed", "cancelled", "waiting_tools") and not limited:
|
||||
diagnostic(self.session_id, "provider_terminal", terminal_failure_reason(wire),
|
||||
event_type=kind, code="LIVE_PROVIDER_UNAVAILABLE",
|
||||
terminal_failed=int(wire["status"] == "failed"),
|
||||
terminal_incomplete=int(wire["status"] == "incomplete"),
|
||||
terminal_tool_calls=len(response.calls), terminal_output_items=len(wire["output"]))
|
||||
self.fail("LIVE_PROVIDER_UNAVAILABLE", turn=response.turn)
|
||||
return
|
||||
# Unfinished tool context cannot safely be reused; fail before execution.
|
||||
if limited and (response.calls or any(
|
||||
item.get("type") != "message" for item in wire["output"])):
|
||||
diagnostic(self.session_id, "provider_terminal", "TOKEN_LIMIT_WITH_UNFINISHED_TOOLS",
|
||||
event_type=kind, code="LIVE_PROVIDER_UNAVAILABLE", terminal_limited=1,
|
||||
terminal_tool_calls=len(response.calls), terminal_output_items=len(wire["output"]))
|
||||
self.fail("LIVE_PROVIDER_UNAVAILABLE", turn=response.turn)
|
||||
return
|
||||
terminal_calls = set()
|
||||
|
||||
Reference in New Issue
Block a user