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(stt): make Whisper recommendation capability-verified, not GPU-presence-based

Ruben Lütke38b27b706ba6
diff --git a/jarvis/hardware/detection.py b/jarvis/hardware/detection.py
index ef0c08536a..a265e17e8a 100644
--- a/jarvis/hardware/detection.py
+++ b/jarvis/hardware/detection.py
@@ -227,32 +227,59 @@ def analyze() -> HardwareReport:
)
-def recommend_whisper(report: HardwareReport) -> WhisperRecommendation:
+def recommend_whisper(
+ report: HardwareReport,
+ gpu_inference_verified: bool | None = None,
+) -> WhisperRecommendation:
"""Maps a HardwareReport to the recommended Whisper configuration.
Heuristic:
- - NVIDIA GPU with >= 4 GB VRAM → large-v3-turbo (fast, MULTILINGUAL)
- - NVIDIA GPU with < 4 GB VRAM → base (multilingual)
- - No CUDA but plenty of RAM → CPU faster-whisper tiny/base
- - Otherwise → OpenAI Whisper API
+ - VERIFIED NVIDIA GPU with >= 4 GB VRAM → large-v3-turbo (fast, MULTILINGUAL)
+ - VERIFIED NVIDIA GPU with < 4 GB VRAM → base (multilingual)
+ - No/unverified GPU but plenty of RAM → CPU faster-whisper base
+ - Otherwise → OpenAI Whisper API
+
+ ``gpu_inference_verified`` is the CAPABILITY gate (AP-21/AP-25). A GPU
+ recommendation is handed out ONLY when a real GPU inference has VERIFIABLY
+ completed on this host (``True``). CUDA *presence* is necessary but not
+ sufficient: a driver/runtime mismatch — or the Blackwell hang that once left
+ every CTranslate2 inference wedged while ``torch.cuda.is_available()`` reported
+ ``True`` — must never persist a ``device="cuda"`` the host cannot actually run.
+ ``None`` (never probed) and ``False`` (probe failed / wedged) both fall back to
+ the CPU-first floor. This keeps the path vendor-neutral: an Apple-Silicon Mac
+ (no NVIDIA, no CUDA — CTranslate2 has no Metal backend) lands on CPU int8, the
+ correct choice there. A verified GPU is still adopted at runtime by the
+ background wake probe; this governs only the FIRST-RUN persisted recommendation.
Never recommends a Distil-Whisper model: all distil-* checkpoints are
English-only and mangle German/Spanish (the runtime force-upgrades them to
large-v3-turbo anyway).
"""
- if not report.has_nvidia_gpu or not report.torch_cuda_available:
+ gpu_usable = (
+ report.has_nvidia_gpu
+ and report.torch_cuda_available
+ and gpu_inference_verified is True
+ )
+ if not gpu_usable:
+ cuda_present_unverified = report.has_nvidia_gpu and report.torch_cuda_available
if report.ram_total_mb >= 8192:
+ rationale = (
+ "CUDA GPU present but its inference is not verified on this host — "
+ "recommending CPU 'base' until the runtime GPU probe passes (it is "
+ "verified and adopted automatically once voice boots). This avoids "
+ "persisting a 'cuda' choice a driver/runtime mismatch cannot run."
+ if cuda_present_unverified
+ else "No CUDA-capable GPU detected. CPU mode with 'base' delivers "
+ "acceptable quality at ~1s latency for 5s audio. "
+ "For better latency, configure the OpenAI Whisper API as a fallback."
+ )
return WhisperRecommendation(
provider="faster-whisper",
model="base",
device="cpu",
compute_type="int8",
expected_latency_ms=1200,
- rationale=(
- "No CUDA-capable GPU detected. CPU mode with 'base' delivers "
- "acceptable quality at ~1s latency for 5s audio. "
- "For better latency, configure the OpenAI Whisper API as a fallback."
- ),
+ rationale=rationale,
)
return WhisperRecommendation(
provider="openai-api",
@@ -361,9 +388,27 @@ def _format_report(report: HardwareReport, rec: WhisperRecommendation) -> str:
return "\n".join(lines)
+def cuda_inference_verified() -> bool | None:
+ """Cached GPU-inference verdict for this host (non-blocking), or ``None``.
+
+ Thin, lazy indirection to ``jarvis.plugins.stt.wake_gpu_probe_cached`` so this
+ setup-path module never imports the STT / ctranslate2 stack eagerly. Feeds
+ ``recommend_whisper``'s capability gate (AP-21/AP-25): the verdict is the one a
+ prior background probe already wrote to disk — never a fresh blocking probe on
+ this report path (AP-26). Any import/read error → ``None`` (treated as
+ unverified → CPU-first).
+ """
+ try:
+ from jarvis.plugins.stt import wake_gpu_probe_cached
+
+ return wake_gpu_probe_cached()
+ except Exception: # noqa: BLE001 — the recommender must stay CPU-first on any error
+ return None
+
+
def main() -> int:
report = analyze()
- rec = recommend_whisper(report)
+ rec = recommend_whisper(report, gpu_inference_verified=cuda_inference_verified())
print(_format_report(report, rec))
return 0
diff --git a/jarvis/plugins/stt/__init__.py b/jarvis/plugins/stt/__init__.py
index 61f9e7ef51..2b9bf6aa0d 100644
--- a/jarvis/plugins/stt/__init__.py
+++ b/jarvis/plugins/stt/__init__.py
@@ -489,6 +489,42 @@ def _wake_gpu_inference_verified() -> bool:
return ok
+def wake_gpu_probe_cached() -> bool | None:
+ """Return the PERSISTED GPU-inference verdict for this host, or ``None``.
+
+ Non-blocking companion to :func:`_wake_gpu_inference_verified` (which BLOCKS
+ on a cache miss to run one real turbo/cuda inference). Reads only the verdict
+ already written to disk by a prior probe or the live backstop; it NEVER
+ launches the probe subprocess. Returns:
+
+ - ``True`` / ``False`` when a verdict for the CURRENTLY installed ctranslate2
+ version is cached;
+ - ``None`` when no verdict exists here, the cache is unreadable, or the cached
+ verdict was written under a DIFFERENT ctranslate2 version (a runtime upgrade
+ can fix — or re-introduce — the AP-25 hang, so a stale verdict is untrusted).
+
+ Off-critical-path callers (the first-run hardware recommender) use this to gate
+ a GPU recommendation on a REAL, verified inference (AP-21/AP-25) instead of mere
+ CUDA presence, while paying nothing when the host has never probed. AP-26-safe:
+ a pure file read, never the blocking probe.
+ """
+ ct2_version = _ctranslate2_version()
+ try:
+ cached = json.loads(_wake_gpu_probe_cache_path().read_text(encoding="utf-8"))
+ except FileNotFoundError:
+ return None
+ except Exception as exc: # noqa: BLE001 — a corrupt cache must never break the caller
+ logger.debug("Wake-GPU probe cache unreadable ({}); treating as unprobed.", exc)
+ return None
+ if (
+ isinstance(cached, dict)
+ and isinstance(cached.get("ok"), bool)
+ and cached.get("ctranslate2") == ct2_version
+ ):
+ return cached["ok"]
+ return None
+
+
def _persist_wake_gpu_probe(ok: bool, ct2_version: str | None = None) -> None:
"""Best-effort write of the probe verdict (shared by probe + bad-mark)."""
cache_path = _wake_gpu_probe_cache_path()
@@ -765,4 +801,5 @@ __all__ = [
"build_wake_whisper",
"mark_wake_gpu_bad",
"start_wake_model_prefetch",
+ "wake_gpu_probe_cached",
]
diff --git a/jarvis/setup/wizard.py b/jarvis/setup/wizard.py
index dca11beb8e..c5d2e04428 100644
--- a/jarvis/setup/wizard.py
+++ b/jarvis/setup/wizard.py
@@ -449,7 +449,12 @@ def step_hardware_check() -> detection.HardwareReport:
_println(" Step 1 / 8 — Hardware analysis")
_println("=" * 60)
report = detection.analyze()
- rec = detection.recommend_whisper(report)
+ # Capability-verified, not presence-based (AP-21/AP-25): only recommend a GPU
+ # config when a real GPU inference has been verified on this host. Non-blocking
+ # — reads the verdict a prior background probe cached, never runs one here.
+ rec = detection.recommend_whisper(
+ report, gpu_inference_verified=detection.cuda_inference_verified()
+ )
_println(detection._format_report(report, rec))
if report.ffmpeg_version is None:
diff --git a/tests/unit/hardware/test_whisper_recommendation.py b/tests/unit/hardware/test_whisper_recommendation.py
index fd5a37a337..a37fa815a3 100644
--- a/tests/unit/hardware/test_whisper_recommendation.py
+++ b/tests/unit/hardware/test_whisper_recommendation.py
@@ -1,12 +1,19 @@
-"""recommend_whisper must never recommend an English-only Whisper model.
-
-Regression guard for the "German is mangled on a GPU box" first-run bug: the
-wizard used to recommend distil-large-v3 / distil-small for NVIDIA GPUs. Every
-Distil-Whisper checkpoint is English-only (there is no multilingual distil) and
-turns German/Spanish into English words. The runtime already force-upgrades such
-models to large-v3-turbo, so recommending them only persisted a confusing,
-self-overridden value into jarvis.toml. The recommender must stay aligned with
-that runtime guard and hand out a multilingual model directly.
+"""``recommend_whisper`` must be capability-VERIFIED and never English-only.
+
+Two guarantees under test:
+
+1. **Never English-only** (original regression): the wizard used to recommend
+ distil-large-v3 / distil-small for NVIDIA GPUs. Every Distil-Whisper checkpoint
+ is English-only (there is no multilingual distil) and turns German/Spanish into
+ English words, so the recommender must hand out a multilingual model directly.
+
+2. **GPU presence is not GPU usability** (AP-21/AP-25): ``recommend_whisper`` only
+ hands back ``device="cuda"`` when a real GPU inference has been VERIFIED on this
+ host (``gpu_inference_verified=True``). CUDA *presence* alone — the value a
+ driver/runtime mismatch or the Blackwell hang leaves ``torch.cuda.is_available()``
+ reporting — falls back to the CPU-first floor, so no ``cuda`` choice a host cannot
+ actually run is ever persisted into ``jarvis.toml``. This also keeps the path
+ vendor-neutral: an Apple-Silicon Mac (no NVIDIA, no CUDA) lands on CPU int8.
"""
from __future__ import annotations
@@ -23,12 +30,23 @@ def _gpu_report(vram_mb: int) -> SimpleNamespace:
has_nvidia_gpu=True,
torch_cuda_available=True,
total_vram_mb=vram_mb,
+ ram_total_mb=16384,
+ )
+
+
+def _cpu_report(*, ram_total_mb: int = 16384) -> SimpleNamespace:
+ """A host with no NVIDIA GPU / no CUDA — a headless VPS or an Apple-Silicon Mac."""
+ return SimpleNamespace(
+ has_nvidia_gpu=False,
+ torch_cuda_available=False,
+ total_vram_mb=0,
+ ram_total_mb=ram_total_mb,
)
@pytest.mark.parametrize("vram", [2000, 4000, 6000, 8000, 16000, 24000])
-def test_gpu_recommendation_is_never_english_only(vram: int) -> None:
- rec = recommend_whisper(_gpu_report(vram))
+def test_verified_gpu_recommendation_is_never_english_only(vram: int) -> None:
+ rec = recommend_whisper(_gpu_report(vram), gpu_inference_verified=True)
assert rec.model not in _ENGLISH_ONLY_MODELS, rec.model
assert not rec.model.startswith("distil-"), (
f"recommended {rec.model!r}: every distil-* model is English-only and "
@@ -37,12 +55,39 @@ def test_gpu_recommendation_is_never_english_only(vram: int) -> None:
@pytest.mark.parametrize("vram", [4000, 8000, 16000, 24000])
-def test_capable_gpu_recommends_multilingual_turbo(vram: int) -> None:
- rec = recommend_whisper(_gpu_report(vram))
+def test_verified_capable_gpu_recommends_multilingual_turbo(vram: int) -> None:
+ rec = recommend_whisper(_gpu_report(vram), gpu_inference_verified=True)
assert rec.model == "large-v3-turbo"
assert rec.device == "cuda"
-def test_low_vram_gpu_recommends_base_multilingual() -> None:
- rec = recommend_whisper(_gpu_report(2000))
+def test_verified_low_vram_gpu_recommends_base_multilingual() -> None:
+ rec = recommend_whisper(_gpu_report(2000), gpu_inference_verified=True)
assert rec.model == "base"
+ assert rec.device == "cuda"
+
+
[email protected]("verified", [None, False])
+def test_unverified_cuda_falls_back_to_cpu(verified) -> None:
+ # CUDA is PRESENT (torch_cuda_available=True) but a real inference has not been
+ # verified — the AP-25 "present but unusable" case. Must not persist "cuda".
+ rec = recommend_whisper(_gpu_report(24000), gpu_inference_verified=verified)
+ assert rec.device == "cpu"
+ assert rec.compute_type == "int8"
+ assert rec.model == "base"
+
+
+def test_apple_silicon_recommends_cpu_int8() -> None:
+ # No NVIDIA GPU, no CUDA (Apple Silicon / headless Linux). CTranslate2 has no
+ # Metal backend, so CPU int8 is the correct, vendor-neutral choice.
+ rec = recommend_whisper(_cpu_report(), gpu_inference_verified=None)
+ assert rec.provider == "faster-whisper"
+ assert rec.device == "cpu"
+ assert rec.compute_type == "int8"
+
+
+def test_default_is_cpu_first_when_verification_unknown() -> None:
+ # The default (no flag passed) must be CPU-first even on a CUDA-present box —
+ # a caller that does not KNOW the GPU works must never get a cuda recommendation.
+ rec = recommend_whisper(_gpu_report(24000))
+ assert rec.device == "cpu"
diff --git a/tests/unit/plugins/stt/test_wake_gpu_probe_cached.py b/tests/unit/plugins/stt/test_wake_gpu_probe_cached.py
new file mode 100644
index 0000000000..a514cadd9a
--- /dev/null
+++ b/tests/unit/plugins/stt/test_wake_gpu_probe_cached.py
@@ -0,0 +1,80 @@
+"""``wake_gpu_probe_cached`` — the NON-blocking reader of the GPU-inference verdict.
+
+Companion to :func:`_wake_gpu_inference_verified` (which BLOCKS on a cache miss to
+run one real turbo/cuda inference in a subprocess). Off-critical-path callers such
+as the first-run hardware recommender (``jarvis.hardware.detection``) must gate a
+GPU recommendation on a REAL, verified inference (AP-21/AP-25) WITHOUT ever paying
+the blocking probe. This reader delivers exactly that:
+
+- a cached verdict for the CURRENTLY installed ctranslate2 version -> True / False;
+- no cache file, or a verdict left over from a DIFFERENT ctranslate2 version
+ (a runtime upgrade may fix or re-introduce the hang) -> ``None`` (unknown);
+- it NEVER launches the probe subprocess.
+"""
+from __future__ import annotations
+
+import json
+
+import pytest
+
+import jarvis.plugins.stt as stt_pkg
+from jarvis.plugins.stt import wake_gpu_probe_cached
+
+
[email protected](autouse=True)
+def _isolated_cache(tmp_path, monkeypatch):
+ monkeypatch.setenv("JARVIS__MEMORY__DATA_DIR", str(tmp_path))
+ return tmp_path
+
+
+def _write_cache(tmp_path, *, ok: bool, ct2: str) -> None:
+ (tmp_path / "wake_gpu_probe.json").write_text(
+ json.dumps({"ok": ok, "ctranslate2": ct2}), encoding="utf-8"
+ )
+
+
+def _pin_version(monkeypatch, version: str) -> None:
+ monkeypatch.setattr(stt_pkg, "_ctranslate2_version", lambda: version)
+
+
+def _forbid_subprocess(monkeypatch) -> None:
+ def _boom() -> bool:
+ raise AssertionError("the cached reader must never launch the probe")
+
+ monkeypatch.setattr(stt_pkg, "_run_wake_gpu_probe_subprocess", _boom)
+
+
+def test_no_cache_file_returns_none(tmp_path, monkeypatch) -> None:
+ _pin_version(monkeypatch, "4.7.1")
+ _forbid_subprocess(monkeypatch)
+ assert wake_gpu_probe_cached() is None
+
+
+def test_verified_verdict_for_current_version_returns_true(tmp_path, monkeypatch) -> None:
+ _pin_version(monkeypatch, "4.7.1")
+ _write_cache(tmp_path, ok=True, ct2="4.7.1")
+ _forbid_subprocess(monkeypatch)
+ assert wake_gpu_probe_cached() is True
+
+
+def test_failed_verdict_for_current_version_returns_false(tmp_path, monkeypatch) -> None:
+ _pin_version(monkeypatch, "4.7.1")
+ _write_cache(tmp_path, ok=False, ct2="4.7.1")
+ _forbid_subprocess(monkeypatch)
+ assert wake_gpu_probe_cached() is False
+
+
+def test_stale_version_verdict_is_treated_as_unknown(tmp_path, monkeypatch) -> None:
+ # A verdict written under a DIFFERENT ctranslate2 version must not be trusted:
+ # a runtime upgrade can fix or re-introduce the AP-25 hang.
+ _pin_version(monkeypatch, "4.8.0")
+ _write_cache(tmp_path, ok=True, ct2="4.7.1")
+ _forbid_subprocess(monkeypatch)
+ assert wake_gpu_probe_cached() is None
+
+
+def test_corrupt_cache_returns_none(tmp_path, monkeypatch) -> None:
+ _pin_version(monkeypatch, "4.7.1")
+ (tmp_path / "wake_gpu_probe.json").write_text("{ not json", encoding="utf-8")
+ _forbid_subprocess(monkeypatch)
+ assert wake_gpu_probe_cached() is None