From 256c4c1b4a08869f0fa51fa913253bcc4e8d6a42 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 18 May 2026 21:56:59 -0700 Subject: [PATCH] fix(gateway): scope audio_file_paths outside media_urls guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The audio-file-paths handling block at line 7334 references the variable unconditionally, but #24879 initialized it inside the 'if event.media_urls' block — so events without media_urls hit UnboundLocalError. Found via test_run_agent_queued_message_does_not_treat_commentary_as_final after PR #28478 landed. --- gateway/run.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gateway/run.py b/gateway/run.py index 4ac739a7458..5ce3fd5521c 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -7254,10 +7254,13 @@ class GatewayRunner: if getattr(event, "channel_context", None): message_text = f"{event.channel_context}\n\n[New message]\n{message_text}" + # Declare at outer scope so the audio-file-paths handling block below + # remains safe when ``event.media_urls`` is empty (no inner block runs). + audio_file_paths: list[str] = [] + if event.media_urls: image_paths = [] audio_paths = [] - audio_file_paths: list[str] = [] # audio file attachments — not for STT for i, path in enumerate(event.media_urls): mtype = event.media_types[i] if i < len(event.media_types) else "" if mtype.startswith("image/") or event.message_type == MessageType.PHOTO: