fix(deepgram): prevent TypeError in STTv2 #sendTask on stream teardown - #1111
Merged
Conversation
I've been experiencing this error when tearing down a Deepgram STTv2 stream: > TypeError: Cannot read properties of undefined (reading 'data') > at #sendTask (file:///app/node_modules/.pnpm/@livekit+agents-plugin-deepgram@1.0.48_@livekit+agents@1.0.48_patch_hash=16f67c4454ddfc_5806c0752ada5e043f9df09228747190/node_modules/@livekit/agents-plugin-deepgram/dist/stt_v2.js:194:50) > at async Promise.all (index 0) > at async SpeechStreamv2.run (file:///app/node_modules/.pnpm/@livekit+agents-plugin-deepgram@1.0.48_@livekit+agents@1.0.48_patch_hash=16f67c4454ddfc_5806c0752ada5e043f9df09228747190/node_modules/@livekit/agents-plugin-deepgram/dist/stt_v2.js:148:24) > at async SpeechStreamv2.mainTask (file:///app/node_modules/.pnpm/@livekit+agents@1.0.48_patch_hash=16f67c4454ddfcf1a293acc3d23e6f58afb9c1038ef83d38702c1_0a10b516bd5ee098b72ec3483ed7545b/node_modules/@livekit/agents/dist/stt/stt.js:74:16) It looks like the issue is that the sendTask loop checks for `!('value' in result)` to detect when the iterator is finished. But `iterator.next()` returns `{ done: true, value: undefined }` in that case, so that check evaluates to `false`, and execution falls through to the `else if ('value' in result)` branch, which tries to read `result.value.data.buffer` on the undefined `result.value`. This fixes the issue by checking `result.value === undefined` instead.
🦋 Changeset detectedLatest commit: 9f5671d The changes in this PR will be included in the next version bump. This PR includes changesets to release 21 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
toubatbrian
approved these changes
Mar 9, 2026
This was referenced Mar 9, 2026
Merged
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.
Description
I've been experiencing this error when tearing down a Deepgram STTv2 stream:
It looks like the issue is that the sendTask loop checks for
!('value' in result)to detect when the iterator is finished.But
iterator.next()returns{ done: true, value: undefined }in that case, so that check evaluates tofalse, and execution falls through to theelse if ('value' in result)branch, which tries to readresult.value.data.bufferon the undefinedresult.value.This fixes the issue by checking
result.value === undefinedinstead.Changes Made
!('value' in result)withresult.value === undefinedPre-Review Checklist
Testing
restaurant_agent.tsandrealtime_agent.tswork properly (for major changes)I also tested by patching @livekit/agents-plugin-deepgram in my application with this change and then confirming that the plugin continues to work correctly and no longer reports the error.
Additional Notes
None.
Note to reviewers: Please ensure the pre-review checklist is completed before starting your review.