Connect OpenAI Realtime to the existing async StructuredTool and shared SearchToolRunner with backend-owned authority and per-turn source references. Add an operator-only smoke harness with persisted actor and provider opt-in. Enforce confirmed readiness delivery, strict function identity, canonical results and once-only continuations. Bound and pace generated audio, preserve turn correlation, and require acknowledged cleanup before response release. Handle Unicode arguments, UTF-8 replay budgets and user-ASR completion replays. Validate with 318 voice/runner/shutdown tests and 1563 provider-free tests. Three Windows symlink tests skip; 311 PostgreSQL tests are deselected. Real-provider, browser playback and PostgreSQL acceptance remain unrun.
85 lines
4.9 KiB
Python
85 lines
4.9 KiB
Python
"""Validated backend-only Phase 1 runtime deadlines and finite transport limits."""
|
|
from pydantic import Field, field_validator, model_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
class RuntimeSettings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_prefix="LIVE_", env_file=".env",
|
|
extra="ignore", hide_input_in_errors=True, frozen=True)
|
|
connect_timeout_seconds: float = Field(default=15, gt=0, allow_inf_nan=False)
|
|
setup_timeout_seconds: float = Field(default=30, gt=0, allow_inf_nan=False)
|
|
tool_timeout_seconds: float = Field(default=75, gt=0, le=75, allow_inf_nan=False)
|
|
response_ack_timeout_seconds: float = Field(default=15, gt=0, allow_inf_nan=False)
|
|
input_commit_timeout_seconds: float = Field(default=15, gt=0, allow_inf_nan=False)
|
|
truncation_ack_timeout_seconds: float = Field(default=5, gt=0, allow_inf_nan=False)
|
|
send_timeout_seconds: float = Field(default=5, gt=0, allow_inf_nan=False)
|
|
dispatch_wait_timeout_seconds: float = Field(default=5, gt=0, allow_inf_nan=False)
|
|
authority_timeout_seconds: float = Field(default=5, gt=0, allow_inf_nan=False)
|
|
playback_stall_timeout_seconds: float = Field(default=5, gt=0, allow_inf_nan=False)
|
|
final_progress_window_ms: int = Field(default=1000, gt=0, le=1000)
|
|
max_binary_message_bytes: int = Field(default=9600, gt=0, le=9600)
|
|
max_client_control_bytes: int = Field(default=4096, gt=0, le=4096)
|
|
max_server_event_bytes: int = Field(default=65536, ge=1024, le=65536)
|
|
max_queued_audio_seconds: float = Field(default=2, gt=0, le=2, allow_inf_nan=False)
|
|
max_queued_audio_bytes: int = Field(default=96000, gt=0, le=96000)
|
|
max_queued_audio_messages: int = Field(default=100, gt=0, le=100)
|
|
max_input_buffer_bytes: int = Field(default=480000, gt=0, le=480000)
|
|
max_output_backlog_bytes: int = Field(default=1440000, gt=0, le=1440000)
|
|
output_credit_window_bytes: int = Field(default=72000, ge=48, le=72000)
|
|
max_control_messages: int = Field(default=64, ge=2, le=64)
|
|
max_control_bytes: int = Field(default=262144, ge=2048, le=262144)
|
|
max_provider_message_bytes: int = Field(default=262144, ge=4096, le=262144)
|
|
max_unretired_refs: int = Field(default=64, gt=0, le=64)
|
|
max_refs: int = Field(default=256, gt=0, le=256)
|
|
max_input_turns: int = Field(default=256, gt=0, le=256)
|
|
max_intents: int = Field(default=256, gt=0, le=256)
|
|
max_events: int = Field(default=4096, gt=0, le=4096)
|
|
max_tool_calls: int = Field(default=256, gt=0, le=256)
|
|
|
|
@property
|
|
def cancellation_timeout_seconds(self):
|
|
return self.truncation_ack_timeout_seconds
|
|
|
|
@field_validator("*", mode="before")
|
|
@classmethod
|
|
def reject_boolean(cls, value):
|
|
if isinstance(value, bool):
|
|
raise ValueError("Boolean is not a runtime limit")
|
|
return value
|
|
|
|
@field_validator("connect_timeout_seconds", "setup_timeout_seconds",
|
|
"tool_timeout_seconds", "response_ack_timeout_seconds",
|
|
"input_commit_timeout_seconds",
|
|
"truncation_ack_timeout_seconds", "send_timeout_seconds",
|
|
"dispatch_wait_timeout_seconds", "authority_timeout_seconds",
|
|
"playback_stall_timeout_seconds")
|
|
@classmethod
|
|
def representable_timeout(cls, value):
|
|
if value > (2**31 - 1) / 1000:
|
|
raise ValueError("Runtime timeout cannot be represented safely")
|
|
return value
|
|
|
|
@model_validator(mode="after")
|
|
def compatible(self):
|
|
seconds_bytes = int(self.max_queued_audio_seconds * 48000)
|
|
if seconds_bytes % 2 or seconds_bytes < self.max_binary_message_bytes:
|
|
raise ValueError("Queued audio duration must hold an aligned PCM message")
|
|
object.__setattr__(self, "max_queued_audio_bytes",
|
|
min(self.max_queued_audio_bytes, seconds_bytes))
|
|
aligned = (self.max_binary_message_bytes, self.max_queued_audio_bytes,
|
|
self.max_input_buffer_bytes, self.max_output_backlog_bytes,
|
|
self.output_credit_window_bytes)
|
|
if any(value % 2 for value in aligned):
|
|
raise ValueError("PCM byte limits must be sample aligned")
|
|
if not (self.max_binary_message_bytes <= self.output_credit_window_bytes
|
|
<= self.max_queued_audio_bytes <= self.max_output_backlog_bytes):
|
|
raise ValueError("PCM message/window/queue/backlog limits are inconsistent")
|
|
if self.max_provider_message_bytes < 4 * ((self.max_binary_message_bytes + 2) // 3) + 256:
|
|
raise ValueError("Provider envelope cannot hold an admitted PCM message")
|
|
if self.max_input_buffer_bytes < self.max_binary_message_bytes:
|
|
raise ValueError("Input buffer cannot hold a PCM message")
|
|
if self.max_unretired_refs > self.max_refs:
|
|
raise ValueError("Unretired references exceed total reference bound")
|
|
if self.max_control_bytes < self.max_server_event_bytes + 1024:
|
|
raise ValueError("Control budget requires reserved terminal-error capacity")
|
|
return self
|