Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: revalidate Qwen snapshot digests before reporting readiness (#8857)

[._.]/ Adam Eivy67945f6fa08b
diff --git a/docs/features/voice.md b/docs/features/voice.md
index 26634059e4..4e6033b5e0 100644
--- a/docs/features/voice.md
+++ b/docs/features/voice.md
@@ -25,8 +25,8 @@ or failed verification returns an error; it never marks the model downloaded.
Earlier versions produced test tones, placeholder checkpoints and download
metadata; those artifacts are not evidence of model readiness. Runtime probes
still report inference unavailable. Model download readiness is separate: it
-requires a verified snapshot marker and all required files at their verified
-sizes; old metadata-only model folders remain unavailable. Use Piper for working local speech until #8857 delivers a real
+requires a verified snapshot marker and fresh size/digest verification of all
+required files; old metadata-only model folders remain unavailable. Use Piper for working local speech until #8857 delivers a real
adapter and an intelligibility smoke run. No model download runs automatically.
Interactive profile benchmarks measure elapsed time until the buffered WAV is
diff --git a/scripts/qwen3_tts_runner.py b/scripts/qwen3_tts_runner.py
index 43bd30b906..4f2bb079d8 100755
--- a/scripts/qwen3_tts_runner.py
+++ b/scripts/qwen3_tts_runner.py
@@ -20,6 +20,8 @@ import sys
from pathlib import Path
+HUB_ENDPOINT = "https://huggingface.co"
+
SUPPORTED_MODELS = (
"Qwen/Qwen3-TTS-12Hz-1.7B-VoiceDesign",
"Qwen/Qwen3-TTS-12Hz-1.7B-Base",
@@ -35,6 +37,23 @@ REQUIRED_FILES = (
)
+def verify_file(path: Path, metadata: dict) -> None:
+ """Verify bytes again on probe, including same-size local corruption."""
+ size, algorithm, digest = metadata["size"], metadata["algorithm"], metadata["digest"]
+ if not isinstance(size, int) or size <= 0 or path.stat().st_size != size:
+ raise ValueError(f"Incomplete model file: {path.name}")
+ if algorithm not in ("sha1", "sha256") or not isinstance(digest, str):
+ raise ValueError("Invalid model verification metadata")
+ checksum = hashlib.new(algorithm)
+ if algorithm == "sha1":
+ checksum.update(f"blob {size}\0".encode())
+ with path.open("rb") as source:
+ for chunk in iter(lambda: source.read(1024 * 1024), b""):
+ checksum.update(chunk)
+ if checksum.hexdigest() != digest:
+ raise ValueError(f"Model file checksum mismatch: {path.name}")
+
+
def installed_snapshot(model_dir: Path, model_id: str) -> Path | None:
"""Read only a completely verified revision; never perform network access."""
try:
@@ -43,13 +62,8 @@ def installed_snapshot(model_dir: Path, model_id: str) -> Path | None:
if manifest["model_id"] != model_id or not re.fullmatch(r"[0-9a-f]{40}", revision):
return None
snapshot = model_dir / revision
- sizes = manifest["files"]
for filename in REQUIRED_FILES:
- expected = sizes[filename]
- if not isinstance(expected, int) or expected <= 0:
- return None
- if (snapshot / filename).stat().st_size != expected:
- return None
+ verify_file(snapshot / filename, manifest["files"][filename])
return snapshot
except (OSError, ValueError, KeyError, TypeError):
return None
@@ -66,7 +80,7 @@ def download_model(model_id: str, models_dir: Path) -> dict:
raise ValueError("Unsupported Qwen3-TTS model")
from huggingface_hub import HfApi, hf_hub_download
- info = HfApi().model_info(model_id, files_metadata=True)
+ info = HfApi(endpoint=HUB_ENDPOINT).model_info(model_id, files_metadata=True)
revision = info.sha
if not isinstance(revision, str) or not re.fullmatch(r"[0-9a-f]{40}", revision):
raise ValueError("Model repository did not return an immutable revision")
@@ -75,7 +89,7 @@ def download_model(model_id: str, models_dir: Path) -> dict:
raise ValueError("Model repository is missing required Qwen3-TTS files")
model_dir = models_dir / model_id.replace("/", "--")
snapshot = model_dir / revision
- sizes = {}
+ verified_files = {}
for filename in REQUIRED_FILES:
entry = files[filename]
if not isinstance(entry.size, int) or entry.size <= 0:
@@ -86,19 +100,11 @@ def download_model(model_id: str, models_dir: Path) -> dict:
if not isinstance(digest, str) or not re.fullmatch(r"[0-9a-f]{64}" if lfs else r"[0-9a-f]{40}", digest):
raise ValueError(f"Missing file digest: {filename}")
# The explicit download operation is the only path allowed to fetch.
- hf_hub_download(repo_id=model_id, filename=filename, revision=revision, local_dir=snapshot)
- target = snapshot / filename
- if target.stat().st_size != entry.size:
- raise ValueError(f"Incomplete model file: {filename}")
- checksum = hashlib.new(algorithm)
- if not lfs:
- checksum.update(f"blob {entry.size}\0".encode())
- with target.open("rb") as source:
- for chunk in iter(lambda: source.read(1024 * 1024), b""):
- checksum.update(chunk)
- if checksum.hexdigest() != digest:
- raise ValueError(f"Model file checksum mismatch: {filename}")
- sizes[filename] = entry.size
+ hf_hub_download(repo_id=model_id, filename=filename, revision=revision,
+ local_dir=snapshot, endpoint=HUB_ENDPOINT)
+ metadata = {"size": entry.size, "algorithm": algorithm, "digest": digest}
+ verify_file(snapshot / filename, metadata)
+ verified_files[filename] = metadata
marker = model_dir / "verified.json"
# Unique temporary markers also make separate explicit CLI downloads safe.
@@ -106,7 +112,7 @@ def download_model(model_id: str, models_dir: Path) -> dict:
descriptor, temporary = tempfile.mkstemp(prefix=".verified-", dir=model_dir)
try:
with os.fdopen(descriptor, "w") as output:
- json.dump({"model_id": model_id, "revision": revision, "files": sizes}, output)
+ json.dump({"model_id": model_id, "revision": revision, "files": verified_files}, output)
output.flush()
os.fsync(output.fileno())
os.replace(temporary, marker)
diff --git a/scripts/qwen3_tts_runner.test.js b/scripts/qwen3_tts_runner.test.js
index 687237ccad..dee63c0013 100644
--- a/scripts/qwen3_tts_runner.test.js
+++ b/scripts/qwen3_tts_runner.test.js
@@ -29,10 +29,11 @@ info = types.SimpleNamespace(sha=revision, siblings=entries)
calls = []
corrupt = None
hub = types.ModuleType("huggingface_hub")
-hub.HfApi = lambda: types.SimpleNamespace(model_info=lambda *args, **kwargs: info)
+hub.HfApi = lambda **kwargs: types.SimpleNamespace(model_info=lambda *args, **kwargs: info)
def download(**kwargs):
calls.append(kwargs)
assert kwargs["revision"] == revision
+ assert kwargs["endpoint"] == "https://huggingface.co"
path = kwargs["local_dir"] / kwargs["filename"]
path.parent.mkdir(parents=True, exist_ok=True)
data = payloads[kwargs["filename"]]
@@ -58,6 +59,8 @@ with tempfile.TemporaryDirectory() as temp:
assert len(calls) == len(runner.REQUIRED_FILES)
# A metadata-only directory or incomplete codec must never report installed.
codec = snapshot / "speech_tokenizer/model.safetensors"
+ codec.write_bytes(b"x" * codec.stat().st_size)
+ assert runner.installed_snapshot(model_dir, model_id) is None
codec.write_bytes(b"truncated")
assert runner.installed_snapshot(model_dir, model_id) is None
codec.unlink()
diff --git a/server/services/voice/qwen3TtsRuntime.js b/server/services/voice/qwen3TtsRuntime.js
index 7e397ad1b1..a7d13005bf 100644
--- a/server/services/voice/qwen3TtsRuntime.js
+++ b/server/services/voice/qwen3TtsRuntime.js
@@ -92,7 +92,7 @@ export async function getQwen3RuntimeStatus() {
try {
const probeArgs = [QWEN3_TTS_RUNNER_SCRIPT, '--probe', '--models-dir', QWEN3_TTS_MODELS_DIR];
- const { stdout } = await runRuntime(python, probeArgs);
+ const { stdout } = await runRuntime(python, probeArgs, 120000);
const data = JSON.parse(stdout.trim());
const modelsState = {};