From f1c6f64dc865c947f22b6f8bd4c6c419a60ca9f6 Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 18 Jun 2026 18:08:24 -0400 Subject: [PATCH] fix: add 1.5s stabilization check in start_jack to catch flaky JACK startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JACK can briefly become operational (jack_lsp returns ports) during startup then crash when the ALSA device fails. The initial readiness check catches this window and returns True prematurely. Add a 0.5s stabilization window after first success — if JACK drops, continue the wait loop instead of returning. Without this, profile changes succeed in the API but leave JACK in a zombie state: process exists with SHM infrastructure but can't serve clients. --- src/system/audio.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/system/audio.py b/src/system/audio.py index 1548a02..78bab91 100644 --- a/src/system/audio.py +++ b/src/system/audio.py @@ -353,10 +353,18 @@ class AudioSystem: "JACK started: period=%d, nperiods=%d, rate=%d", profile["period"], profile["nperiods"], profile["rate"], ) - # Auto-connect ports if enabled - if self.config.auto_connect: - self.connect_fx_ports() - return True + # Stabilization check — JACK can start briefly then crash + # if the ALSA device is flaky. Wait 1.5s with retries. + time.sleep(0.5) + if _jack_is_operational(): + # Auto-connect ports if enabled + if self.config.auto_connect: + self.connect_fx_ports() + return True + # JACK was running but dropped — don't return yet, + # continue the wait loop for a fresh attempt + logger.warning("JACK appeared briefly then became non-operational") + continue # JACK process exists but not ready yet — keep waiting continue