voice: tolerate the wake-tail pause; harden the front end
Endpointing fix. The wake detector usually fires inside the wake phrase, so the first speech captured after it is the phrase's tail (plus the cue beep echoing back through the mic), not the command. A fixed 500 ms trailing-silence endpoint then ended the capture during the natural pause before the command: the utterance held 240-400 ms of speech and STT returned empty. In a recorded session 18 of 30 wakes dropped the command that way (only 10 transcribed). The endpoint now uses a longer silence tolerance (vad.initial_silence_ms, default 1500) until vad.min_command_ms (default 700) of speech is in hand, then reverts to vad.silence_ms, so a pause before the command is tolerated while a real command still ends promptly. Front-end hardening (the ways it was silently dying or losing work): - Utterances run on a worker thread, not the audio thread, and a task error is traced and spoken rather than propagated, so one bad command cannot stop the mic or take the front end down. - Capture-stream watchdog: read with a timeout and close/reopen the input after a sustained stall, so a wedged PortAudio/ALSA callback recovers instead of hanging the gateway (traced voice_stream_stalled/reopened). - faulthandler enabled (CLI + unit) so a fatal signal dumps every thread's stack to the journal. - The scheduler's answer-side entry points (answer, answer_question, resolve_repair, answer_approval) are guarded like submit_request: an EngineUnavailable is fatal-and-reported and any other resume/repair error returns a reply instead of propagating into a front end.
This commit is contained in:
1 parent
e86ed805ee
commit
f6ef66b532
9 files changed
+391
-33
No files matched your search
@@ -201,6 +201,37 @@ def test_service_routes_pending_answer_to_same_chat(tmp_path):
|
||||
assert any("AB123" in text for text in drain_outbound(service))
|
||||
|
||||
|
||||
def test_service_survives_answer_failure(tmp_path):
|
||||
# A resume that raises must come back as a reply, never propagate into the
|
||||
# front end (the voice adapter calls handle_inbound synchronously).
|
||||
scheduler = build_scheduler(tmp_path)
|
||||
service = build_service(scheduler)
|
||||
scheduler._run_skill(need_input_skill([]), Request("track it", source="simplex:4"))
|
||||
assert scheduler.pending is not None
|
||||
|
||||
def boom(*_args, **_kwargs):
|
||||
raise RuntimeError("kaboom")
|
||||
|
||||
scheduler._answer = boom
|
||||
service.handle_inbound(InboundMessage(text="AB123", chat_id="4", contact_id="4"))
|
||||
assert any("kaboom" in text for text in drain_outbound(service))
|
||||
|
||||
|
||||
def test_answer_engine_unavailable_is_fatal(tmp_path):
|
||||
from semif_agent.engine import EngineUnavailable
|
||||
|
||||
scheduler = build_scheduler(tmp_path)
|
||||
scheduler._run_skill(need_input_skill([]), Request("track it", source="simplex:4"))
|
||||
|
||||
def boom(*_args, **_kwargs):
|
||||
raise EngineUnavailable("engine down")
|
||||
|
||||
scheduler._answer = boom
|
||||
reply = scheduler.answer("AB123")
|
||||
assert reply.status == "fatal"
|
||||
assert scheduler.fatal is not None
|
||||
|
||||
|
||||
def test_service_refuses_other_chat_during_pending(tmp_path):
|
||||
scheduler = build_scheduler(tmp_path)
|
||||
service = build_service(scheduler)
|
||||
|
||||
Reference in new issue
Block a user