silly-animal-40683
12/11/2025, 9:42 PMgpt-4o-transcribe). I’d like to use a different model via plugin, but there’s no support for streaming via the DeepGram plugin, which leaves OpenAI as the last option.
[15:34:47.134] ERROR (34541): Invalid state: WritableStream is locked
jobID: "AJ_CkBtgNxHGBGk"
err: {
"type": "TypeError",
"message": "Invalid state: WritableStream is locked",
"stack":
TypeError [ERR_INVALID_STATE]: Invalid state: WritableStream is locked
at InternalWritableStream.close (node:internal/webstreams/writablestream:218:9)
at VADStream.endInput ([REDACTED]/node_modules/.pnpm/@livekit+agents@1.0.24_@livekit+rtc-node@0.13.21_zod@4.1.13/node_modules/@livekit/agents/src/vad.ts:240:25)
at forwardInput ([REDACTED]/node_modules/.pnpm/@livekit+agents@1.0.24_@livekit+rtc-node@0.13.21_zod@4.1.13/node_modules/@livekit/agents/src/stt/stream_adapter.ts:61:23)
at async Promise.all (index 0)
"code": "ERR_INVALID_STATE"
}
Why is this occurtall-airline-16756
12/11/2025, 9:42 PMtall-airline-16756
12/11/2025, 9:43 PMgpt-4o-transcribe). That makes the root cause clear and how to fix it.
Why this happens
• The error occurs because the VAD-based input pipeline (the VADStream created by the StreamAdapter) is still active when the agent handoff begins. During teardown the code tries to close a WritableStream that is already locked/in-use, producing the "WritableStream is locked" TypeError.
• This specifically happens with STT models that require VAD and do not support native streaming, because the StreamAdapter bridges non‑streaming STT with the VAD pipeline and is sensitive to the agent lifecycle timing.
What you can do right now
• Upgrade the LiveKit SDK packages to a post-v1.0 stable release where this lifecycle race condition was addressed. Recommended versions:
◦ @livekit/agents: ~1.3.0
◦ @livekit/rtc-node: ~1.3.0
◦ @livekit/agents-plugin-openai: ~1.3.0
• Ensure you fully close/end any STT streams before initiating a handoff. Example pattern:
const sttStream = stt.stream();
// ... feed/process audio ...
await sttStream.end(); // wait for clean closure before starting handoff
• If updating is not possible immediately, add a short delay between ending the current agent activity and starting the next agent to allow streams to drain cleanly.
Longer-term options
• Use a fully streaming STT model (DeepGram Nova-2 or similar) so the pipeline uses streaming end-to-end and avoids the StreamAdapter VAD race.
• If you want, I can walk through your current package.json and show the exact upgrade commands and verify there are no breaking changes to your code.
Would you like help upgrading your packages or checking your stream cleanup logic?
Sources: Agents v0.x migration guide - Node.js | LiveKit Docs | Improving voice AI's turn detection with transformers | Turn detection and interruptions | LiveKit Docssilly-animal-40683
12/11/2025, 9:46 PM@livekit/agents for Node.js is 1.0.7tall-airline-16756
12/11/2025, 9:47 PMsilly-animal-40683
12/11/2025, 9:48 PMtall-airline-16756
12/11/2025, 9:48 PMnpm config get registry
Expected: https://registry.npmjs.org/ If different:
npm config set registry https://registry.npmjs.org/
• pnpm uses npm's registry config by default; to be explicit:
pnpm config get registry
pnpm config set registry https://registry.npmjs.org/
2) Clear lockfiles / cache (optional but helps)
• npm:
rm -rf node_modules package-lock.json
npm cache clean --force
• pnpm:
rm -rf node_modules pnpm-lock.yaml
pnpm store prune
3) Upgrade commands
• npm:
npm install @livekit/agents@^1.0.18 @livekit/rtc-node@^1.0.18 @livekit/agents-plugin-openai@^1.0.18
• pnpm:
pnpm add @livekit/agents@^1.0.18 @livekit/rtc-node@^1.0.18 @livekit/agents-plugin-openai@^1.0.18
4) Verify installed versions
npm ls @livekit/agents @livekit/rtc-node @livekit/agents-plugin-openai
# or
pnpm ls @livekit/agents @livekit/rtc-node @livekit/agents-plugin-openai
5) If your registry still shows only older versions
• Confirm any organization-scoped registry settings in .npmrc (project or global).
• Check private registry mirrors or corporate proxies that may cache older packages.
• As a temporary workaround, install directly from the tarball or Git ref if available (only if provided by LiveKit).
If you want, share the output of npm config get registry and npm ls @livekit/agents and I’ll help verify and adapt the commands for your environment.
Sources: Agents (Node.js) | livekit/livekit_composite | DeepWiki