From a9c862f4890009affcab6330ccae62ace0f405e9 Mon Sep 17 00:00:00 2001 From: Carolina <79524656+carochacs@users.noreply.github.com> Date: Sun, 2 Aug 2026 14:27:28 -0600 Subject: [PATCH 1/3] Fix: status check reported ready before models finished loading (#4) ls_status() treated any HTTP 200 from /health as "alignment server ready", but the demucs-server responds 200 with status:"ok" as soon as the process is up -- well before whisperx (needed for /align's VAD-anchored windows) finishes downloading/loading. During that window /health's own `warmup` block already reports e.g. `whisperx: "downloading"`. This showed a green "Alignment server ready" notice while a request would still hit the server mid-warmup, then fail with a confusing "Cannot connect to alignment server" the moment the user actually clicked Align -- despite the ready notice being visible seconds earlier. ls_status() now inspects /health's `warmup.whisperx` field and only reports available:true once it's "ready", surfacing an accurate "still loading" reason otherwise. Per-language aligners load lazily on demand and are not gated on here. Co-authored-by: Claude Haiku 4.5 --- routes.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/routes.py b/routes.py index f27a3c4..de39999 100644 --- a/routes.py +++ b/routes.py @@ -96,16 +96,41 @@ def setup(app: FastAPI, context: dict): @app.get("/api/plugins/lyrics_sync/status") def ls_status(): - """Check if alignment server is reachable.""" + """Check if the alignment server is reachable AND actually ready to + align — not just that /health returns 200. + + The demucs-server's /health responds 200 with `status: "ok"` as soon + as the process is up, well before its models finish loading — during + that window its `warmup` block reports fields like `whisperx: + "downloading"`. Treating any 200 as "ready" (the previous behavior) + showed a green "Alignment server ready" notice while a request would + still hit the server mid-warmup, surfacing as a confusing + "Cannot connect to alignment server" once the user actually clicked + Align. `/align` needs whisperx (transcription, used for VAD-anchored + alignment windows — see the demucs-server's own /align docs) loaded + first; per-language aligners load lazily on demand and are not + gated on here. + """ url = _get_demucs_server_url() if not url: return {"available": False, "reason": "No demucs server configured"} try: import requests resp = requests.get(f"{url}/health", timeout=5) - if resp.status_code == 200: - return {"available": True, "server_url": url} - return {"available": False, "reason": f"Server returned {resp.status_code}"} + if resp.status_code != 200: + return {"available": False, "reason": f"Server returned {resp.status_code}"} + body = resp.json() + warmup = body.get("warmup") or {} + whisperx_state = warmup.get("whisperx") + if whisperx_state != "ready": + return { + "available": False, + "reason": ( + f"Alignment model still loading ({whisperx_state or 'unknown'}) " + "— try again in a moment." + ), + } + return {"available": True, "server_url": url} except Exception as e: return {"available": False, "reason": str(e)} From e7192a3a3f7ad81cac1c6969f98418b490bc8f84 Mon Sep 17 00:00:00 2001 From: Carolina <79524656+carochacs@users.noreply.github.com> Date: Sun, 2 Aug 2026 19:45:00 -0600 Subject: [PATCH 2/3] Harden Demucs URL and readiness checks Restrict configured Demucs server URLs to local/private HTTP(S) targets, rejecting credentials and non-local hosts. Health and align requests now disable redirects, and availability messaging better distinguishes known WhisperX warmup states from unknown readiness failures. README requirements were updated to clarify that the plugin only treats the server as available when `/health` is 200 and `warmup.whisperx` is exactly `"ready"`. --- README.md | 8 +++++++- routes.py | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bdcb129..5a3eaf9 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,16 @@ Because sloppak songs already have an isolated vocals track from Demucs separati ## Requirements -- A running [Slopsmith Demucs Server](https://github.com/byrongamatos/slopsmith-demucs-server) with the `/align` endpoint (v2+) +- A running [Slopsmith Demucs Server](https://github.com/byrongamatos/slopsmith-demucs-server) v2 or later with the `/align` endpoint and `/health` readiness data - The demucs server URL must be configured in Slopsmith settings - Sloppak songs with split stems (use the Sloppak Converter plugin with Demucs splitting enabled) +The alignment server is considered available only when `/health` returns HTTP 200 +and `warmup.whisperx` is exactly `"ready"`. Demucs Server v2 and later expose +this `warmup.whisperx` field; the server can return 200 while WhisperX is still +downloading or loading, so the plugin reports it as unavailable until warmup is +complete. + ## Install ```bash diff --git a/routes.py b/routes.py index de39999..852c3c5 100644 --- a/routes.py +++ b/routes.py @@ -1,8 +1,10 @@ """Lyrics Sync plugin — generate time-synced LRC from plain text lyrics + vocals stem.""" import json +import ipaddress import os from pathlib import Path +from urllib.parse import urlparse from fastapi import FastAPI from fastapi.responses import JSONResponse, Response @@ -13,6 +15,25 @@ SLOPPAK_CACHE_DIR = None +def _is_approved_demucs_url(url: object) -> bool: + """Allow only local/private HTTP(S) Demucs server destinations.""" + if not isinstance(url, str): + return False + parsed = urlparse(url) + if parsed.scheme not in {"http", "https"} or parsed.username or parsed.password: + return False + hostname = parsed.hostname + if not hostname or parsed.query or parsed.fragment: + return False + if hostname.lower() in {"localhost", "host.docker.internal"}: + return True + try: + address = ipaddress.ip_address(hostname) + except ValueError: + return False + return address.is_loopback or address.is_private or address.is_link_local + + def _get_demucs_server_url() -> str | None: """Get the configured demucs server URL from config.json.""" config_file = _config_dir / "config.json" @@ -20,7 +41,7 @@ def _get_demucs_server_url() -> str | None: try: cfg = json.loads(config_file.read_text()) url = cfg.get("demucs_server_url", "") - if url: + if _is_approved_demucs_url(url): return url.rstrip("/") except Exception: pass @@ -116,19 +137,23 @@ def ls_status(): return {"available": False, "reason": "No demucs server configured"} try: import requests - resp = requests.get(f"{url}/health", timeout=5) + resp = requests.get(f"{url}/health", timeout=5, allow_redirects=False) if resp.status_code != 200: return {"available": False, "reason": f"Server returned {resp.status_code}"} body = resp.json() warmup = body.get("warmup") or {} whisperx_state = warmup.get("whisperx") if whisperx_state != "ready": + if whisperx_state in {"downloading", "loading", "starting", "warming_up"}: + reason = ( + f"Alignment model still loading ({whisperx_state}) " + "— try again in a moment." + ) + else: + reason = f"Alignment model is not ready ({whisperx_state or 'unknown'})" return { "available": False, - "reason": ( - f"Alignment model still loading ({whisperx_state or 'unknown'}) " - "— try again in a moment." - ), + "reason": reason, } return {"available": True, "server_url": url} except Exception as e: @@ -177,6 +202,7 @@ def ls_align(data: dict): "granularity": granularity, }, timeout=300, + allow_redirects=False, ) if resp.status_code != 200: From af47801c36ad7e9f0d670373885515f0cec700e9 Mon Sep 17 00:00:00 2001 From: Carolina <79524656+carochacs@users.noreply.github.com> Date: Sun, 2 Aug 2026 20:09:54 -0600 Subject: [PATCH 3/3] Restrict demucs URL approval to localhost only Removes 'host.docker.internal' from the list of approved hostnames for demucs URLs, limiting approval to 'localhost' only. --- routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes.py b/routes.py index 852c3c5..edd5471 100644 --- a/routes.py +++ b/routes.py @@ -25,7 +25,7 @@ def _is_approved_demucs_url(url: object) -> bool: hostname = parsed.hostname if not hostname or parsed.query or parsed.fragment: return False - if hostname.lower() in {"localhost", "host.docker.internal"}: + if hostname.lower() == "localhost": return True try: address = ipaddress.ip_address(hostname)