From 406eb719c33c63b4b4c29f90f7391ea2e863bc0f Mon Sep 17 00:00:00 2001 From: devatnull Date: Sun, 28 Jun 2026 16:19:25 +0300 Subject: [PATCH] fix: gate interrupt STT transcript echoes --- gateway/run.py | 12 ++++++------ .../gateway/test_stt_transcript_echo_config.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index e94d46971bf..9381f0eab0f 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -18613,7 +18613,7 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew # real transcript instead of an empty string # (or file-path placeholder). Matches the UX # of fresh voice messages including the - # 🎙️ echo back to the user. + # optional 🎙️ echo back to the user. _media_urls = getattr(_peek_event, "media_urls", None) or [] _media_types = getattr(_peek_event, "media_types", None) or [] _audio_paths = [] @@ -18631,7 +18631,7 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew pending_text, _audio_paths, ) pending_text = _enriched - if _transcripts: + if _transcripts and self._should_echo_stt_transcripts(): _echo_meta = {"thread_id": source.thread_id} if source.thread_id else None for _tx in _transcripts: try: @@ -19030,9 +19030,9 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew # Transcribe audio media on the dequeued event BEFORE it is # handed back as the next user turn, so queued/interrupting # voice messages drain with the real transcript instead of - # a file-path placeholder. Echo each transcript back to the - # user (same 🎙️ format as fresh voice messages) so voice - # interrupts feel identical to text interrupts. + # a file-path placeholder. When configured, echo each + # transcript back to the user in the same 🎙️ format as + # fresh voice messages. _pending_text = pending_event.text or "" _media_urls = getattr(pending_event, "media_urls", None) or [] _media_types = getattr(pending_event, "media_types", None) or [] @@ -19051,7 +19051,7 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew _pending_text, _audio_paths, ) pending = _enriched or None - if _transcripts: + if _transcripts and self._should_echo_stt_transcripts(): _echo_meta = {"thread_id": source.thread_id} if source.thread_id else None for _tx in _transcripts: try: diff --git a/tests/gateway/test_stt_transcript_echo_config.py b/tests/gateway/test_stt_transcript_echo_config.py index b65fcb2d4c2..52d5c26ebc6 100644 --- a/tests/gateway/test_stt_transcript_echo_config.py +++ b/tests/gateway/test_stt_transcript_echo_config.py @@ -1,3 +1,4 @@ +from pathlib import Path from types import SimpleNamespace from gateway.config import GatewayConfig @@ -39,3 +40,19 @@ def test_gateway_runner_uses_stt_echo_transcripts_flag(): runner.config = SimpleNamespace() assert runner._should_echo_stt_transcripts() is True + + +def test_all_gateway_transcript_echo_sends_are_gated(): + source = Path(__file__).resolve().parents[2] / "gateway" / "run.py" + lines = source.read_text().splitlines() + + echo_send_lines = [ + index + for index, line in enumerate(lines) + if "f'🎙️" in line or 'f"🎙️' in line + ] + + assert echo_send_lines + for index in echo_send_lines: + context = "\n".join(lines[max(0, index - 12): index + 1]) + assert "_should_echo_stt_transcripts()" in context