From 1fd08f50ee06a0ede0a75a44f41a467a8a85ea77 Mon Sep 17 00:00:00 2001 From: jiawenlai1109 <270987117+jiawenlai1109@users.noreply.github.com> Date: Tue, 22 Sep 2026 17:55:01 +0800 Subject: [PATCH] fix(audio_generator): clean up temp file when gTTS save() fails generate_audio_cross_platform() created the temp MP3 via tts.save() one statement *before* the try/finally that was supposed to remove it, so any exception raised by the save itself escaped the cleanup and left temp_audio_.mp3 in the current working directory. gTTS.save() performs an outbound HTTP request, which is exactly the path that fails offline or behind egress restrictions, and .gitignore does not cover the temp_audio_* pattern - so every such run litters the working tree. Move the save inside the existing try. Success-path behaviour is unchanged, and this now matches how generate_audio_mac_wav() in the same file already guards its two temp paths. Verified on Ubuntu 22.04 / Python 3.14.7, same offline-failing test before and after: leaked temp_audio_*.mp3 count went 1 -> 0, test result unchanged (1 failed, gTTSError: Failed to connect). black --check passes; rest of the module is 1 passed, 1 skipped, 1 pre-existing offline failure. --- agentic_security/probe_data/audio_generator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agentic_security/probe_data/audio_generator.py b/agentic_security/probe_data/audio_generator.py index 50babe5..341fe0e 100644 --- a/agentic_security/probe_data/audio_generator.py +++ b/agentic_security/probe_data/audio_generator.py @@ -88,9 +88,8 @@ def generate_audio_cross_platform(prompt: str) -> bytes: tts = gTTS(text=prompt, lang="en") temp_mp3_path = f"temp_audio_{uuid.uuid4().hex}.mp3" - tts.save(temp_mp3_path) - try: + tts.save(temp_mp3_path) with open(temp_mp3_path, "rb") as f: audio_bytes = f.read() finally: