From 3eec5e54b1bd969eeb504444898ddc5963502c99 Mon Sep 17 00:00:00 2001 From: JayMishra-github Date: Mon, 16 Feb 2026 10:13:29 -0800 Subject: [PATCH] fix(voice-call): auto-end call when media stream disconnects When a Twilio media stream disconnects (e.g., caller hangs up or network drops), the call object was left in an active state indefinitely. This caused "stuck calls" that consumed resources and blocked new calls. Now calls are automatically ended when their media stream closes, matching the expected lifecycle behavior. Co-Authored-By: Claude Opus 4.6 --- extensions/voice-call/src/webhook.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extensions/voice-call/src/webhook.ts b/extensions/voice-call/src/webhook.ts index 41c8b3e2254..b7ccaf2f6ea 100644 --- a/extensions/voice-call/src/webhook.ts +++ b/extensions/voice-call/src/webhook.ts @@ -181,6 +181,13 @@ export class VoiceCallWebhookServer { }, onDisconnect: (callId) => { console.log(`[voice-call] Media stream disconnected: ${callId}`); + // Auto-end call when media stream disconnects to prevent stuck calls. + // Without this, calls can remain active indefinitely after the stream closes. + const disconnectedCall = this.manager.getCallByProviderCallId(callId); + if (disconnectedCall) { + console.log(`[voice-call] Auto-ending call ${disconnectedCall.callId} on stream disconnect`); + void this.manager.endCall(disconnectedCall.callId).catch(() => {}); + } if (this.provider.name === "twilio") { (this.provider as TwilioProvider).unregisterCallStream(callId); }