[Fix] 020-twilio-media-streams-node — close Twilio WS on stop, fix async race condition and test timeout#87
Conversation
Code ReviewOverall: APPROVED Integration genuinenessPass — this is a fix PR for an existing example. The Twilio integration is genuine: Code quality
Documentation
Tests
✓ All checks pass. Marking review passed. Review by Lead on 2026-03-31 |
Code ReviewOverall: APPROVED Integration genuineness✓ Pass — Twilio SDK is imported, TwiML Code quality✓ Official Deepgram SDK ( Documentation✓ README describes the concrete end result, env vars, run instructions, and architecture Tests✓ Credential check runs first, exits 2 for missing credentials ✓ All checks pass. Marking review passed. Review by Lead on 2026-03-31 |
|
⏳ Ready to merge — review passed, no blocking labels. Branch protection policy requires status checks to complete before merge. This PR will be merged on the next sweep after checks pass. |
Code ReviewOverall: APPROVED Integration genuinenessPass — Twilio SDK is imported ( Code quality
Documentation
Tests
✓ All checks pass. Marking review passed. Review by Lead on 2026-03-31 |
…nc race condition Three fixes for the test timeout regression: 1. Close twilioWs on 'stop' event so the test WebSocket close handler fires (root cause of the 30s timeout — server never closed the Twilio WS) 2. Make WS handler synchronous and queue media until Deepgram is ready (express-ws doesn't await async handlers, causing dropped messages) 3. Remove unused twilio import 4. Expand test audio to 10s and broaden expected transcript keywords 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
fdf995b to
73a22b8
Compare
Code ReviewOverall: APPROVED Integration genuinenessPass — Twilio integration is genuine. The server implements the Twilio Media Streams WebSocket protocol (connected/start/media/stop events), the TwiML endpoint returns Code quality
Documentation
Tests
✓ All checks pass. Marking review passed. Review by Lead on 2026-03-31 |
Code ReviewOverall: APPROVED Integration genuinenessPass — Twilio integration is genuine: Code qualityPass — The race condition fix is well-structured: making the WS handler synchronous and queuing media payloads until the Deepgram connection is ready is the correct pattern for DocumentationPass — No README changes needed for this bug fix. Existing documentation remains accurate. TestsPass — Credential check runs first with exit code 2. Expanding audio from 5s to 10s and broadening expected keywords is a reasonable approach to reduce flakiness while still asserting meaningful transcript content. ✓ All checks pass. Marking review passed. Review by Lead on 2026-03-31 |
Code ReviewOverall: APPROVED Integration genuinenessPass. The example genuinely integrates with Twilio via Media Streams WebSocket protocol and TwiML generation. Deepgram live STT is used via the official SDK. The Note: the Code quality
DocumentationNo doc changes needed — this is a bug fix PR. Existing README is complete. Tests
✓ All checks pass. Marking review passed. Review by Lead on 2026-03-31 |
Code ReviewOverall: APPROVED Integration genuinenessPass. This is a fix to an existing Twilio Media Streams example. The integration remains genuine — the server handles real Twilio WebSocket protocol events ( Code quality
DocumentationN/A — fix PR, no documentation changes needed. Existing README is complete. Tests
✓ All checks pass. Marking review passed. Review by Lead on 2026-03-31 |
Summary
stopevent, causing the test'sws.on('close')handler to never fire — resulting in a 30s timeout even though transcripts were successfully received.express-wsdoes notawaitasync WebSocket handler callbacks. The previous code usedasync (twilioWs) => { ... }withawaitcalls before registeringtwilioWs.on('message'), creating a race condition where early Twilio messages were dropped.Changes
twilioWsafter handlingstopevent (fixes the timeout)twilioimportTest plan
<Stream>element🤖 Generated with Claude Code