Skip to content

fix(deepgram): prevent TypeError in STTv2 #sendTask on stream teardown - #1111

Merged
toubatbrian merged 2 commits into
livekit:mainfrom
mykmelez:fix-sttv2-sendtask-crash
Mar 9, 2026
Merged

fix(deepgram): prevent TypeError in STTv2 #sendTask on stream teardown#1111
toubatbrian merged 2 commits into
livekit:mainfrom
mykmelez:fix-sttv2-sendtask-crash

Conversation

@mykmelez

@mykmelez mykmelez commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Description

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.

Changes Made

  • replaced !('value' in result) with result.value === undefined

Pre-Review Checklist

  • Build passes: All builds (lint, typecheck, tests) pass locally
  • AI-generated code reviewed: Removed unnecessary comments and ensured code quality
  • Changes explained: All changes are properly documented and justified above
  • Scope appropriate: All changes relate to the PR title, or explanations provided for why they're included
  • Video demo: A small video demo showing changes works as expected and did not break any existing functionality using Agent Playground (if applicable)

Testing

  • Automated tests added/updated (if applicable)
  • All tests pass
  • Make sure both restaurant_agent.ts and realtime_agent.ts work 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.

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-bot

changeset-bot Bot commented Mar 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f5671d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@livekit/agents-plugin-deepgram Patch
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-xai Patch
@livekit/agents-plugins-test Patch

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

@CLAassistant

CLAassistant commented Mar 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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 potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@toubatbrian
toubatbrian merged commit 8823a90 into livekit:main Mar 9, 2026
5 checks passed
This was referenced Mar 9, 2026
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.

3 participants