Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(speech): align Whisper cache readiness (#841)

Danny Ward8c149c001153
diff --git a/dodaios/speech/local_install.py b/dodaios/speech/local_install.py
index cd3ce2e4e8..af3d3a052c 100644
--- a/dodaios/speech/local_install.py
+++ b/dodaios/speech/local_install.py
@@ -134,10 +134,7 @@ def _run_install(provider_id: str) -> None:
verify = local_status(provider_id)
if verify is not None and not verify.ready:
ok = False
- message = (
- f"The install finished, but {entry.model_label} is still not "
- "usable. Try again — the download may have been interrupted."
- )
+ message = verify.detail
with run.lock:
run.state = "done" if ok else "error"
diff --git a/dodaios/speech/local_models.py b/dodaios/speech/local_models.py
index 13306e7325..5931e1abea 100644
--- a/dodaios/speech/local_models.py
+++ b/dodaios/speech/local_models.py
@@ -56,6 +56,17 @@ SHERPA_ONNX_MODULE = "sherpa_onnx"
Runtime = Literal["faster-whisper", "sherpa-onnx"]
+# Keep the cache probe aligned with faster-whisper.utils.download_model. Its
+# snapshot filter deliberately excludes repository documentation and metadata.
+_WHISPER_MODEL_ALLOW_PATTERNS = (
+ "config.json",
+ "preprocessor_config.json",
+ "model.bin",
+ "tokenizer.json",
+ "vocabulary.*",
+)
+_WHISPER_MODEL_REQUIRED_FILES = ("config.json", "model.bin", "tokenizer.json")
+
#: Runtime id -> module to probe. A runtime the app does not know about is
#: reported absent rather than guessed at.
_RUNTIME_MODULES: dict[str, str] = {
@@ -236,8 +247,13 @@ def whisper_model_cached(name: str) -> bool:
failure (not cached, engine missing, unfamiliar cache layout) reads as
"not present", which is the fail-closed direction for a readiness claim.
"""
+ return _whisper_model_cache_issue(name) is None
+
+
+def _whisper_model_cache_issue(name: str) -> str | None:
+ """Explain why a faster-whisper checkpoint is not usable from the cache."""
if not name.strip():
- return False
+ return "no model was selected"
try:
directory = Path(name)
if not directory.is_dir():
@@ -260,22 +276,33 @@ def whisper_model_cached(name: str) -> bool:
break
repo_id = aliases.get(name, "")
if not isinstance(repo_id, str) or not repo_id:
- return False
+ return "the model name is not available in the installed faster-whisper runtime"
from huggingface_hub import snapshot_download
- directory = Path(snapshot_download(repo_id, local_files_only=True))
+ directory = Path(
+ snapshot_download(
+ repo_id,
+ local_files_only=True,
+ allow_patterns=list(_WHISPER_MODEL_ALLOW_PATTERNS),
+ )
+ )
# A snapshot directory alone can be a partial download. The tokenizer
# must also be local, otherwise the recognizer fetches one during boot.
- required = ("config.json", "model.bin", "tokenizer.json")
- return all(
- (directory / file).is_file() and (directory / file).stat().st_size > 0
- for file in required
- ) and any(
+ missing = [
+ file
+ for file in _WHISPER_MODEL_REQUIRED_FILES
+ if not (directory / file).is_file() or (directory / file).stat().st_size == 0
+ ]
+ if not any(
file.is_file() and file.stat().st_size > 0 for file in directory.glob("vocabulary.*")
- )
+ ):
+ missing.append("vocabulary.*")
+ if missing:
+ return f"missing or empty model files: {', '.join(missing)}"
+ return None
except Exception as exc: # noqa: BLE001 — an uncertain cache is not ready
log.debug("Whisper checkpoint %r is not cached locally: %s", name, exc)
- return False
+ return "the required model files could not be read from the local cache"
def models_root(data_dir: str | None = None) -> Path:
@@ -339,17 +366,15 @@ def whisper_status(model: str) -> LocalModelStatus:
tells them what to do next.
"""
engine = runtime_installed("faster-whisper")
- cached = whisper_model_cached(model) if engine else False
+ cache_issue = _whisper_model_cache_issue(model) if engine else None
+ cached = engine and cache_issue is None
if not engine:
detail = (
"The local speech engine is not installed yet. Install it from here "
"to transcribe on this machine without an API key."
)
- elif not cached:
- detail = (
- f"The engine is installed, but the {model} model still has to be "
- "downloaded (about 3 GB, once)."
- )
+ elif cache_issue is not None:
+ detail = f"The engine is installed, but the {model} model is not ready: {cache_issue}."
else:
detail = f"Ready — {model} runs entirely on this machine."
return LocalModelStatus(
diff --git a/tests/unit/speech/test_cold_model_status.py b/tests/unit/speech/test_cold_model_status.py
index 4f48a36d32..3db51c4ad6 100644
--- a/tests/unit/speech/test_cold_model_status.py
+++ b/tests/unit/speech/test_cold_model_status.py
@@ -34,17 +34,52 @@ def test_alias_probe_reads_installed_mapping_without_executing_it(tmp_path, monk
monkeypatch.syspath_prepend(str(tmp_path))
monkeypatch.delitem(sys.modules, "faster_whisper", raising=False)
seen = []
+ model_dir = tmp_path / "partial"
+ model_dir.mkdir()
+ for name in (
+ "config.json",
+ "preprocessor_config.json",
+ "model.bin",
+ "tokenizer.json",
+ "vocabulary.json",
+ ):
+ (model_dir / name).write_text("fixture", encoding="utf-8")
def snapshot(repo, **kwargs):
seen.append((repo, kwargs))
- return str(tmp_path / "partial")
+ return str(model_dir)
monkeypatch.setattr(huggingface_hub, "snapshot_download", snapshot)
- assert local_models.whisper_model_cached("turbo") is False
- assert seen == [("custom/turbo", {"local_files_only": True})]
+ assert local_models.whisper_model_cached("turbo") is True
+ assert seen == [
+ (
+ "custom/turbo",
+ {
+ "local_files_only": True,
+ "allow_patterns": [
+ "config.json",
+ "preprocessor_config.json",
+ "model.bin",
+ "tokenizer.json",
+ "vocabulary.*",
+ ],
+ },
+ )
+ ]
+ assert not (model_dir / "README.md").exists()
+ assert not (model_dir / ".gitattributes").exists()
assert "faster_whisper" not in sys.modules
+def test_cache_issue_names_missing_payload_files(tmp_path):
+ for name in ("config.json", "tokenizer.json", "vocabulary.json"):
+ (tmp_path / name).write_text("fixture", encoding="utf-8")
+
+ assert local_models._whisper_model_cache_issue(str(tmp_path)) == (
+ "missing or empty model files: model.bin"
+ )
+
+
@pytest.mark.asyncio
async def test_slow_status_disk_check_does_not_block_the_loop(monkeypatch):
from dodaios.ui.web import provider_routes
diff --git a/tests/unit/speech/test_local_install.py b/tests/unit/speech/test_local_install.py
new file mode 100644
index 0000000000..7154c0a468
--- /dev/null
+++ b/tests/unit/speech/test_local_install.py
@@ -0,0 +1,25 @@
+"""The install result must explain a cache-readiness failure accurately."""
+
+from dodaios.speech import local_install
+from dodaios.speech.local_models import LocalModelStatus
+
+
+def test_install_reports_the_specific_model_readiness_issue(monkeypatch):
+ detail = "The engine is installed, but large-v3 is not ready: missing model.bin."
+ status = LocalModelStatus(
+ runtime="faster-whisper",
+ engine_installed=True,
+ model_present=False,
+ model_label="large-v3",
+ detail=detail,
+ )
+ run = local_install._InstallRun()
+ monkeypatch.setattr(local_install, "_run_for", lambda provider_id: run)
+ monkeypatch.setattr(local_install, "local_status", lambda provider_id: status)
+ monkeypatch.setattr(local_install, "_download_model", lambda entry, progress: None)
+
+ local_install._run_install("faster-whisper")
+
+ assert run.state == "error"
+ assert run.message == detail
+ assert "download may have been interrupted" not in run.message
diff --git a/tests/unit/speech/test_local_models.py b/tests/unit/speech/test_local_models.py
index 6a865d66ee..052448f97c 100644
--- a/tests/unit/speech/test_local_models.py
+++ b/tests/unit/speech/test_local_models.py
@@ -42,19 +42,23 @@ def test_installed_engine_without_weights_is_not_ready(
importable" as "this provider works".
"""
monkeypatch.setattr(local_models, "runtime_installed", lambda runtime: True)
- monkeypatch.setattr(local_models, "whisper_model_cached", lambda name: False)
+ monkeypatch.setattr(
+ local_models,
+ "_whisper_model_cache_issue",
+ lambda name: "missing or empty model files: model.bin",
+ )
status = local_models.whisper_status("large-v3")
assert status.ready is False
assert status.engine_installed is True
assert status.model_present is False
- assert "downloaded" in status.detail
+ assert "missing or empty model files: model.bin" in status.detail
def test_engine_and_weights_present_is_ready(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(local_models, "runtime_installed", lambda runtime: True)
- monkeypatch.setattr(local_models, "whisper_model_cached", lambda name: True)
+ monkeypatch.setattr(local_models, "_whisper_model_cache_issue", lambda name: None)
status = local_models.whisper_status("large-v3")
@@ -149,7 +153,11 @@ def test_status_reports_the_model_the_config_actually_names(
) -> None:
"""An override must be reflected, or the card reassures about the wrong model."""
monkeypatch.setattr(local_models, "runtime_installed", lambda runtime: True)
- monkeypatch.setattr(local_models, "whisper_model_cached", lambda name: False)
+ monkeypatch.setattr(
+ local_models,
+ "_whisper_model_cache_issue",
+ lambda name: "missing or empty model files: model.bin",
+ )
status = local_models.local_status("faster-whisper", model_override="small")