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
+18 -6
View File
@@ -10,7 +10,7 @@ from app.infrastructure.gemini_live import GeminiLiveAdapter
from app.infrastructure.realtime import RealtimeAdapter
from app.modules.voice.runtime import VoiceRuntime
from app.modules.voice.settings import RuntimeSettings
from tests.unit.test_gemini_live import FakeGoogleTransport, make, cleanup
from tests.unit.test_gemini_live import FakeGoogleTransport, make, cleanup, input_turn as gemini_input_turn
from tests.unit.test_realtime_phase1 import runner, persisted, until
@pytest.mark.parametrize('provider,adapter,rate', [('gemini',GeminiLiveAdapter,16000),('openai',RealtimeAdapter,24000)])
@@ -80,18 +80,30 @@ def test_actual_authority_check_deadline(runner):
await r.start();assert r.failure=='SEARCH_TIMEOUT';await r.close()
asyncio.run(scenario())
def test_ten_seconds_continuous_uncommitted_silence_keeps_frozen_bound(runner,persisted):
def test_thirty_seconds_gemini_silence_keeps_transport_bounded(runner,persisted):
async def scenario():
r,adapter,wire,out,receive=await make(SimpleNamespace(engine=None),runner,persisted)
try:
for _ in range(100):
for _ in range(300):
await r.input_audio(bytes(4800))
await until(lambda:r.input_transport_count==0 or not r.usable)
async with asyncio.timeout(3):
while r.input_transport_count and r.usable:
await asyncio.sleep(0)
assert r.usable,r.failure
assert r.input_dispatched_total==480000
assert r.input_dispatched_total==1440000
assert r.uncommitted_speech_bytes == r.input_transport_bytes == 0
assert not r.inputs and r.input_committed_total == 0
await r.input_audio(bytes(2))
assert r.failure=='LIVE_BUFFER_OVERFLOW'
await until(lambda: r.input_transport_count == 0)
assert r.usable and r.failure is None
assert not any('toolResponse' in m for m in wire.sent)
await gemini_input_turn(r, wire, start=30000)
await wire.inbound.put({'serverContent': {'modelTurn': {'parts': [
{'inlineData': {'mimeType': 'audio/pcm;rate=24000', 'data': 'AAA='}}
]}}})
await until(lambda: r.current is not None and r.current.committed or not r.usable)
assert r.usable and r.current.stop_boundary == 30100 * 48
assert r.input_committed_total == r.current.stop_boundary
finally:await cleanup(r,receive)
asyncio.run(scenario())