fix(voice-call): guard synchronous realtime close

This commit is contained in:
Vincent Koc
2026-07-31 05:26:29 +08:00
parent 645929da80
commit 2269e0cfcf
@@ -752,6 +752,8 @@ export class RealtimeCallHandler {
typeof this.providerConfig.interruptResponseOnInputAudio === "boolean"
? this.providerConfig.interruptResponseOnInputAudio
: undefined;
// Providers may close synchronously before createBridge returns; no consult can exist yet.
let nativeConsultOwner: ActiveRealtimeVoiceBridge | undefined;
const session = harness.createBridge({
provider: this.realtimeProvider,
cfg: this.coreConfig,
@@ -935,7 +937,9 @@ export class RealtimeCallHandler {
this.activeBridgesByCallId.delete(callSid);
this.activeTelephonyClosersByCallId.delete(callId);
this.activeTelephonyClosersByCallId.delete(callSid);
this.cancelNativeConsult(callId, session);
if (nativeConsultOwner) {
this.cancelNativeConsult(callId, nativeConsultOwner);
}
this.clearUserTranscriptState(callId);
harness.finishOutputAudio(reason);
harness.emit({
@@ -961,6 +965,7 @@ export class RealtimeCallHandler {
});
},
});
nativeConsultOwner = session;
providerHandlesInputAudioBargeIn =
session.bridge.handlesInputAudioBargeIn ?? providerHandlesInputAudioBargeIn;
const closeTelephony = (reason: TelephonyCloseReason) => {