voice: hold the wake word until the scheduler reaches a result

Gate the wake word on the scheduler's single slot being free: a wake that
fires while the current request is still running is ignored (traced
voice_wake_blocked), so a second command cannot start mid-run. The gate is
GatewayService.input_ready (False while a run executes, True when idle or
paused for the user's answer), handed to adapters via set_input_ready; the
voice adapter passes it to VoiceDaemon.input_ready.
This commit is contained in:
gabby committed 2026-10-09 23:52:57 +00:00
1 parent ff94ea938c
commit 88700898be
8 files changed
+130 -7

No files matched your search

+23
View File
@@ -128,6 +128,13 @@ class GatewayService:
humanize_cfg = humanize_cfg if isinstance(humanize_cfg, dict) else {}
self._humanize_default = bool(humanize_cfg.get("enabled", False))
self.humanizer = self._build_humanizer(humanize_cfg)
#: Let an adapter that needs it gate input on the scheduler being free
#: (the voice gateway holds the wake word until the current request
#: reaches a result). Generic hook; only some adapters implement it.
for adapter in self.adapters.values():
setter = getattr(adapter, "set_input_ready", None)
if callable(setter):
setter(self.input_ready)
self._owners: dict[str, Target] = {}
self._parents: dict[str, str] = {}
self._pending_owner: Target | None = None
@@ -275,6 +282,22 @@ class GatewayService:
return (platform, source[len(prefix):])
return None
def input_ready(self) -> bool:
"""Whether a new command may start now.
False while the single scheduler slot is executing a run; True when the
scheduler is idle or paused for the user's answer to a question (the run
is not running, so the answer must be accepted). The voice gateway uses
this to hold the wake word until the current request has reached a
result. Reads the scheduler's flags without its lock on purpose — the
lock is held for the whole run, so acquiring it here would block the
audio loop for the duration of the run.
"""
scheduler = self.scheduler
if getattr(scheduler, "pending", None) is not None:
return True
return getattr(scheduler, "current", None) is None
def handle_inbound(self, msg: InboundMessage, platform: str | None = None) -> None:
"""Handle one authorized inbound command. Called by the adapter."""
if platform is None:
+10
View File
@@ -53,6 +53,16 @@ class VoiceAdapter(GatewayAdapter):
def check_requirements(self) -> tuple[bool, str | None]:
return self.daemon.check_requirements()
def set_input_ready(self, ready) -> None:
"""Gate the wake word on the scheduler being able to accept a command.
`ready` is a callable returning whether a new command may start now
(`GatewayService.input_ready`). While it returns False the wake word is
ignored, so a second command cannot be started before the current
request has reached a result.
"""
self.daemon.input_ready = ready
# ---- transport ----
def run(