feat(voice): add isolated Local S2S v3 candidate and acceptance evidence
Extract the provider boundary while retaining OpenAI/Gemini contracts. Add an opt-in isolated Local S2S adapter, pinned engine extension, bounded component gateway and frozen effective configuration profiles. Enforce request token limits, zero retries, local asset validation, connection deadlines, disconnect ownership, bounded cleanup and signals. Include regression coverage, pinned source fixtures, operator guidance, asset fingerprints and guarded disposable PostgreSQL acceptance tooling. Preserve immutable fixture bytes across Git line-ending conversion. Validation recorded in the reports: - 74 repair, 107 combined and 242 preservation checks passed. - Fresh PostgreSQL local checks: 2 passed. - Expanded PostgreSQL: 57 passed, 6 documented baseline failures. - Compose configurations, staged whitespace and fixture hashes passed. Phase 1 live listening and Phase 2 complete engine/SDK/POSIX, real component audio and Persian browser acceptance remain pending. No operational switch, paid call, model download or Phase 3 implementation is included.
This commit is contained in:
@@ -13,7 +13,9 @@ from pydantic import ValidationError
|
||||
from app.modules.knowledge.evidence import SearchExecution
|
||||
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.provider import (
|
||||
canonical_json, strict_json, ProviderProtocolError, VoiceProvider, HistoryRepair, HistoryRepairReceipt,
|
||||
)
|
||||
from app.modules.voice.settings import RuntimeSettings
|
||||
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
|
||||
@@ -133,6 +135,8 @@ class Audio:
|
||||
cleanup: str | None = None
|
||||
cleanup_deadline: float | None = None
|
||||
cleanup_dispatched: bool = False
|
||||
repair: HistoryRepair | None = None
|
||||
repair_receipt: HistoryRepairReceipt | None = None
|
||||
|
||||
@dataclass
|
||||
class Command:
|
||||
@@ -163,7 +167,7 @@ class VoiceRuntime:
|
||||
authority_check is a trusted async backend callback that captures/revalidates
|
||||
the session's persisted actor/epoch. It is never model input.
|
||||
"""
|
||||
def __init__(self, adapter, service, runner, user_id, emit, *,
|
||||
def __init__(self, adapter: VoiceProvider, service, runner, user_id, emit, *,
|
||||
authority_check=None, clock=time.monotonic, tool_seconds=None,
|
||||
session_id=None, max_calls=None, settings=None, close_client=None, tool_store=None):
|
||||
self.settings = settings or getattr(adapter, "settings", None) or RuntimeSettings()
|
||||
@@ -423,8 +427,7 @@ class VoiceRuntime:
|
||||
self.discard_pending_transcript(response)
|
||||
if not response.terminal and not response.cancel_event:
|
||||
response.cancel_event = identity()
|
||||
self.command(dict(type="response.cancel", response_id=response.id,
|
||||
event_id=response.cancel_event))
|
||||
self.command(self.adapter.cancellation_request(response.id, response.cancel_event))
|
||||
task = asyncio.create_task(self._finish_failure(writable))
|
||||
self.tasks.add(task)
|
||||
task.add_done_callback(self._failure_finished)
|
||||
@@ -970,8 +973,7 @@ class VoiceRuntime:
|
||||
audio.data.clear()
|
||||
if not response.terminal and not response.cancel_event:
|
||||
response.cancel_event = identity()
|
||||
self.command(dict(type="response.cancel", response_id=response.id,
|
||||
event_id=response.cancel_event))
|
||||
self.command(self.adapter.cancellation_request(response.id, response.cancel_event))
|
||||
if any(r.visible for r in affected):
|
||||
self.control(dict(type="turn_interrupted", turn_ref=old.ref,
|
||||
cancelled_tool_call_ids=[
|
||||
@@ -1109,8 +1111,9 @@ class VoiceRuntime:
|
||||
self.retire(audio)
|
||||
continue
|
||||
audio.cleanup = identity()
|
||||
self.command(dict(type="conversation.item.truncate", event_id=audio.cleanup,
|
||||
item_id=audio.item, content_index=audio.index, audio_end_ms=audio.played))
|
||||
audio.repair = HistoryRepair(self.session_id, response.turn.token,
|
||||
response.id, audio.cleanup, audio.item, audio.index, audio.played)
|
||||
self.command(self.adapter.history_repair_request(audio.repair))
|
||||
|
||||
async def client_control(self, raw):
|
||||
async with self.lock:
|
||||
@@ -1492,7 +1495,7 @@ class VoiceRuntime:
|
||||
intent = wire.get("metadata", {}).get("voice_intent")
|
||||
if (self.pending_create is None or not self.intent_dispatched
|
||||
or intent != self.pending_create[0]):
|
||||
self.command(dict(type="response.cancel", response_id=wire["id"]))
|
||||
self.command(self.adapter.cancellation_request(wire["id"]))
|
||||
raise ValueError("Unsolicited response")
|
||||
_, turn = self.pending_create
|
||||
response = Response(wire["id"], turn, creation_intent=intent,
|
||||
@@ -1504,8 +1507,7 @@ class VoiceRuntime:
|
||||
response.interrupted = True
|
||||
response.final_deadline = self.clock() + self.settings.final_progress_window_ms / 1000
|
||||
response.cancel_event = identity()
|
||||
self.command(dict(type="response.cancel", response_id=response.id,
|
||||
event_id=response.cancel_event))
|
||||
self.command(self.adapter.cancellation_request(response.id, response.cancel_event))
|
||||
elif self.responses[wire["id"]].creation_intent != wire.get("metadata", {}).get("voice_intent"):
|
||||
raise ValueError("Response creation identity conflict")
|
||||
elif kind in ("response.output_item.added", "response.output_item.done"):
|
||||
@@ -1733,6 +1735,11 @@ class VoiceRuntime:
|
||||
event_type=kind, audio=matches[0] if len(matches) == 1 else None)
|
||||
return
|
||||
audio = matches[0]
|
||||
receipt = self.adapter.confirm_history_repair(audio.repair, event)
|
||||
if (not isinstance(receipt, HistoryRepairReceipt)
|
||||
or receipt.repair != audio.repair):
|
||||
raise ProviderProtocolError("Uncorrelated history repair receipt")
|
||||
audio.repair_receipt = receipt
|
||||
audio.cleanup_deadline = None
|
||||
self.trace("truncate_acknowledged", audio=audio)
|
||||
self.retire(audio)
|
||||
|
||||
Reference in New Issue
Block a user