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:
gabby committed 2026-10-09 09:41:00 +00:00
1 parent e86ed805ee
commit f6ef66b532
9 files changed
+391 -33

No files matched your search

+43 -2
View File
@@ -631,7 +631,21 @@ class Scheduler:
a pre-act contract variable is left unset and marked skipped, and an
act-driven pause receives the empty string (the body may then fail,
which is assessed normally).
Guarded like `submit_request`: a front end calls this synchronously
(the voice adapter from its worker thread), so an engine failure must
be fatal-and-reported, and any other error must come back as a reply
rather than propagate and take the front end down.
"""
try:
return self._answer(text)
except EngineUnavailable as exc:
return SchedulerReply("fatal", self._mark_fatal(exc))
except Exception as exc:
self.trace.append("error", "?", phase="answer", message=str(exc))
return SchedulerReply("error", f"could not resume the run: {exc}")
def _answer(self, text: str) -> SchedulerReply:
with self._lock:
if self.pending is None:
return SchedulerReply("error", "no run is waiting for input")
@@ -818,8 +832,17 @@ class Scheduler:
"""Answer a deferred question. An empty answer skips it.
A repair question carries the detail the user wants the skill repaired
with; answering it starts the repair directly.
with; answering it starts the repair directly. Guarded so an engine or
repair failure is reported instead of propagating into the front end.
"""
try:
return self._answer_question(question_id, text)
except EngineUnavailable as exc:
return "fatal", self._mark_fatal(exc)
except Exception as exc:
return "error", f"could not record the answer: {exc}"
def _answer_question(self, question_id: str, text: str) -> tuple[str, str]:
offer_id: str | None = None
answer = (text or "").strip()
with self._lock:
@@ -870,7 +893,16 @@ class Scheduler:
The draft worker is blocked in `_request_approval`; setting the status
and notifying releases it (True registers + writes the body, False
aborts). The terminal trace event is written by the worker, not here.
Guarded so an unexpected failure is reported instead of propagating.
"""
try:
return self._answer_approval(approval_id, approved)
except EngineUnavailable as exc:
return "fatal", self._mark_fatal(exc)
except Exception as exc:
return "error", f"could not record the approval: {exc}"
def _answer_approval(self, approval_id: str, approved: bool) -> tuple[str, str]:
with self._lock:
approval = next(
(a for a in self.approvals if a.id == approval_id), None
@@ -915,8 +947,17 @@ class Scheduler:
`retry` requeues the original request; `repair_skill` rewrites the body
from the observed failure; `ask_user` posts a question whose answer
starts the repair; `no_repair` closes the offer. Repair writes are
bounded by `codegen.repair.max_attempts` per skill.
bounded by `codegen.repair.max_attempts` per skill. Guarded so a retry
run or write failure is reported instead of propagating.
"""
try:
return self._resolve_repair(offer_id, action)
except EngineUnavailable as exc:
return "fatal", self._mark_fatal(exc)
except Exception as exc:
return "error", f"could not execute the repair: {exc}"
def _resolve_repair(self, offer_id: str, action: str | None = None) -> tuple[str, str]:
with self._lock:
offer = next((r for r in self.repairs if r.id == offer_id), None)
if offer is None: