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: reuse unchanged Qwen verification and surface download errors (#8857)

[._.]/ Adam Eivyb4f3ac99c659
diff --git a/docs/features/voice.md b/docs/features/voice.md
index 4e6033b5e0..24e8ad1cd5 100644
--- a/docs/features/voice.md
+++ b/docs/features/voice.md
@@ -25,8 +25,9 @@ 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 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
+requires a verified snapshot marker and all required files. Unchanged verified
+files use their size, change timestamps, and filesystem identity; changed files
+are rehashed before they can report ready; 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 4f2bb079d8..b9f66ea658 100755
--- a/scripts/qwen3_tts_runner.py
+++ b/scripts/qwen3_tts_runner.py
@@ -37,8 +37,14 @@ REQUIRED_FILES = (
)
-def verify_file(path: Path, metadata: dict) -> None:
- """Verify bytes again on probe, including same-size local corruption."""
+def file_fingerprint(path: Path) -> list[int]:
+ stat = path.stat()
+ return [stat.st_size, stat.st_mtime_ns, stat.st_ctime_ns, stat.st_ino, stat.st_dev]
+
+
+def verify_file(path: Path, metadata: dict) -> list[int]:
+ """Verify bytes and reject files changed while hashing."""
+ before = file_fingerprint(path)
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}")
@@ -52,6 +58,9 @@ def verify_file(path: Path, metadata: dict) -> None:
checksum.update(chunk)
if checksum.hexdigest() != digest:
raise ValueError(f"Model file checksum mismatch: {path.name}")
+ if before != file_fingerprint(path):
+ raise ValueError(f"Model file changed during verification: {path.name}")
+ return before
def installed_snapshot(model_dir: Path, model_id: str) -> Path | None:
@@ -63,7 +72,13 @@ def installed_snapshot(model_dir: Path, model_id: str) -> Path | None:
return None
snapshot = model_dir / revision
for filename in REQUIRED_FILES:
- verify_file(snapshot / filename, manifest["files"][filename])
+ path = snapshot / filename
+ metadata = manifest["files"][filename]
+ # The verified bytes stay valid while their filesystem identity and
+ # change timestamps match. Rehash changed files, including equal-size
+ # replacements, without rereading multi-GB weights on every status.
+ if file_fingerprint(path) != metadata.get("fingerprint"):
+ verify_file(path, metadata)
return snapshot
except (OSError, ValueError, KeyError, TypeError):
return None
@@ -103,7 +118,7 @@ def download_model(model_id: str, models_dir: Path) -> dict:
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)
+ metadata["fingerprint"] = verify_file(snapshot / filename, metadata)
verified_files[filename] = metadata
marker = model_dir / "verified.json"
@@ -218,7 +233,8 @@ def main() -> int:
print(json.dumps(download_model(args.model_id, Path(args.models_dir))))
return 0
except Exception as error:
- print(json.dumps({"ok": False, "code": "QWEN3_DOWNLOAD_FAILED", "error": str(error)}), file=sys.stderr)
+ code = "QWEN3_DOWNLOAD_UNAVAILABLE" if isinstance(error, ImportError) else "QWEN3_DOWNLOAD_FAILED"
+ print(json.dumps({"ok": False, "code": code, "error": str(error)}), file=sys.stderr)
return 1
if args.probe:
diff --git a/scripts/qwen3_tts_runner.test.js b/scripts/qwen3_tts_runner.test.js
index dee63c0013..09d6d7f5dd 100644
--- a/scripts/qwen3_tts_runner.test.js
+++ b/scripts/qwen3_tts_runner.test.js
@@ -9,7 +9,7 @@ const script = fileURLToPath(new URL('./qwen3_tts_runner.py', import.meta.url));
// Exercise the production download/probe boundary with a tool-free fake Hub;
// no model, provider, hardware, credentials, or real user directories are used.
const fixture = String.raw`
-import hashlib, importlib.util, json, sys, tempfile, types
+import hashlib, importlib.util, json, os, sys, tempfile, types
from pathlib import Path
spec = importlib.util.spec_from_file_location("qwen_runner", sys.argv[1])
runner = importlib.util.module_from_spec(spec)
@@ -56,10 +56,17 @@ with tempfile.TemporaryDirectory() as temp:
result = runner.download_model(model_id, root)
snapshot = runner.installed_snapshot(model_dir, model_id)
assert snapshot == Path(result["path"])
+ # Repeated status checks do not rehash unchanged multi-GB weights.
+ verifier = runner.verify_file
+ runner.verify_file = lambda *args: (_ for _ in ()).throw(AssertionError("rehashed unchanged file"))
+ assert runner.installed_snapshot(model_dir, model_id) == snapshot
+ runner.verify_file = verifier
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)
+ original = codec.stat()
+ codec.write_bytes(b"x" * original.st_size)
+ os.utime(codec, ns=(original.st_atime_ns, original.st_mtime_ns))
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
diff --git a/server/services/voice/qwen3TtsRuntime.js b/server/services/voice/qwen3TtsRuntime.js
index a7d13005bf..4bf7b5683f 100644
--- a/server/services/voice/qwen3TtsRuntime.js
+++ b/server/services/voice/qwen3TtsRuntime.js
@@ -143,8 +143,17 @@ function runRuntime(pythonPath, args, timeout = 10000) {
child.stdout.on('data', (d) => { stdout = (stdout + d.toString()).slice(-65536); });
child.stderr.on('data', (d) => { stderr = (stderr + d.toString()).slice(-8192); });
child.on('close', (code) => {
- if (code === 0) resolve({ stdout, stderr });
- else reject(new Error(`Qwen3 runtime failed (code ${code}): ${stderr || stdout}`));
+ if (code === 0) return resolve({ stdout, stderr });
+ // Hub progress may precede the runner's final structured error line.
+ let failure = null;
+ try { failure = JSON.parse(stderr.trim().split(/\r?\n/).at(-1)); } catch { /* Non-JSON process failure. */ }
+ if (['QWEN3_DOWNLOAD_UNAVAILABLE', 'QWEN3_DOWNLOAD_FAILED'].includes(failure?.code)) {
+ return reject(new ServerError(failure.error || 'Qwen3 model download failed', {
+ status: failure.code === 'QWEN3_DOWNLOAD_UNAVAILABLE' ? 503 : 502,
+ code: failure.code,
+ }));
+ }
+ reject(new Error(`Qwen3 runtime failed (code ${code}): ${stderr || stdout}`));
});
child.on('error', reject);
});
diff --git a/server/services/voice/qwen3TtsRuntime.test.js b/server/services/voice/qwen3TtsRuntime.test.js
index dc12817321..6a17adbc86 100644
--- a/server/services/voice/qwen3TtsRuntime.test.js
+++ b/server/services/voice/qwen3TtsRuntime.test.js
@@ -31,7 +31,7 @@ describe('qwen3TtsRuntime', () => {
child.stdout = new EventEmitter();
child.stderr = new EventEmitter();
queueMicrotask(() => {
- child.stdout.emit('data', JSON.stringify(data));
+ (code === 0 ? child.stdout : child.stderr).emit('data', JSON.stringify(data));
child.emit('close', code);
});
return child;
@@ -59,8 +59,10 @@ describe('qwen3TtsRuntime', () => {
runnerResponse({ ok: true, modelId });
await expect(downloadQwen3Model(modelId)).rejects.toMatchObject({ code: 'QWEN3_DOWNLOAD_INVALID_RESULT' });
- runnerResponse({ error: 'checksum mismatch' }, 1);
- await expect(downloadQwen3Model(modelId)).rejects.toThrow(/checksum mismatch/);
+ runnerResponse({ code: 'QWEN3_DOWNLOAD_FAILED', error: 'checksum mismatch' }, 1);
+ await expect(downloadQwen3Model(modelId)).rejects.toMatchObject({ status: 502, code: 'QWEN3_DOWNLOAD_FAILED' });
+ runnerResponse({ code: 'QWEN3_DOWNLOAD_UNAVAILABLE', error: 'No module named huggingface_hub' }, 1);
+ await expect(downloadQwen3Model(modelId)).rejects.toMatchObject({ status: 503, code: 'QWEN3_DOWNLOAD_UNAVAILABLE' });
await expect(downloadQwen3Model('unknown/invalid-model')).rejects.toMatchObject({ code: 'UNKNOWN_QWEN3_MODEL' });
});
});