Skip to content

fix(telnyx): detect a silently dropped STT socket instead of hanging - #7359

Open
sidxh wants to merge 1 commit into
livekit:mainfrom
sidxh:fix/telnyx-half-open
Open

sidxh wants to merge 1 commit into
livekit:mainfrom
sidxh:fix/telnyx-half-open

Conversation

@sidxh

@sidxh sidxh commented Sep 19, 2026

Copy link
Copy Markdown

On a half-open connection (no FIN, no RST) the Telnyx STT SpeechStream sits on a dead socket forever: the session stays open, no transcripts arrive, and nothing is ever logged.

Two things cause it, same class as Deepgram v1 before #7206 and Soniox in #7357. _connect_ws opens the socket without heartbeat, so recv_task parks on ws.receive() and the retry in _main_task, which only runs when something raises, never gets a turn. This plugin has no keepalive task, so when audio stops nothing else touches the socket either. And a WSMsgType.ERROR (how a heartbeat timeout arrives) was logged and stepped over; the loop only ended because a CLOSED followed, raised as a generic "closed unexpectedly" with the reason on ws.exception() dropped.

This adds heartbeat=30.0 (parity with Deepgram and Muse) and raises a retryable APIConnectionError from the ERROR frame with ws.exception() as the cause, so _main_task reconnects deterministically and the log says why.

Verified against a local fake Telnyx server that goes dead 10s into each connection while keeping the TCP socket open, with a real SpeechStream pushing silence for 120s. On main the last transcript is at 9.2s, nothing is logged for the remaining 110s, and one socket is opened. With this change the plugin logs Telnyx STT connection lost (caused by ServerTimeoutError: No PONG received after 15.0 seconds) at 55.8s, reconnects, and transcripts resume at 57s; three sockets over the run. Two regression tests added in a new tests/test_plugin_telnyx_stt.py; both fail on main.

This deliberately leaves the send path alone. #6474 covers send-side drops across several plugins including this one, and the two changes are independent.

30s heartbeat means ~46s to detect, which is long for a live call. Kept it for parity; happy to lower it.

Closes #7358.

Add heartbeat=30.0 to the STT ws_connect and raise a retryable
APIConnectionError from recv_task on WSMsgType.ERROR, with ws.exception()
attached, so _main_task reconnects and the reason is logged. Same fix as
livekit#7206 for Deepgram v1 and livekit#7357 for Soniox.
@sidxh
sidxh requested a review from a team as a code owner September 19, 2026 21:27

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

telnyx STT: a silently dropped WebSocket is never detected

1 participant