fix(voice): expand speech buffer to 60s, handle 2.1 cancellation race, and bound cleanup
- Expand max_input_buffer_bytes to 3,072,000 (64s at 24kHz PCM16) with 65s fixed deadline - Broaden response_cancel_not_active race classifier to include gpt-realtime-2.1/shimmer - Add transport abort method and bound cleanup waits during websocket close - Record repair progress in docs/plans/live-conversation-repair-progress.md
This commit is contained in:
@@ -395,13 +395,21 @@ class VoiceRuntime:
|
||||
return self._provider_close_task
|
||||
|
||||
async def _bounded_provider_close(self):
|
||||
closing = asyncio.create_task(self.adapter.close())
|
||||
done, _ = await asyncio.wait({closing}, timeout=self.settings.send_timeout_seconds)
|
||||
if done:
|
||||
if closing.cancelled():
|
||||
return TimeoutError("Provider close cancelled")
|
||||
return closing.exception()
|
||||
closing.cancel()
|
||||
closing.add_done_callback(lambda task: task.exception() if not task.cancelled() else None)
|
||||
try:
|
||||
await asyncio.wait_for(self.adapter.close(), self.settings.send_timeout_seconds)
|
||||
except Exception as exc:
|
||||
# Return failures through shielded ownership. Python 3.14 otherwise
|
||||
# logs raw exception text when a shield waiter was cancelled.
|
||||
return exc
|
||||
|
||||
aborted = self.adapter.abort()
|
||||
except Exception:
|
||||
aborted = False
|
||||
diagnostic(self.session_id, "provider_close", "CLEANUP_ABORT",
|
||||
code=self.failure, abort_succeeded=int(aborted))
|
||||
return TimeoutError("Provider close deadline")
|
||||
def _provider_close_finished(self, task):
|
||||
if not task.cancelled():
|
||||
exc = task.result()
|
||||
@@ -501,7 +509,7 @@ class VoiceRuntime:
|
||||
speech_bytes=self.uncommitted_speech_bytes)
|
||||
if reason == "SPEECH_STOP_DEADLINE" and turn is not None:
|
||||
state["elapsed_ms"] = int((self.clock() - turn.speech_deadline +
|
||||
self.settings.max_input_buffer_bytes / 48000) * 1000)
|
||||
self.settings.speech_stop_timeout_seconds) * 1000)
|
||||
if audio is not None:
|
||||
state.update(sent_bytes=audio.sent, played_ms=audio.played,
|
||||
elapsed_ms=int((self.clock() - audio.stall_deadline +
|
||||
@@ -1336,7 +1344,7 @@ class VoiceRuntime:
|
||||
if not self.usable:
|
||||
return
|
||||
self.current.start_position = start
|
||||
self.current.speech_deadline = self.clock() + self.settings.max_input_buffer_bytes / 48000
|
||||
self.current.speech_deadline = self.clock() + self.settings.speech_stop_timeout_seconds
|
||||
if not self.check_deadlines():
|
||||
return
|
||||
elif self.inputs[item].start_position != start:
|
||||
@@ -1768,8 +1776,15 @@ class VoiceRuntime:
|
||||
tasks = [*self._workers, *self.tasks]
|
||||
for task in tasks:
|
||||
task.cancel()
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
pending = set()
|
||||
if tasks:
|
||||
_, pending = await asyncio.wait(tasks, timeout=self.settings.send_timeout_seconds)
|
||||
if pending:
|
||||
diagnostic(self.session_id, "runtime_close", "CLEANUP_TIMEOUT",
|
||||
code=self.failure, pending_tasks=len(pending))
|
||||
try:
|
||||
await self._close_provider()
|
||||
except Exception as exc:
|
||||
return exc
|
||||
if pending:
|
||||
return TimeoutError("Runtime task termination deadline")
|
||||
|
||||
Reference in New Issue
Block a user