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:
@@ -286,3 +286,16 @@ def test_terminal_technical_failure_is_not_accepted_as_cancellation_race(
|
||||
finally:
|
||||
await runtime.close()
|
||||
asyncio.run(scenario())
|
||||
|
||||
@pytest.mark.parametrize("model,voice,accepted", [
|
||||
("gpt-realtime-mini", "shimmer", True),
|
||||
("gpt-realtime-2.1", "shimmer", True),
|
||||
("gpt-realtime-2.1", "alloy", False),
|
||||
("gpt-realtime-2.1-mini", "shimmer", False),
|
||||
])
|
||||
def test_no_active_classifier_is_profile_and_signature_bounded(model, voice, accepted):
|
||||
from app.infrastructure.realtime import RealtimeAdapter
|
||||
adapter = RealtimeAdapter(object(), model=model, voice=voice)
|
||||
assert adapter.is_no_active(CAPTURED_NO_ACTIVE) is accepted
|
||||
assert not adapter.is_no_active(dict(CAPTURED_NO_ACTIVE, code="other"))
|
||||
assert not adapter.is_no_active(dict(CAPTURED_NO_ACTIVE, param="response_id"))
|
||||
@@ -121,7 +121,7 @@ def test_capacity_diagnostics_identify_the_failure_without_payloads(runner, pers
|
||||
await runtime.input_audio(bytes(9600))
|
||||
reason = "CAPTURE_TRANSPORT_CAPACITY"
|
||||
elif branch == "late_start":
|
||||
await stream(runtime, 1500, now)
|
||||
await stream(runtime, 3300, now)
|
||||
await runtime.handle(dict(type="input_audio_buffer.speech_started",
|
||||
item_id="private-input-id", audio_start_ms=0))
|
||||
reason = "UNCOMMITTED_SPEECH_BYTES"
|
||||
@@ -129,12 +129,12 @@ def test_capacity_diagnostics_identify_the_failure_without_payloads(runner, pers
|
||||
await runtime.handle(dict(type="input_audio_buffer.speech_started",
|
||||
item_id="private-input-id", audio_start_ms=0))
|
||||
# Fixed clock isolates the byte bound from the independent wall deadline.
|
||||
for _ in range(50):
|
||||
for _ in range(320):
|
||||
await runtime.input_audio(bytes(9600))
|
||||
async with asyncio.timeout(3):
|
||||
while runtime.input_transport_count:
|
||||
await asyncio.sleep(0)
|
||||
assert runtime.uncommitted_speech_bytes == 480000
|
||||
assert runtime.uncommitted_speech_bytes == 3072000
|
||||
await runtime.input_audio(bytes(2))
|
||||
reason = "UNCOMMITTED_SPEECH_BYTES"
|
||||
assert runtime.failure == "LIVE_BUFFER_OVERFLOW" and runtime.close_code == 1013
|
||||
@@ -146,3 +146,29 @@ def test_capacity_diagnostics_identify_the_failure_without_payloads(runner, pers
|
||||
finally:
|
||||
await runtime.close()
|
||||
asyncio.run(scenario())
|
||||
|
||||
@pytest.mark.parametrize("speech_seconds", [10, 30, 60])
|
||||
def test_continuous_speech_with_padding_reaches_new_bound(runner, persisted, speech_seconds):
|
||||
async def scenario():
|
||||
now = [0.]
|
||||
runtime, _, _ = await make(SimpleNamespace(engine=None), runner, persisted,
|
||||
clock=lambda: now[0])
|
||||
try:
|
||||
await runtime.handle(dict(type="input_audio_buffer.speech_started",
|
||||
item_id="u1", audio_start_ms=0))
|
||||
turn = runtime.current
|
||||
assert turn.speech_deadline == 65
|
||||
# Four seconds covers the maximum configured VAD prefix/silence padding.
|
||||
for _ in range((speech_seconds + 4) * 5):
|
||||
await runtime.input_audio(bytes(9600))
|
||||
await until(lambda: runtime.input_transport_count == 0)
|
||||
now[0] += .2
|
||||
assert runtime.usable
|
||||
assert runtime.uncommitted_speech_bytes == (speech_seconds + 4) * 48000
|
||||
await runtime.handle(dict(type="input_audio_buffer.speech_stopped",
|
||||
item_id="u1", audio_end_ms=(speech_seconds + 4) * 1000))
|
||||
await runtime.handle(dict(type="input_audio_buffer.committed", item_id="u1"))
|
||||
assert turn.committed and runtime.uncommitted_speech_bytes == 0
|
||||
finally:
|
||||
await runtime.close()
|
||||
asyncio.run(scenario())
|
||||
@@ -202,3 +202,33 @@ def test_provider_decode_failure_has_safe_specific_reason(caplog, raw, reason):
|
||||
assert reason in caplog.text
|
||||
assert raw not in caplog.text
|
||||
asyncio.run(scenario())
|
||||
|
||||
def test_close_deadline_does_not_strand_provider_cleanup(runner, persisted, caplog):
|
||||
async def scenario():
|
||||
runtime, wire, _ = await make(SimpleNamespace(engine=None), runner, persisted)
|
||||
runtime.settings = RuntimeSettings(_env_file=None, send_timeout_seconds=.03)
|
||||
release = asyncio.Event()
|
||||
started = asyncio.Event()
|
||||
|
||||
async def stubborn():
|
||||
started.set()
|
||||
while not release.is_set():
|
||||
try:
|
||||
await release.wait()
|
||||
except asyncio.CancelledError:
|
||||
continue
|
||||
|
||||
task = asyncio.create_task(stubborn())
|
||||
runtime.tasks.add(task)
|
||||
await started.wait()
|
||||
runtime.fail("LIVE_PROVIDER_PROTOCOL_ERROR", writable=False)
|
||||
try:
|
||||
with pytest.raises(TimeoutError):
|
||||
await runtime.close()
|
||||
assert runtime.failure == "LIVE_PROVIDER_PROTOCOL_ERROR"
|
||||
assert runtime._provider_close_task.done()
|
||||
assert "pending_tasks=1" in caplog.text
|
||||
finally:
|
||||
release.set()
|
||||
await task
|
||||
asyncio.run(scenario())
|
||||
Reference in New Issue
Block a user