Skip to content

fix(transcription): end a stream cleanly when the provider already closed it - #30

Merged
thestumonkey merged 1 commit into
devfrom
pr/stt-closed-stream
Nov 9, 2026
Merged

thestumonkey merged 1 commit into
devfrom
pr/stt-closed-stream

Conversation

@thestumonkey

Copy link
Copy Markdown
Member

Problem

Deepgram closes an idle stream (NET-0001) after about 10 s with no audio. When the session then ended, end_stream sent CloseStream on the dead socket. It raised ConnectionClosedError, logged a traceback, marked transcription completion as error, and never removed the stream from _streams (one leaked entry per such session).

No transcript is lost: finals that arrived before the close were already published.

Fix

  • end_stream pops the stream entry first, so no exit path leaks it.
  • An already-closed socket logs one warning with the close code and reason, then returns an empty final result.

Not in scope

  • Sending Deepgram KeepAlive during audio pauses, so the stream stays open. Not done on purpose.

Tests

  • tests/test_streaming_end_stream_closed.py: fails before the fix, passes after.
  • tests/test_streaming_clock_offset.py: passes.
  • tests/test_voice_streaming_delivery.py already fails 2 tests and hangs on dev, without this change.

🤖 Generated with Claude Code

…osed it

Deepgram closes an idle stream (NET-0001) after ~10 s without audio. When
the session then ended, end_stream sent CloseStream on the dead socket,
raised ConnectionClosedError, and never removed the stream entry. It now
unregisters the stream first and logs one warning for an already-closed
socket instead of raising.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thestumonkey
thestumonkey merged commit 6cce121 into dev Nov 9, 2026
3 of 7 checks passed
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.

1 participant