fix(voice): correct input accounting and session termination
Separate detected speech limits from continuous microphone silence while preserving transport bounds and absolute commit fencing. Handle verified OpenAI cancellation races and terminal items, preserve causal close outcomes, and share bounded cleanup ownership with safe diagnostics. Add regression coverage and align the API contract and frontend handoff. Validation: 61 focused unit tests passed; staged diff whitespace checks passed. Live browser acceptance remains outstanding.
This commit is contained in:
@@ -40,8 +40,8 @@ class RealtimeAdapter:
|
||||
if not isinstance(self.settings, RuntimeSettings):
|
||||
raise ValueError("Validated runtime settings required")
|
||||
self.transport, self.model, self.voice = transport, model, voice
|
||||
# Fail closed by default: no stable documented structured race code.
|
||||
# Only install a classifier after separate selected-profile acceptance.
|
||||
# The default classifier is restricted to the empirically verified
|
||||
# OpenAI profile below. Other profiles require separate acceptance.
|
||||
self.no_active_classifier = no_active_classifier
|
||||
|
||||
def setup(self):
|
||||
@@ -93,9 +93,31 @@ class RealtimeAdapter:
|
||||
except (ValueError, TypeError, UnicodeError, RecursionError) as exc:
|
||||
raise ProviderProtocolError("Malformed provider event") from exc
|
||||
|
||||
def normalize_output_item(self, item):
|
||||
# GA assistant items use output_audio; internal/Gemini events use audio.
|
||||
# Keep replay hashing on the original wire value and normalize only this
|
||||
# documented item field. Runtime still validates role/layout/identities.
|
||||
if isinstance(item, dict) and item.get("type") == "message":
|
||||
content = item.get("content")
|
||||
if isinstance(content, list):
|
||||
return dict(item, content=[
|
||||
dict(part, type="audio")
|
||||
if isinstance(part, dict) and part.get("type") == "output_audio"
|
||||
else part for part in content])
|
||||
return item
|
||||
|
||||
def is_no_active(self, error):
|
||||
try:
|
||||
return self.no_active_classifier is not None and self.no_active_classifier(error) is True
|
||||
if self.no_active_classifier is not None:
|
||||
return self.no_active_classifier(error) is True
|
||||
# Selected-profile probe: docs/guides/live-context-sync-repair.md.
|
||||
# The runtime separately requires the cancellation intent event_id,
|
||||
# terminal response confirmation, and heard-position truncation.
|
||||
return (self.model == "gpt-realtime-mini" and self.voice == "shimmer"
|
||||
and isinstance(error, dict)
|
||||
and error.get("type") == "invalid_request_error"
|
||||
and error.get("code") == "response_cancel_not_active"
|
||||
and error.get("param") is None)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user