Skip to content

The agent that grows with you

fix(gateway): pool-route wake.start/wake.status — same STT lazy-install chain

kshitij3b3bda7b00df
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py
index bf504a1ecab..1407c9586fb 100644
--- a/tests/test_tui_gateway_server.py
+++ b/tests/test_tui_gateway_server.py
@@ -1612,12 +1612,12 @@ def test_wake_owner_is_sticky_and_routes_detection_to_first_transport(monkeypatc
server._wake_owner_transport = None
server._wake_owner_surface = ""
try:
- started = server.dispatch({
+ started = _dispatch_sync({
"id": "wake-1",
"method": "wake.start",
"params": {"surface": "gui", "session_id": "first-session"},
}, transport=first)
- denied = server.dispatch({
+ denied = _dispatch_sync({
"id": "wake-2",
"method": "wake.start",
"params": {"surface": "tui", "session_id": "second-session"},
@@ -1678,7 +1678,7 @@ def test_wake_owner_is_sticky_and_routes_detection_to_first_transport(monkeypatc
"disabled_persisted": False,
}
- reclaimed = server.dispatch({
+ reclaimed = _dispatch_sync({
"id": "wake-reclaim-2",
"method": "wake.start",
"params": {"surface": "tui", "session_id": "second-session"},
@@ -1748,7 +1748,7 @@ def test_wake_toggle_persists_enabled_flag_only_on_explicit_gesture(monkeypatch)
server._wake_owner_surface = ""
try:
# Passive auto-arm (no persist): refused, config untouched.
- passive = server.dispatch({
+ passive = _dispatch_sync({
"id": "wake-passive",
"method": "wake.start",
"params": {"surface": "gui"},
@@ -1757,7 +1757,7 @@ def test_wake_toggle_persists_enabled_flag_only_on_explicit_gesture(monkeypatch)
assert persisted == []
# Explicit gesture: enables in config AND arms.
- clicked = server.dispatch({
+ clicked = _dispatch_sync({
"id": "wake-click",
"method": "wake.start",
"params": {"surface": "gui", "persist": True},
@@ -1778,7 +1778,7 @@ def test_wake_toggle_persists_enabled_flag_only_on_explicit_gesture(monkeypatch)
# persist does NOT override an explicit surface scoping.
config.update(enabled=True, surface="tui")
- scoped = server.dispatch({
+ scoped = _dispatch_sync({
"id": "wake-scoped",
"method": "wake.start",
"params": {"surface": "gui", "persist": True},
@@ -1832,7 +1832,7 @@ def test_wake_status_reports_configured_input_device_and_windows_silence_hint(mo
server._wake_owner_transport = transport
server._wake_owner_surface = "gui"
try:
- response = server.dispatch(
+ response = _dispatch_sync(
{"id": "wake-status", "method": "wake.status", "params": {}},
transport=transport,
)
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.py
index f22f65fa7d0..08934c7201a 100644
--- a/tests/tui_gateway/test_protocol.py
+++ b/tests/tui_gateway/test_protocol.py
@@ -658,9 +658,12 @@ def test_completion_handlers_are_pool_routed(completion_method, server):
assert completion_method in server._LONG_HANDLERS
[email protected]("voice_method", ["voice.toggle", "voice.record", "voice.tts"])
-def test_voice_handlers_are_pool_routed(voice_method, server):
- """Voice RPCs must run on the pool, never the WS reader thread.
+ "voice_or_wake_method",
+ ["voice.toggle", "voice.record", "voice.tts", "wake.start", "wake.status"],
+)
+def test_voice_and_wake_handlers_are_pool_routed(voice_or_wake_method, server):
+ """Voice and wake RPCs must run on the pool, never the WS reader thread.
Regression: voice.toggle (status) triggers check_voice_requirements() →
STT provider auto-detect → a SYNCHRONOUS faster-whisper lazy install (uv/pip
@@ -668,8 +671,13 @@ def test_voice_handlers_are_pool_routed(voice_method, server):
prompt.submit / session.list frames queued behind it — the desktop showed
sent messages that never reached the agent. Same bug class as #21123 /
#50005: anything that can stall for seconds must stay off the reader thread.
+
+ wake.start and wake.status share the same STT lazy-install path via
+ check_wake_word_requirements() → _stt_ready() → _get_provider(), and
+ wake.start additionally calls lazy_deps.ensure() for wake-word engine deps.
+ The desktop polls wake.status on every gateway-ready.
"""
- assert voice_method in server._LONG_HANDLERS
+ assert voice_or_wake_method in server._LONG_HANDLERS
def test_skin_live_switch_end_to_end(server, tmp_path, monkeypatch):
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index b9649de3c0f..4eb8c1dcf3e 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -285,6 +285,16 @@ _LONG_HANDLERS = frozenset(
"voice.toggle",
"voice.record",
"voice.tts",
+ # wake.start calls check_wake_word_requirements() → _stt_ready() →
+ # _get_provider() → _try_lazy_install_stt() → ensure("stt.faster_whisper")
+ # (same synchronous subprocess install chain as the voice RPCs above).
+ # It also calls start_listening() → _build_engine() whose constructors
+ # call lazy_deps.ensure("wake.openwakeword" / "wake.sherpa" / …).
+ # wake.status calls check_wake_word_requirements() too and is polled
+ # by the desktop on every gateway-ready, so it can re-trigger the
+ # same block on a fresh launch. Same bug class as #21123 / #50005.
+ "wake.start",
+ "wake.status",
# Desktop also polls the in-memory live-session registry every 15s.
# The handler is normally cheap, but under heavy agent GIL pressure it
# can still stall for tens of seconds. Keep it off the WS reader thread