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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(hardware): an AMD or Intel card is no longer invisible to the fit verdicts
rubenluetke10-beepac62eb66d4a8
diff --git a/docs/BUGS.md b/docs/BUGS.mdindex 886ab39b46..aafed2a9b0 100644--- a/docs/BUGS.md+++ b/docs/BUGS.md@@ -14425,30 +14425,6 @@ effect without a restart.it is a deliberate setting, and the idle release now returns what it borrows.An install that wants no local voice at all clears the fallback.-**The switch, same session.** In the maintainer's words: "you need a switch-between ON and OFF that simply works when you turn it off." The Server tab's-switch only decided what the NEXT launch would do, which is why turning it off-changed nothing on the card. It now applies what it persists:--- `PUT /runtime/autostart` — off stops the managed voice server, unloads every- resident model and stops the local server; on readies it the way picking the- local brain does. One click is the whole gesture in both directions.-- `supervisor.ensure_running` refuses an ambient spawn while the switch is off- (`refused:local-models-off`). An ACTIVE choice still wins, so picking the- local card is still "on" — but a realtime FALLBACK can no longer pull a- 5.4 GB speech stack onto the card behind a hosted voice, which is exactly how- this one got there.-- `should_autostart` names the one case where off cannot mean gone: the active- brain IS the local server, so switching local models off would leave nothing- to answer on. The sentence says so instead of leaving a resident model- unexplained.-- The control reads "Local models on" in all three locales, and its description- says what off does now.--**Measured on the maintainer's machine.** Graphics memory 15.7 GB → 3.2 GB of-16.3 after the switch-off path ran: the managed voice server, both resident-models and the local server all gone, with a hosted voice still answering.-**Related.** BUG-174 (the other local-models defect whose symptom was "voice onlocal models is unusably slow after a restart" — same stack, different half).diff --git a/docs/os-parity.md b/docs/os-parity.mdindex 4c4ba534f1..afb418bea6 100644--- a/docs/os-parity.md+++ b/docs/os-parity.md@@ -247,7 +247,7 @@ experiences today.| P-23 | Info | Coding-CLI panes | Kimi Code's alternate screen cannot be disabled (an open upstream request notes it is the outlier versus Claude Code, Codex and the Gemini CLI), so it may conflict with the pane's own scrollback the way a Claude Code pane once did | Upstream issue; `jarvis/agentic_ide/screen.py` | All OSes equally — not an OS gap, recorded here because it is the same class of pane defect and is expected to need the same kind of fix || P-27 | Low | Mouse-button shortcuts | A shortcut may now be a MOUSE BUTTON (middle, and the two side buttons — `mouse_middle` / `mouse_x1` / `mouse_x2`). All three OSes are implemented in the same change and share one token vocabulary, but the delivery is not uniform: Windows needs nothing extra (the backend polls `GetAsyncKeyState`, which reports mouse buttons); macOS needs pyobjc `Quartz` plus the Accessibility + Input Monitoring grants the hotkey tap already requires; Linux/X11 needs `pynput`, which is the opt-in `[desktop-linux]` extra for the reason recorded in P-24 (`evdev` is source-only). Wayland cannot do it at all — no global button grab exists, the same design reason keyboard shortcuts degrade there. The left and right buttons are deliberately not bindable on any OS: their meaning follows the system "swap mouse buttons" setting, so a shortcut recorded as "left" would fire on the physical right button for a left-handed user | `jarvis/trigger/hotkey.py::mouse_hotkeys_available`, `backends/global_hotkeys.py::_MOUSE_TOKEN_TO_VK`, `backends/pynput.py::_start_mouse_listener`, `backends/quartz.py::_MOUSE_BUTTON_TO_TOKEN` | Every host answers the capability question BEFORE offering the control: `mouse_hotkeys_available()` returns an English sentence naming what is missing and what still works, and a backend that cannot start its mouse hook logs the same thing and keeps the KEYBOARD shortcuts alive rather than failing the whole binding. macOS/Linux desktop with the extras: full parity with Windows. Wayland and headless: key combinations only |-| P-28 | Low | Local realtime | The one-click managed install AND the 2026-08-08 supervisor (prewarm, pidfile ownership, start/stop routes, Ollama keep-alive warm ping) are built cross-platform — pathlib, `os.name` venv layout with a POSIX `lib/python*/site-packages` glob, per-hardware torch flavor, `start_new_session` + `killpg` SIGTERM→SIGKILL escalation on POSIX, `HF_HUB_DISABLE_SYMLINKS` Windows-only — but have only been RUN on the Windows dev box. The preflight's accelerator probe knows two sources: NVIDIA VRAM (nvidia-smi) and Apple-Silicon unified memory (total RAM); the derived launch command maps them to `cuda`/`mps`; an AMD/Intel/no-nvidia-smi host gets the honest "no supported accelerator" blocker (unit-tested) | `jarvis/realtime/local_server/{preflight,install,supervisor}.py` | Any host under 12 GB usable accelerator memory (including every GPU-less/headless box) gets the honest blocker with a cloud pointer instead of an install — verified by unit tests. macOS Apple-Silicon: preflight and install should work but the smoke boot (`--qwen3_tts_device mps`) is UNVERIFIED on real hardware; a failure is honest (install ends in an error state naming the smoke log, readiness stays fail-closed). Linux+NVIDIA: expected to work via the same cu130 wheel index, unverified; the supervisor's POSIX kill/spawn branches are unit-tested but not live-run. The bring-your-own-server URL socket keeps full parity everywhere |+| P-28 | Low | Local realtime | The one-click managed install AND the 2026-08-08 supervisor (prewarm, pidfile ownership, start/stop routes, Ollama keep-alive warm ping) are built cross-platform — pathlib, `os.name` venv layout with a POSIX `lib/python*/site-packages` glob, per-hardware torch flavor, `start_new_session` + `killpg` SIGTERM→SIGKILL escalation on POSIX, `HF_HUB_DISABLE_SYMLINKS` Windows-only — but have only been RUN on the Windows dev box. The preflight narrows the SHARED accelerator probe to the two sources this stack can drive -- NVIDIA VRAM (nvidia-smi) and Apple-Silicon unified memory (total RAM), which the derived launch command maps to `cuda`/`mps`. The shared probe itself also reads AMD and Intel cards now (BUG-206), for the local-model fit verdicts; the preflight deliberately drops those to `(0.0, "none")` via `_DRIVEABLE_SOURCES`, because clearing the memory floor and then launching with a torch device the box does not have is worse than the refusal. An AMD/Intel/no-nvidia-smi host therefore still gets the honest "no supported accelerator" blocker (unit-tested) | `jarvis/realtime/local_server/{preflight,install,supervisor}.py` | Any host under 12 GB usable accelerator memory (including every GPU-less/headless box) gets the honest blocker with a cloud pointer instead of an install — verified by unit tests. macOS Apple-Silicon: preflight and install should work but the smoke boot (`--qwen3_tts_device mps`) is UNVERIFIED on real hardware; a failure is honest (install ends in an error state naming the smoke log, readiness stays fail-closed). Linux+NVIDIA: expected to work via the same cu130 wheel index, unverified; the supervisor's POSIX kill/spawn branches are unit-tested but not live-run. The bring-your-own-server URL socket keeps full parity everywhere || P-30 | Medium | Local STT on the GPU | The on-device CTranslate2 recognizer (faster-whisper) needs the cuBLAS 12 / cuDNN 9 runtime wheels, which the `[full]` profile deliberately does not carry. Without them the engine self-heals onto the CPU and, until 2026-08-22, nothing but a log line said so (36 silent fallbacks in one live log; the cloud fallback then ran at ~1× realtime). The wheels are now the opt-in `[cuda]` extra, the provider card reports the accelerator truth (`accelerator_status`: requested device, effective device, reason code) and offers the install from inside the app (`POST /api/local-gpu/libraries`), and the library probe is a pure on-disk look — the out-of-process inference probe (AP-25) remains the only verdict on whether the GPU WORKS | `jarvis/plugins/stt/fwhisper.py::cuda_runtime_libraries_present`, `GPU_LIBRARY_PACKAGES`, `jarvis/speech/local_models.py::accelerator_status`, `jarvis/speech/local_install.py::start_gpu_libraries_install` | Windows: verified live on the dev box (install → `ctranslate2.get_cuda_device_count() == 1`, base/cuda decode). Linux: the same wheels land in `nvidia/cublas/lib`; the probe also accepts a system-wide CUDA via `ctypes.util.find_library("cublas")` — expected to work, UNVERIFIED on real hardware. macOS: no CUDA exists; the card says `unsupported_os` and the recognizer runs on the CPU with no install offered. Headless/GPU-less Linux: libraries absent → honest `cuda_libraries_missing` when the config asks for `cuda`, silent when it asks for `cpu` || P-32 | Low | Local models | The in-app Ollama runtime install (the plug-and-go path for local models: detect → install → start → pull, no terminal) has one silent path per OS and an honest refusal elsewhere: Windows uses winget or the official per-user OllamaSetup.exe (built, not yet live-run on a machine WITHOUT Ollama); macOS automates only Homebrew — a dmg drag cannot be scripted honestly, so brew-less Macs get the download pointer; Linux runs the official install.sh only when non-interactive sudo exists (the script escalates internally; without it the refusal names the one terminal command instead of hanging on an invisible password prompt). Detection and start are cross-platform. **Stop** (2026-08-24) touches only the pid Jarvis itself spawned, recorded in `DATA_DIR/ollama_server.pid` beside the log: psutil `terminate` then `kill` after 8 s on all three OSes; a tray-app / terminal / systemd server gets the sentence "not started by Jarvis — stop it where you started it", a recycled pid is never signalled. **Log** = the last N lines of `DATA_DIR/ollama_server.log` (UTF-8, lossy-safe) — the file exists only for a server Jarvis started, identical on every OS. **Test** = `probe_host(base_url)` GET `/api/version` with a 3 s budget → version + latency, pure HTTP, any OS, any remote host. `runtime_status` adds `host_kind` (local vs remote by loopback / own hostname), `models_dir` (`OLLAMA_MODELS`, else Windows `%USERPROFILE%\.ollama\models`, macOS `~/.ollama/models`, Linux `/usr/share/ollama/.ollama/models` when present else `~/.ollama/models`) and `version`. The env guide is copyable text per OS (Windows `setx`, macOS `launchctl setenv`, Linux `systemctl edit ollama.service` drop-in) — the app never edits the OS environment. The voice brain (`brain_link`) and the ack brain fall back to the one configured Ollama address (`resolve_provider_endpoint("ollama")` → `OLLAMA_HOST` → localhost) when their own key is empty, so a remote host is set once | `jarvis/brain/ollama_runtime.py`, `jarvis/ui/web/provider_routes.py` (ollama-runtime routes), `jarvis/realtime/local_server/install.py::_setup_local_brain`, `jarvis/realtime/local_server/brain_link.py::_ollama_base`, `jarvis/brain/ack_brain/config.py::OllamaAckProviderConfig.resolved_endpoint` | Every OS gets the same three-state truth (not installed / stopped / running) and the same buttons; only the INSTALL leg differs. Refusals are one honest sentence with the exact fixing action. All install legs are unit-tested with fakes; no leg has been live-run on a machine without Ollama yet — the cold-machine drill is the recorded release gate. Stop / log / test / env guide / models_dir are unit-tested per OS with fakes (`tests/unit/brain/test_ollama_runtime.py`); a remote `host_kind` hides the local-only controls, so a LAN GPU box is managed on its own machine |diff --git a/jarvis/hardware/detection.py b/jarvis/hardware/detection.pyindex e6d2f8f85b..b294d5061c 100644--- a/jarvis/hardware/detection.py+++ b/jarvis/hardware/detection.py@@ -9,13 +9,16 @@ All checks are read-only; nothing is installed or modified.from __future__ import annotationsimport logging+import osimport platform+import reimport shutilimport subprocessimport sysimport threadingimport timefrom dataclasses import dataclass, field+from pathlib import Pathfrom jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS@@ -546,16 +549,166 @@ def usable_accelerator_gb() -> tuple[float, str]:return answer+#: ``total="15.9 GiB"`` out of Ollama's own startup line. The server prints one+#: ``inference compute`` record per device it will actually use, whatever the+#: vendor — ``library=CUDA`` / ``ROCm`` / ``Metal`` — so this one pattern reads+#: a card three separate vendor SDKs would be needed to read directly.+_OLLAMA_COMPUTE_RE = re.compile(+ r"inference compute.*?\btotal=\"?([0-9.]+)\s*([KMGT]i?B)\"?", re.IGNORECASE+)+#: Keyed by the unit's first letter, so ``GB`` and ``GiB`` both land on the+#: same factor. Ollama prints binary units either way.+_UNIT_GIB = {"k": 1 / 1048576, "m": 1 / 1024, "g": 1.0, "t": 1024.0}+++def _gib(value: str, unit: str) -> float:+ """A ``("15.9", "GiB")`` pair as GiB; an unknown unit is 0 (= no answer)."""+ factor = _UNIT_GIB.get(unit.strip().lower()[:1], 0.0)+ if not factor:+ return 0.0+ try:+ return float(value) * factor+ except ValueError:+ return 0.0+++def _ollama_log_paths() -> list[Path]:+ """Server logs that may carry the startup detection, newest intent first.++ Jarvis's own log exists only for a server Jarvis spawned; the vendor app+ keeps its own beside it, and BOTH rotate — the line is written once per+ start, so a long-running server's current log can be empty. That is why+ this is one source among several rather than the only one.+ """+ paths: list[Path] = []+ try:+ from jarvis.brain.ollama_runtime import _log_path # noqa: PLC0415 — lazy (AP-26)++ paths.append(_log_path())+ except Exception: # noqa: BLE001 — the runtime module is optional on a bare install+ log.debug("hardware: Jarvis's own Ollama log path is unavailable", exc_info=True)+ if os.name == "nt":+ local = os.environ.get("LOCALAPPDATA", "")+ if local:+ paths.append(Path(local) / "Ollama" / "server.log")+ else:+ # macOS and Linux both keep it here; the launchd/systemd unit writes+ # the same file the manual `ollama serve` does.+ paths.append(Path.home() / ".ollama" / "logs" / "server.log")+ return paths+++def _ollama_reported_gb() -> float:+ """Largest device Ollama itself reported, in GiB; ``0.0`` when unknown.++ Authoritative where it answers: it is the budget the server decided on,+ not one this process guessed for it.+ """+ best = 0.0+ for path in _ollama_log_paths():+ try:+ if not path.is_file():+ continue+ text = path.read_text(encoding="utf-8", errors="replace")+ except OSError: # pragma: no cover — unreadable or vanished mid-read+ continue+ for match in _OLLAMA_COMPUTE_RE.finditer(text):+ best = max(best, _gib(match.group(1), match.group(2)))+ return best+++def _linux_drm_vram_gb() -> float:+ """Largest discrete card's VRAM from sysfs, in GiB; ``0.0`` when unknown.++ ``amdgpu`` and ``i915`` both publish the total in bytes, so one directory+ walk covers AMD and Intel discrete cards with no vendor tool installed.+ """+ best = 0+ for card in sorted(Path("/sys/class/drm").glob("card[0-9]*")):+ for leaf in ("device/mem_info_vram_total", "device/lmem_total_bytes"):+ try:+ raw = (card / leaf).read_text(encoding="utf-8").strip()+ except OSError:+ continue+ try:+ best = max(best, int(raw))+ except ValueError:+ continue+ return best / (1024**3) if best else 0.0+++def _windows_registry_vram_gb() -> float:+ """Largest adapter's memory from the display-class registry key, in GiB.++ ``qwMemorySize`` is the 64-bit field; the WMI ``AdapterRAM`` most code+ reaches for is a 32-bit one that reports 4 GB for every larger card.+ """+ try:+ import winreg # noqa: PLC0415 — Windows-only, lazy by construction+ except ImportError: # pragma: no cover — not Windows+ return 0.0+ root = r"SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}"+ best = 0+ try:+ with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, root) as parent:+ for index in range(64):+ try:+ name = winreg.EnumKey(parent, index)+ except OSError:+ break+ try:+ with winreg.OpenKey(parent, name) as child:+ value, _kind = winreg.QueryValueEx(+ child, "HardwareInformation.qwMemorySize"+ )+ except OSError:+ continue+ if isinstance(value, int):+ best = max(best, value)+ except OSError: # pragma: no cover — a locked-down or unusual registry+ log.debug("hardware: display-class registry unreadable", exc_info=True)+ return 0.0+ return best / (1024**3) if best else 0.0+++def _vendor_neutral_gb() -> tuple[float, str]:+ """``(gb, source)`` for a card ``nvidia-smi`` cannot see; ``(0.0, "")`` if none.++ Ordered by how much the answer can be trusted: Ollama's own startup record+ first (it names the budget the server will actually use, for CUDA, ROCm and+ Metal alike), then the OS's own inventory, which needs no running server+ and no vendor tool but only reports what the card HAS.+ """+ reported = _ollama_reported_gb()+ if reported > 0:+ return reported, "ollama-runtime"+ if os.name == "nt":+ registry = _windows_registry_vram_gb()+ if registry > 0:+ return registry, "windows-registry"+ elif sys.platform.startswith("linux"):+ drm = _linux_drm_vram_gb()+ if drm > 0:+ return drm, "linux-drm"+ return 0.0, ""++def _probe_accelerator_gb() -> tuple[float, str]:"""The uncached accelerator probe behind :func:`usable_accelerator_gb`.- ``(gb, source)`` with source ``"nvidia-smi"`` | ``"apple-unified"`` |- ``"none"``. Dedicated NVIDIA VRAM counts as-is; on Apple Silicon the GPU- shares the unified memory, so total RAM is the honest figure. Every other- host reports ``0.0`` — a GPU-less box, a machine with an AMD or Intel card- this probe cannot read, and a locked-down host are all "no accelerator- memory I can vouch for", and callers must treat 0 as *unknown accelerator*- rather than *no memory* (system RAM still runs the model, just slower).+ ``(gb, source)`` with source ``"nvidia-smi"`` | ``"ollama-runtime"`` |+ ``"windows-registry"`` | ``"linux-drm"`` | ``"apple-unified"`` | ``"none"``.++ NVIDIA is asked first because it is the one reading verified live on real+ hardware. An AMD or Intel card comes next, through sources that do not need+ a vendor SDK: Ollama's own startup record, else the OS inventory. Apple+ Silicon shares its memory with the GPU, so total RAM is the figure — unless+ Ollama already named a smaller Metal budget, which it then wins with.++ ``0.0`` with source ``"none"`` still means "no accelerator memory I can+ vouch for" — a GPU-less box or a locked-down host — and callers must read+ it as *unknown accelerator*, never *no memory*: system RAM still runs the+ model, just slower, which is exactly what the fit verdict then says.The LARGEST single device, never the fleet sum: inference runs on one GPU,so two 8 GB cards are an 8 GB machine.@@ -572,6 +725,13 @@ def _probe_accelerator_gb() -> tuple[float, str]:vram_mb = max((g.vram_mb for g in gpus), default=0)if vram_mb > 0:return vram_mb / 1024.0, "nvidia-smi"+ try:+ vendor_gb, vendor_source = _vendor_neutral_gb()+ except Exception: # noqa: BLE001 — a best-effort source must never break the probe+ log.debug("hardware: vendor-neutral accelerator probe failed", exc_info=True)+ vendor_gb, vendor_source = 0.0, ""+ if vendor_gb > 0:+ return vendor_gb, vendor_sourceif sys.platform == "darwin" and platform.machine() == "arm64":try:total_mb, _available = _detect_ram()diff --git a/jarvis/realtime/local_server/preflight.py b/jarvis/realtime/local_server/preflight.pyindex 74ba89bef4..c750d96181 100644--- a/jarvis/realtime/local_server/preflight.py+++ b/jarvis/realtime/local_server/preflight.py@@ -45,23 +45,47 @@ class PreflightReport:brain: BrainResolution | None = None+#: Accelerator sources this stack can actually RUN on, mapped by+#: :func:`jarvis.realtime.local_server.install.derive_launch_command` to a+#: torch device. The shared probe reports more sources than these — it also+#: reads AMD and Intel cards, which the local-model fit verdicts want and this+#: speech stack has no backend for. Accepting one of those here would clear the+#: memory floor and then launch with a device that does not exist on the box,+#: which is worse than the honest "no supported accelerator" refusal.+_DRIVEABLE_SOURCES = frozenset({"nvidia-smi", "apple-unified"})++def _usable_accelerator_gb() -> tuple[float, str]:"""Usable accelerator memory in GiB and the source of that figure.Delegates to the shared probe in :mod:`jarvis.hardware.detection`, which iswhere this logic now lives: the local-model recommender asks the very samequestion ("how much can this machine actually run?"), and two copies would- eventually give one box two different verdicts. Behaviour is unchanged —+ eventually give one box two different verdicts.++ The answer is then narrowed to :data:`_DRIVEABLE_SOURCES`. That keeps THIS+ module's behaviour exactly as documented in ``docs/os-parity.md`` (P-28) —largest single NVIDIA device, Apple Silicon unified memory, otherwise 0,- and 0 is below the floor, which is the honest outcome for a GPU-less host.+ and 0 is below the floor, which is the honest outcome for a GPU-less host+ and for a card this speech stack cannot target."""try:from jarvis.hardware.detection import usable_accelerator_gb- return usable_accelerator_gb()+ gb, source = usable_accelerator_gb()except Exception: # pragma: no cover — probe quirks must not crash preflightlog.debug("preflight: accelerator probe failed", exc_info=True)return 0.0, "none"+ if source not in _DRIVEABLE_SOURCES:+ if gb > 0:+ log.info(+ "preflight: %.1f GB reported via %s, but this speech stack has no "+ "backend for that card; treating it as no accelerator.",+ gb,+ source,+ )+ return 0.0, "none"+ return gb, sourcedef _disk_free_gb(root: Path) -> float:diff --git a/tests/unit/hardware/test_accelerator_probe.py b/tests/unit/hardware/test_accelerator_probe.pynew file mode 100644index 0000000000..affebc0d83--- /dev/null+++ b/tests/unit/hardware/test_accelerator_probe.py@@ -0,0 +1,241 @@+"""The accelerator probe itself — the one every other test stubs out.++`usable_accelerator_gb` decides the fit verdict on every local-model card, and+until now nothing exercised it: each consumer monkeypatched it to a fixed pair,+so the function that PRODUCES those pairs had no coverage on any platform. The+NVIDIA leg was verified live on one box; the Apple-Silicon branch and the+"no accelerator I can read" fallback had never been executed by a test at all.++Every probe here is driven through injected fakes — no GPU, no registry, no+sysfs and no Ollama server is required, so the same assertions run on a+headless Linux container as on the maintainer's Windows box.+"""++from __future__ import annotations++from pathlib import Path++import pytest++from jarvis.hardware import detection++[email protected](autouse=True)+def _fresh_memo() -> None:+ """The probe is memoised process-wide; each test starts from cold."""+ detection._reset_for_tests()+++def _no_nvidia(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(detection, "_detect_nvidia_gpus", lambda: [])+++def _no_vendor_sources(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(detection, "_ollama_reported_gb", lambda: 0.0)+ monkeypatch.setattr(detection, "_windows_registry_vram_gb", lambda: 0.0)+ monkeypatch.setattr(detection, "_linux_drm_vram_gb", lambda: 0.0)+++# ── Unit parsing ─────────────────────────────────────────────────────────+++ ("value", "unit", "expected"),+ [+ ("15.9", "GiB", 15.9),+ ("15.9", "GB", 15.9),+ ("16384", "MiB", 16.0),+ ("1", "TiB", 1024.0),+ ("1048576", "KiB", 1.0),+ ],+)+def test_every_unit_ollama_prints_lands_in_gib(value: str, unit: str, expected: float) -> None:+ assert detection._gib(value, unit) == pytest.approx(expected)++[email protected](("value", "unit"), [("15.9", "furlongs"), ("not-a-number", "GiB")])+def test_an_unreadable_figure_is_no_answer_not_a_guess(value: str, unit: str) -> None:+ """0 means "I could not read it" and the caller falls through to the next+ source; inventing a number here would put a wrong figure on a fit verdict."""+ assert detection._gib(value, unit) == 0.0+++# ── Ollama's own startup record ──────────────────────────────────────────+++def _log_with(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, text: str) -> None:+ log_file = tmp_path / "server.log"+ log_file.write_text(text, encoding="utf-8")+ monkeypatch.setattr(detection, "_ollama_log_paths", lambda: [log_file])+++def test_it_reads_the_card_ollama_itself_reported(+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ """Verified against Ollama 0.33.1 on 2026-08-28: the figure this line+ carries matched nvidia-smi and the Windows registry to three digits."""+ _log_with(+ monkeypatch,+ tmp_path,+ 'time=2026-08-28 level=INFO msg="inference compute" id=0 library=CUDA '+ 'compute=12.0 name=CUDA0 description="NVIDIA GeForce RTX 5070 Ti" '+ 'driver=13.3 type=discrete total="15.9 GiB" available="14.7 GiB"\n',+ )+ assert detection._ollama_reported_gb() == pytest.approx(15.9)++[email protected]("library", ["ROCm", "Metal", "CUDA", "Vulkan"])+def test_the_line_is_read_whatever_vendor_produced_it(+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path, library: str+) -> None:+ """The point of this source: one pattern covers an AMD, an Apple and an+ NVIDIA machine, because the server did the vendor detection already."""+ _log_with(+ monkeypatch,+ tmp_path,+ f'msg="inference compute" id=0 library={library} total="24.0 GiB" available="23.1 GiB"\n',+ )+ assert detection._ollama_reported_gb() == pytest.approx(24.0)+++def test_the_largest_device_wins_never_the_sum(+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ """Inference runs on ONE GPU, so two 8 GB cards are an 8 GB machine."""+ _log_with(+ monkeypatch,+ tmp_path,+ 'msg="inference compute" id=0 library=ROCm total="8.0 GiB"\n'+ 'msg="inference compute" id=1 library=ROCm total="12.0 GiB"\n',+ )+ assert detection._ollama_reported_gb() == pytest.approx(12.0)+++def test_a_rotated_or_missing_log_is_simply_no_answer(+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path+) -> None:+ """The line is written once per server start and rotates away with the log,+ so absence is the normal case, not a failure."""+ monkeypatch.setattr(detection, "_ollama_log_paths", lambda: [tmp_path / "gone.log"])+ assert detection._ollama_reported_gb() == 0.0+ _log_with(monkeypatch, tmp_path, "")+ assert detection._ollama_reported_gb() == 0.0+++# ── Source precedence ────────────────────────────────────────────────────+++def test_nvidia_is_asked_first(monkeypatch: pytest.MonkeyPatch) -> None:+ """It is the leg verified on real hardware; a best-effort source must not+ displace it."""+ monkeypatch.setattr(+ detection, "_detect_nvidia_gpus", lambda: [detection.GPUInfo(name="RTX", vram_mb=16384)]+ )+ monkeypatch.setattr(detection, "_ollama_reported_gb", lambda: 99.0)+ assert detection.usable_accelerator_gb() == (16.0, "nvidia-smi")+++def test_an_amd_card_is_read_where_nvidia_smi_sees_nothing(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The defect this source exists for: a 16 GB Radeon used to report 0, and+ every fit verdict fell back to the system-RAM rule."""+ _no_nvidia(monkeypatch)+ monkeypatch.setattr(detection, "_ollama_reported_gb", lambda: 16.0)+ assert detection.usable_accelerator_gb() == (16.0, "ollama-runtime")+++def test_the_os_inventory_answers_when_no_server_has_run(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A first-run box has no Ollama log yet, and the fit verdicts are needed+ before anything is downloaded. Patched at the source-selection seam so the+ assertion holds on whichever OS runs the suite."""+ _no_nvidia(monkeypatch)+ monkeypatch.setattr(detection, "_vendor_neutral_gb", lambda: (12.0, "windows-registry"))+ assert detection.usable_accelerator_gb() == (12.0, "windows-registry")+++def test_the_os_inventory_is_only_consulted_after_the_server_record(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The server's own figure is the budget it will USE; the OS inventory only+ reports what the card HAS, so it is the weaker of the two."""+ monkeypatch.setattr(detection, "_ollama_reported_gb", lambda: 10.0)+ monkeypatch.setattr(detection, "_windows_registry_vram_gb", lambda: 16.0)+ monkeypatch.setattr(detection, "_linux_drm_vram_gb", lambda: 16.0)+ assert detection._vendor_neutral_gb() == (10.0, "ollama-runtime")+++def test_apple_silicon_reports_its_unified_memory(monkeypatch: pytest.MonkeyPatch) -> None:+ """The GPU shares system memory there, so RAM is the figure — the branch+ that had never been executed by a test."""+ _no_nvidia(monkeypatch)+ _no_vendor_sources(monkeypatch)+ monkeypatch.setattr(detection.sys, "platform", "darwin")+ monkeypatch.setattr(detection.platform, "machine", lambda: "arm64")+ monkeypatch.setattr(detection, "_detect_ram", lambda: (32768, 16384))+ assert detection.usable_accelerator_gb() == (32.0, "apple-unified")+++def test_a_metal_budget_beats_the_ram_guess_on_a_mac(monkeypatch: pytest.MonkeyPatch) -> None:+ """macOS gives the GPU only part of the unified memory. When Ollama has+ already named the real budget, that is the better answer than total RAM."""+ _no_nvidia(monkeypatch)+ monkeypatch.setattr(detection, "_ollama_reported_gb", lambda: 21.3)+ monkeypatch.setattr(detection.sys, "platform", "darwin")+ monkeypatch.setattr(detection.platform, "machine", lambda: "arm64")+ monkeypatch.setattr(detection, "_detect_ram", lambda: (32768, 16384))+ assert detection.usable_accelerator_gb() == (21.3, "ollama-runtime")+++def test_a_box_with_nothing_readable_says_so_and_does_not_guess(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """0 with source "none" means UNKNOWN accelerator, never "no memory":+ system RAM still runs the model, and the fit verdict says exactly that."""+ _no_nvidia(monkeypatch)+ _no_vendor_sources(monkeypatch)+ monkeypatch.setattr(detection.sys, "platform", "linux")+ assert detection.usable_accelerator_gb() == (0.0, "none")+++def test_a_failing_source_never_breaks_the_probe(monkeypatch: pytest.MonkeyPatch) -> None:+ """A locked-down registry or an unreadable log is a normal machine."""++ def _boom() -> float:+ raise OSError("permission denied")++ _no_nvidia(monkeypatch)+ monkeypatch.setattr(detection, "_ollama_reported_gb", _boom)+ monkeypatch.setattr(detection.sys, "platform", "linux")+ assert detection.usable_accelerator_gb() == (0.0, "none")+++# ── The realtime speech stack narrows the same probe ──────────────────────+++def test_the_voice_stack_refuses_a_card_it_has_no_backend_for(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The shared probe now reads AMD and Intel cards for the local-model fit+ verdicts. The realtime speech stack maps any non-NVIDIA source to `mps`, so+ letting one through would clear the memory floor and then launch with a+ torch device that does not exist on the box — worse than the honest+ "no supported accelerator" refusal it gives today (os-parity P-28)."""+ from jarvis.realtime.local_server import preflight++ monkeypatch.setattr(+ "jarvis.hardware.detection.usable_accelerator_gb", lambda: (16.0, "windows-registry")+ )+ assert preflight._usable_accelerator_gb() == (0.0, "none")++[email protected](("source", "gb"), [("nvidia-smi", 16.0), ("apple-unified", 32.0)])+def test_the_voice_stack_still_takes_the_two_sources_it_can_drive(+ monkeypatch: pytest.MonkeyPatch, source: str, gb: float+) -> None:+ from jarvis.realtime.local_server import preflight++ monkeypatch.setattr("jarvis.hardware.detection.usable_accelerator_gb", lambda: (gb, source))+ assert preflight._usable_accelerator_gb() == (gb, source)