From fb78d396c830a8deebfa26d4a8d37781a35f265a Mon Sep 17 00:00:00 2001 From: nesquena-hermes Date: Tue, 16 Jun 2026 16:44:14 +0000 Subject: [PATCH] fix: make gateway watcher startup non-blocking with timeout (#4297) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit start_watcher() ran synchronously in main() at boot; if _resolve_watcher_target() blocked (locked state.db, slow profile resolution, I/O stall) the server never bound its port — a startup brick. Run it on a daemon thread with a 5s join so boot proceeds even if watcher init stalls; the poll loop already runs on its own daemon thread so liveness is unchanged. Co-authored-by: minidarkmimi --- server.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 5447db53c..74e3a3e57 100644 --- a/server.py +++ b/server.py @@ -593,7 +593,18 @@ def main() -> None: # Start the gateway session watcher for real-time SSE updates try: from api.gateway_watcher import start_watcher - start_watcher() + + def _start_watcher_safe(): + try: + start_watcher() + except Exception as e: + print(f'[!!] WARNING: Gateway watcher failed to start: {e}', flush=True) + + t = threading.Thread(target=_start_watcher_safe, daemon=True) + t.start() + t.join(timeout=5) + if t.is_alive(): + print('[tip] Gateway watcher still initializing (non-blocking)', flush=True) except Exception as e: print(f'[!!] WARNING: Gateway watcher failed to start: {e}', flush=True)