agents icon indicating copy to clipboard operation
agents copied to clipboard

soniox STT: a silently dropped WebSocket is never detected

Open sidxh opened this issue 2 months ago • 0 comments

Bug Description

On a half-open connection (no FIN, no RST) the Soniox SpeechStream sits on a dead socket forever: the session stays open, no transcripts arrive, and nothing is ever logged. This is the same bug #7206 fixed for Deepgram v1 last week, still present in livekit-plugins-soniox.

Three things cause it. _connect_ws opens the socket without heartbeat, so async for msg in self._ws in _recv_messages_task never returns and the reconnect in _run, which only fires when that task ends, never gets a turn. _keepalive_task catches every exception and returns, and when no audio is flowing that write is the only thing that would notice the drop. And a WSMsgType.ERROR (how a heartbeat timeout arrives) hits the "unexpected message type" branch and is stepped over, so the reason on ws.exception() is lost.

Expected Behavior

The dropped connection is detected within the heartbeat window, the reason is logged, and the stream reconnects through the plugin's existing _reconnect_event path.

Reproduction Steps

Run a real soniox.STT(base_url="ws://127.0.0.1:8765") stream against a local aiohttp WebSocket server with autoping=False that answers audio frames with token messages for 10s and then stops reading, stops writing, and stops answering pings while keeping the TCP socket open. Push 20ms silence frames for 120s.

On main: transcripts stop at 10s, no warning or error is logged, one socket for the whole run.

Versions

livekit-agents 1.8.2, livekit-plugins-soniox at main (e5024c76d), aiohttp 3.14.3, Python 3.13, macOS.

sidxh avatar Sep 19 '26 20:09 sidxh