# Think I found a bug in livekit-plugins-deepgram's STT

**URL:** <https://community.livekit.io/t/think-i-found-a-bug-in-livekit-plugins-deepgrams-stt/1596>\
**Category:** Agents\
**Tags:** deepgram\
**Created:** [July 10, 2026, 5:04pm UTC](https://community.livekit.io/t/think-i-found-a-bug-in-livekit-plugins-deepgrams-stt/1596 "2026-07-10T17:04:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Aziz](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/ahmed_aziz/32/1978_2.png) [@Ahmed\_Aziz](https://community.livekit.io/u/Ahmed_Aziz)\
**Post date:** [July 10, 2026, 5:04pm UTC](https://community.livekit.io/t/think-i-found-a-bug-in-livekit-plugins-deepgrams-stt/1596/1 "2026-07-10T17:04:39Z")

</div>

a transient Deepgram disconnect can crash the _entire_ `AgentSession`, not just reconnect the STT leg.

When Deepgram closes the socket, `recv_task` handles it properly (raises a typed, retryable `APIStatusError`). But `send_task` in `SpeechStream._run()` can be mid-write at the same moment and throws a raw `aiohttp.ClientConnectionResetError` instead — it’s not wrapped in try/except like `recv_task` is. Since core `stt.py` only retries on the `APIError` hierarchy and treats everything else as unrecoverable, that raw exception kills the whole session if it happens to land first.

Checked and it’s still there on `main` (not just our pinned 1.6.1) — same unwrapped `ws.send_bytes()` in both `stt.py` and the newer `stt_v2.py`.

---

<div class="post-metadata">

**Author:** ![Edward\_Ed\_Charbeneau](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/edward_ed_charbeneau/32/1765_2.png) [@Edward\_Ed\_Charbeneau](https://community.livekit.io/u/Edward_Ed_Charbeneau)\
**Post date:** [July 10, 2026, 8:47pm UTC](https://community.livekit.io/t/think-i-found-a-bug-in-livekit-plugins-deepgrams-stt/1596/2 "2026-07-10T20:47:16Z")

</div>

I took a look at this with Claude and confirmed the issue.

```  
In `SpeechStream._run()` (both `stt.py` and `stt_v2.py`, current `main`), `recv_task` and `send_task` handle a socket drop asymmetrically:

- `recv_task` converts an unexpected close into a typed `APIStatusError(retryable=True)`.
- `send_task`’s `await ws.send_bytes(...)` / `send_str(...)` are unwrapped, so a mid-write drop raises raw `aiohttp.ClientConnectionResetError` (not in the `APIError` hierarchy).

Both tasks live in one `asyncio.gather`, and `_run` re-raises whichever fails first. So one physical disconnect is a race:

- recv wins → `APIError` caught by `RecognizeStream._main_task`, retried/reconnected. Fine.
- send wins → raw exception isn’t matched by `_main_task`’s `except APIError`, so it escapes with **no retry and no `_emit_error`** — the stream task just dies, taking the session down instead of reconnecting.

Fix: wrap the writes in `send_task` and re-raise connection errors as `APIConnectionError`/`APIStatusError(retryable=True)` so send is symmetric with recv (and swallow-and-return on expected close, like `recv_task` does). Scope the catch to connection errors, not bare `Exception`.

Same unwrapped-`send_bytes` pattern exists in other plugins (elevenlabs, inference STT). Related but distinct from #4609. [ElevenLabs STT stream does not reconnect after mid-stream WebSocket disconnection · Issue #4609 · livekit/agents · GitHub](https://github.com/livekit/agents/issues/4609)  
```

---

<div class="post-metadata">

**Author:** ![darryncampbell](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/darryncampbell/32/20_2.png) [@darryncampbell](https://community.livekit.io/u/darryncampbell)\
**Post date:** [July 13, 2026, 9:29am UTC](https://community.livekit.io/t/think-i-found-a-bug-in-livekit-plugins-deepgrams-stt/1596/3 "2026-07-13T09:29:29Z")

</div>

Thanks @Edward_Ed_Charbeneau - Ed is on the Deepgram DevRel team 🙂

@Edward_Ed_Charbeneau what is the best next step here, will you raise this on our internal channel, or shall I?

---

<div class="post-metadata">

**Author:** ![Edward\_Ed\_Charbeneau](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/edward_ed_charbeneau/32/1765_2.png) [@Edward\_Ed\_Charbeneau](https://community.livekit.io/u/Edward_Ed_Charbeneau)\
**Post date:** [July 13, 2026, 1:30pm UTC](https://community.livekit.io/t/think-i-found-a-bug-in-livekit-plugins-deepgrams-stt/1596/4 "2026-07-13T13:30:17Z")

</div>

I’ll bring this up in our internal Slack. Where our teams can discuss.

---

<div class="post-metadata">

**Author:** ![Tina\_Nguyen](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/tina_nguyen/32/576_2.png) [@Tina\_Nguyen](https://community.livekit.io/u/Tina_Nguyen)\
**Post date:** [July 15, 2026, 4:15am UTC](https://community.livekit.io/t/think-i-found-a-bug-in-livekit-plugins-deepgrams-stt/1596/5 "2026-07-15T04:15:42Z")

</div>

hi all! @Ahmed_Aziz , thank you for surfacing this issue. i’ve opened a PR to address this here: [(deepgram stt): fix reconnect on send-side socket drops instead of crashing the session by tinalenguyen · Pull Request #6429 · livekit/agents · GitHub](https://github.com/livekit/agents/pull/6429)

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/system/32/26_2.png) [@system](https://community.livekit.io/u/system)\
**Post date:** [July 17, 2026, 4:16am UTC](https://community.livekit.io/t/think-i-found-a-bug-in-livekit-plugins-deepgrams-stt/1596/6 "2026-07-17T04:16:32Z")

</div>

Closed on July 17, 2026, 4:16am UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
