Error the audio stream when the connection closes before turn.end - #35
Merged
Merged
Conversation
Contributor
Author
|
Quick note on the failing check — it's the docs deploy, not the change itself. The steps that actually check the code — |
Migushthe2nd
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #34.
Problem
oncloseends every in-flight audio stream withpush(null)— the same thing theturn.endhandler does on a normal finish. So when a connection drops mid-synthesis (beforeturn.end), the truncated result looks identical to a complete one:toStream()emits a cleanendwith a partial buffer,toFile()writes a short file, and there's no error to catch and retry on. It shows up most with rotating/residential proxies, whose connections drop mid-stream fairly often.Change
turn.endwas received for each request (aturnEndedflag on the stream record).onclose, streams that finished normally still end cleanly; streams closed beforeturn.endare nowdestroy()ed with anError, so callers can catch it and retry.toFile():.pipe()doesn't forward a source-stream error to the writable, so the truncated case would otherwise hang the write promise forever. Added anaudioStreamerror handler that tears down the file stream and rejects. The happy path is unchanged.Tests
Added a
truncated connectionsuite backed by a local WebSocket server standing in for Edge:turn.end→ the stream must error (partial audio has already been delivered), andturn.endnormally → the stream must end cleanly (guards against false positives).Existing tests are unchanged and still pass.