From 0787d157b1fafa9cf2b82092bd6786bfc2227460 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Tue, 10 Feb 2026 21:47:09 -0800 Subject: [PATCH 1/2] fix(deepgram): prevent TypeError in STTv2 #sendTask on stream teardown 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. --- plugins/deepgram/src/stt_v2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/deepgram/src/stt_v2.ts b/plugins/deepgram/src/stt_v2.ts index 3701576b9..b4cc4145d 100644 --- a/plugins/deepgram/src/stt_v2.ts +++ b/plugins/deepgram/src/stt_v2.ts @@ -296,7 +296,7 @@ class SpeechStreamv2 extends stt.SpeechStream { } // If we broke above, we don't process data. If not, 'result' is IteratorResult - if (hasEnded && !('value' in result)) { + if (hasEnded && result.value === undefined) { // Process flush below } else if ('value' in result) { const data = result.value; From 9f5671d7c33391d817bbfc5e16ded71d40187e5b Mon Sep 17 00:00:00 2001 From: Brian Yin Date: Mon, 9 Mar 2026 08:54:23 -0700 Subject: [PATCH 2/2] Create wise-cherries-collect.md --- .changeset/wise-cherries-collect.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wise-cherries-collect.md diff --git a/.changeset/wise-cherries-collect.md b/.changeset/wise-cherries-collect.md new file mode 100644 index 000000000..0ccaf9705 --- /dev/null +++ b/.changeset/wise-cherries-collect.md @@ -0,0 +1,5 @@ +--- +"@livekit/agents-plugin-deepgram": patch +--- + +fix(deepgram): prevent TypeError in STTv2 #sendTask on stream teardown