From 100593496462b41aa2a9bc47f03d1facc82fcdb3 Mon Sep 17 00:00:00 2001 From: Dan Guido Date: Sun, 25 Jan 2026 02:22:55 -0500 Subject: [PATCH] fix(voice-call): use iterative queue processing to prevent heap exhaustion The recursive processQueue() pattern accumulated stack frames, causing JavaScript heap out of memory errors on macOS CI. Convert to while loop for constant stack usage regardless of queue depth. --- extensions/voice-call/src/media-stream.ts | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/extensions/voice-call/src/media-stream.ts b/extensions/voice-call/src/media-stream.ts index b2a7e6d65..cae7279b6 100644 --- a/extensions/voice-call/src/media-stream.ts +++ b/extensions/voice-call/src/media-stream.ts @@ -252,21 +252,24 @@ export class MediaStreamHandler { /** * Process the TTS queue for a stream. + * Uses iterative approach to avoid stack accumulation from recursion. */ private async processQueue(streamSid: string): Promise { - const queue = this.ttsQueues.get(streamSid); - if (!queue || queue.length === 0) { - this.ttsPlaying.set(streamSid, false); - return; - } - this.ttsPlaying.set(streamSid, true); - const playFn = queue.shift()!; - try { - await playFn(); - } finally { - await this.processQueue(streamSid); + while (true) { + const queue = this.ttsQueues.get(streamSid); + if (!queue || queue.length === 0) { + this.ttsPlaying.set(streamSid, false); + return; + } + + const playFn = queue.shift()!; + try { + await playFn(); + } catch (error) { + console.error("[MediaStream] TTS playback error:", error); + } } }