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:
amirhosein mazaheri
2026-10-10 17:41:11 +03:30
parent b06eaf59f4
commit a769196bfa
23 changed files with 1809 additions and 92 deletions
+11 -1
View File
@@ -25,6 +25,13 @@ def unregister(session_id):
if entry:
entry.finished.set()
def failure_outcome(session_id):
# Called from the durable close transaction. Failure is an immutable first
# outcome published on the owner loop before any error reaches the browser.
with _LOCK:
entry = ENTRIES.get(session_id)
return entry.runtime.failure if entry else None
def notify(*, organization_id=None, new_epoch=None, auth_session_id=None, session_id=None, code='CONTEXT_REVOKED'):
with _LOCK:
selected = [e for sid, e in ENTRIES.items()
@@ -34,7 +41,10 @@ def notify(*, organization_id=None, new_epoch=None, auth_session_id=None, sessio
and (session_id is None or sid == session_id)]
async def fail(entry):
async with entry.runtime.lock:
entry.runtime.fail(code)
if code == "user_requested":
entry.runtime.stop_requested()
else:
entry.runtime.fail(code)
for entry in selected:
if not entry.loop.is_closed():
entry.loop.call_soon_threadsafe(lambda e=entry: asyncio.create_task(fail(e)))