Plan 3 fix: GA turn_detection auto-create_response + reset state on WS reconnect

GA Realtime API requires create_response:true and interrupt_response:true
inside turn_detection — without them the model never auto-generates a
reply after VAD detects speech_stopped, so the relay idles out at 30s
with no assistant audio. Add both.

Client side: when the /device WS drops (Coolify rolling deploy, etc.),
Session.run_forever reconnects but the StateMachine kept whatever state
it was in — usually LISTENING, which permanently disables the wakeword.
Add StateMachine.force_idle() and a Callbacks.on_disconnected() hook;
main.py wires it to force the state back to IDLE on every disconnect.
Also harden Session's fire-and-forget send_* helpers to swallow
ConnectionClosed instead of bubbling up as unhandled task exceptions.
This commit is contained in:
2026-06-12 06:50:00 +00:00
parent 7294a81a9a
commit 8bb0ce51b1
5 changed files with 79 additions and 12 deletions
+25
View File
@@ -100,3 +100,28 @@ def test_sleep_played_outside_idle_pending_is_noop():
sm = StateMachine()
sm.sleep_played()
assert sm.state is State.IDLE
def test_force_idle_from_listening_resets_state_and_reenables_wakeword():
sm = StateMachine()
sm.wake_fired()
sm.session_started()
assert sm.state is State.LISTENING
sm.force_idle()
assert sm.state is State.IDLE
assert sm.wakeword_enabled
def test_force_idle_from_assistant_speaking_resets():
sm = StateMachine()
sm.wake_fired()
sm.session_started()
sm.assistant_audio_arrived()
sm.force_idle()
assert sm.state is State.IDLE
def test_force_idle_on_idle_is_noop():
sm = StateMachine()
sm.force_idle()
assert sm.state is State.IDLE