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

+33
View File
@@ -186,6 +186,39 @@ def test_service_submit_error_is_replied(tmp_path):
assert outbound, "expected a reply"
def test_service_input_ready_tracks_scheduler(tmp_path):
# The voice gateway holds the wake word on this: not ready while a run is
# executing, ready when idle or paused for the user's answer.
scheduler = build_scheduler(tmp_path)
service = build_service(scheduler)
assert service.input_ready() is True # idle
scheduler.busy("working")
assert service.input_ready() is False # a run is executing
scheduler.pending = object() # paused for the answer
assert service.input_ready() is True
scheduler.pending = None
scheduler.current = None
assert service.input_ready() is True
def test_service_wires_input_ready_into_voice_adapter(tmp_path):
# A constructed service hands its `input_ready` to an adapter that exposes
# `set_input_ready` (the voice gateway).
class ReadyAdapter:
name = "voice"
def __init__(self):
self.ready = None
def set_input_ready(self, fn):
self.ready = fn
scheduler = build_scheduler(tmp_path)
adapter = ReadyAdapter()
service = GatewayService(scheduler, adapter, config={})
assert adapter.ready == service.input_ready
def test_service_routes_pending_answer_to_same_chat(tmp_path):
scheduler = build_scheduler(tmp_path)
service = build_service(scheduler)
+33 -2
View File
@@ -84,7 +84,7 @@ class FakeTts:
return b"PCM", 22050
def make_daemon(frames, stt_text="hello", config=None):
def make_daemon(frames, stt_text="hello", config=None, input_ready=None):
audio = FakeAudio(frames)
engines = VoiceEngines(
wake=FakeWake(),
@@ -100,7 +100,7 @@ def make_daemon(frames, stt_text="hello", config=None):
}
if config:
cfg.update(config)
return VoiceDaemon(cfg, engines=engines), engines
return VoiceDaemon(cfg, engines=engines, input_ready=input_ready), engines
# ---- requirements ----------------------------------------------------------
@@ -150,6 +150,37 @@ def test_no_wake_word_produces_nothing():
assert engines.stt.calls == []
# ---- input gating (hold the wake word while the scheduler is busy) ---------
def test_wake_blocked_while_input_not_ready():
# While the scheduler slot is busy the wake word is ignored: no cue, no
# capture, no transcription (traced `voice_wake_blocked`).
ready = {"ok": False}
daemon, engines = make_daemon(
[b"WAKE", b"speech", b"SIL", b"SIL"], input_ready=lambda: ready["ok"]
)
events = []
daemon._event = lambda kind, **kw: events.append(kind)
heard = []
daemon.run(heard.append)
assert heard == []
assert engines.stt.calls == []
assert engines.audio.writes == []
assert "voice_wake_blocked" in events
assert "voice_wake" not in events
def test_wake_allowed_when_input_ready():
ready = {"ok": True}
daemon, engines = make_daemon(
[b"WAKE", b"speech", b"SIL", b"SIL"], input_ready=lambda: ready["ok"]
)
heard = []
daemon.run(heard.append)
assert heard == ["hello"]
def test_max_utterance_caps_collection(monkeypatch):
import semif_agent.voice_transport as vt