fix: make gateway watcher startup non-blocking with timeout (#4297)

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 <minidarkmimi@users.noreply.github.com>
This commit is contained in:
nesquena-hermes
2026-06-16 16:44:14 +00:00
parent 232963791f
commit fb78d396c8
+12 -1
View File
@@ -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)