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
feat(realtime): gate the TTS-server spawn on FREE accelerator memory
rubenluetke10-beepa3d8bc978530
diff --git a/docs/os-parity.md b/docs/os-parity.mdindex 9c015b3748..d2d1d4081a 100644--- a/docs/os-parity.md+++ b/docs/os-parity.md@@ -260,6 +260,9 @@ experiences today.| P-37 | Low | Dev instance | A second desktop app from the same checkout (`--instance dev` / `JARVIS_INSTANCE=dev`, see `docs/dev-instance.md`) is built OS-neutral — own `data-dev/`, ports +100, own single-instance lock, window title, DEV-badged icon, no wake word / global hotkeys / chat channels / autostart / on-screen overlay (the dev app boots the NullOverlay at runtime and its overlay-style route answers 409, so a pick there can never rewrite the shared `jarvis.toml`) — but only the WINDOWS identity layer has been run live: AUMID `PersonalJarvis.PersonalJarvis.Dev`, Start-Menu shortcut `Personal Jarvis Dev.lnk`, branded `PersonalJarvisDev.exe`, tray tooltip. Linux gets its own `.desktop` entry + `StartupWMClass` through the same code path (unverified live). macOS has NO separate bundle for the dev instance: the dock shows the default app's bundle icon, and an in-app restart of the dev instance re-enters through the interpreter directly (`build_launch_command` skips the LaunchServices bundle for a non-default instance, because `open -a` would not carry `JARVIS_INSTANCE` and would bring it back as a second default app) — so the restarted dev app has no TCC attachment of its own | `jarvis/core/instance.py`, `jarvis/ui/icon_utils.py` (instance-bound constants), `jarvis/ui/relauncher.py::build_launch_command` | Windows: full parity, verified live. Linux desktop: expected parity (title, icon, tray, data, ports), entry unverified. macOS: functional (data, ports, title, ambient duties, in-app restart), dock icon degrades as described — the dev window is still told apart by its title and the DEV tag in the sidebar |+| P-40 | Low | Local realtime | The spawn-time FREE-accelerator-memory gate (2026-09-01, BUG-204's unfixed half) reads free VRAM only through NVIDIA tooling (NVML, else `nvidia-smi memory.free`). Apple unified memory and ROCm have no cheap free-memory reading here, so those hosts answer `(0.0, "none")` = *unknown* — and an unknown reading deliberately ALLOWS the spawn (AP-22: refusing on a number nobody can read would brick every non-NVIDIA box; the install preflight already vouched for the hardware class) | `jarvis/hardware/detection.py::free_accelerator_gb`, `jarvis/realtime/local_server/supervisor.py::_accelerator_memory_refusal`, `tests/contract/test_accelerator_memory_probe.py` | NVIDIA hosts (all OSes): a card provably too full refuses with one honest log line and the hosted fallback takes the call. macOS/ROCm: unchanged behaviour — the gate is a no-op there by design, recorded here so nobody "fixes" the asymmetry by inventing a free-memory number |+| P-41 | Info | Process priority | Autostart process priority is a WINDOWS-only defect class: Task Scheduler's default (7) started the whole tree BelowNormal (BUG-210); the fix (`-Priority 5` + raise-only `ensure_normal_process_priority`) is capability-gated and a quiet no-op elsewhere. macOS LaunchAgents already run `ProcessType=Interactive` (`jarvis/autostart/macos.py`) and Linux XDG autostart is not niced — neither OS needs, nor gets, a priority write. The JarvisBar loop-waker (BUG-202) stays Windows-only for the same shape of reason: the lost-timer sleep is a Tcl *Windows notifier* failure mode; X11/Aqua notifiers wait on a socket/run loop and have never shown it (`jarvis/core/process_utils.py::thread_message_loop_wake_supported`) | `jarvis/autostart/windows.py`, `jarvis/core/process_utils.py::ensure_normal_process_priority` | macOS/Linux: nothing to repair, nothing written. A future report of a frozen Linux bar should be diagnosed fresh (py-spy), never "fixed" by porting the WM_NULL waker to a platform whose notifier cannot lose timers that way |+## Native installers (added 2026-08-25)Personal Jarvis is downloadable as a native installer on all three systems,diff --git a/jarvis/hardware/detection.py b/jarvis/hardware/detection.pyindex b294d5061c..845e0d4a0d 100644--- a/jarvis/hardware/detection.py+++ b/jarvis/hardware/detection.py@@ -742,6 +742,50 @@ def _probe_accelerator_gb() -> tuple[float, str]:return 0.0, "none"+def free_accelerator_gb() -> tuple[float, str]:+ """FREE accelerator memory in GiB right now, and where the figure came from.++ ``(gb, source)`` with source ``"nvml"`` | ``"nvidia-smi"`` | ``"none"``.+ ``(0.0, "none")`` means *unknown* — no NVIDIA tooling answered — and a+ caller must treat it as "cannot vouch for free memory", never as "the card+ is full": Apple's unified memory and ROCm have no cheap free-memory reading+ here, and refusing to spawn on an unknowable number would turn every such+ box into a brick (AP-22 shape).++ Deliberately UNCACHED, unlike :func:`usable_accelerator_gb`: free memory+ moves with every model load/unload, and the one caller that needs it (the+ local-realtime spawn gate) asks at most once per spawn attempt, which the+ supervisor already rate-limits. The LARGEST single device's free figure,+ matching the total probe's one-GPU-runs-inference rule.+ """+ try:+ import pynvml # type: ignore[import-untyped]++ pynvml.nvmlInit()+ try:+ free_mb = 0+ for i in range(pynvml.nvmlDeviceGetCount()):+ handle = pynvml.nvmlDeviceGetHandleByIndex(i)+ mem = pynvml.nvmlDeviceGetMemoryInfo(handle)+ free_mb = max(free_mb, int(mem.free) // (1024 * 1024))+ finally:+ pynvml.nvmlShutdown()+ if free_mb > 0:+ return free_mb / 1024.0, "nvml"+ except Exception: # noqa: BLE001 — no pynvml / no driver is a normal state+ log.debug("hardware: NVML free-memory probe unavailable", exc_info=True)+ out = _run(["nvidia-smi", "--query-gpu=memory.free", "--format=csv,noheader,nounits"])+ free_mb = 0+ for line in out.strip().splitlines():+ try:+ free_mb = max(free_mb, int(line.strip()))+ except ValueError:+ continue+ if free_mb > 0:+ return free_mb / 1024.0, "nvidia-smi"+ return 0.0, "none"++def system_ram_gb() -> float | None:"""Total system memory in GiB, or ``None`` when it cannot be read.diff --git a/jarvis/realtime/local_server/supervisor.py b/jarvis/realtime/local_server/supervisor.pyindex 70765c2e05..1ebb8bc8d3 100644--- a/jarvis/realtime/local_server/supervisor.py+++ b/jarvis/realtime/local_server/supervisor.py@@ -171,7 +171,10 @@ VOICE_BRAIN_CONTEXT_TOKENS_FLOOR = 8192#: instructions, the transcript and the answer, so the cache survives the call.VOICE_BRAIN_DECLARATION_SHARE = 0.25#: Accelerator memory kept free for the local STT + TTS models beside the brain.-VOICE_STACK_RESERVE_GB = 4.0+#: Measured, not guessed (BUG-204 forensics 2026-08-28): the Qwen3-TTS server+#: alone holds ~5.4 GB plus CUDA-graph warm-up headroom; the old 4.0 was+#: smaller than the TTS by itself, so the reserve never actually reserved.+VOICE_STACK_RESERVE_GB = 6.0#: Historical name of the floor; readers that only need "some bound" keep it.VOICE_BRAIN_CONTEXT_TOKENS = VOICE_BRAIN_CONTEXT_TOKENS_FLOOR_VOICE_MODEL_SUFFIX_RE = re.compile(r"-voice-(\d+)k$")@@ -1210,6 +1213,47 @@ def _local_models_switched_off() -> str:return "refused:local-models-off"+def _accelerator_memory_refusal() -> str:+ """``"refused:accelerator-memory"`` when the card provably cannot take the+ stack, ``""`` when it can — or when free memory is UNKNOWN.++ BUG-204's unfixed half: nothing ever checked FREE memory before spawning+ the multi-GB TTS server, so on a card already holding the voice brain and+ the desktop the spawn oversubscribed VRAM and the whole machine dropped to+ 1 FPS. The gate asks for :data:`VOICE_STACK_RESERVE_GB` of free memory —+ the measured STT+TTS footprint — right before the spawn (after the orphan+ sweep, so a killed stale server's memory already counts as free).++ An unknown reading (no NVIDIA tooling — Apple unified memory, ROCm, a+ locked-down host) allows the spawn: refusing on a number nobody can read+ would brick every such box (AP-22), and the install-time preflight already+ vouched for the hardware class. The refusal is capability-shaped, so the+ caller's normal fallback chain (hosted realtime) takes over — degrading+ honestly instead of freezing the desktop.+ """+ try:+ from jarvis.hardware.detection import free_accelerator_gb # lazy (AP-26)++ free_gb, source = free_accelerator_gb()+ except Exception: # noqa: BLE001 — a broken probe must never veto the spawn+ log.debug("supervisor: free-memory probe failed", exc_info=True)+ return ""+ if source == "none" or free_gb <= 0.0:+ return ""+ if free_gb >= VOICE_STACK_RESERVE_GB:+ return ""+ log.warning(+ "local-realtime supervisor: not spawning — only %.1f GB of accelerator "+ "memory is free (%s) and the voice stack needs ~%.1f GB. The hosted "+ "fallback takes this call; free the card (or stop other models) to "+ "run locally.",+ free_gb,+ source,+ VOICE_STACK_RESERVE_GB,+ )+ return "refused:accelerator-memory"++def ensure_running(*,launch_command: str,@@ -1383,6 +1427,9 @@ def ensure_running("local-realtime supervisor: removed %s orphan process(es) before spawn",killed,)+ refused = _accelerator_memory_refusal()+ if refused:+ return refusedtry:command = prepare_voice_brain_command(command)except RuntimeError as exc:diff --git a/tests/contract/test_accelerator_memory_probe.py b/tests/contract/test_accelerator_memory_probe.pynew file mode 100644index 0000000000..11f0aed00c--- /dev/null+++ b/tests/contract/test_accelerator_memory_probe.py@@ -0,0 +1,91 @@+"""Contract of the free-accelerator-memory capability.++Every consumer (today: the local-realtime spawn gate) relies on exactly this+shape: a non-negative ``(gb, source)`` tuple, ``(0.0, "none")`` for *unknown*+— never a raise, never a negative, never an invented number on a host with no+NVIDIA tooling (Apple unified memory, ROCm, locked-down boxes). The spawn+gate's own contract: a provable shortage refuses, an UNKNOWN reading never+does (AP-22 — refusing on a number nobody can read bricks every non-NVIDIA+box).+"""++from __future__ import annotations++import builtins++import pytest++from jarvis.hardware import detection+from jarvis.realtime.local_server import supervisor++_ALLOWED_SOURCES = {"nvml", "nvidia-smi", "none"}+++def test_probe_answers_the_contract_shape_on_this_host() -> None:+ free_gb, source = detection.free_accelerator_gb()+ assert isinstance(free_gb, float)+ assert free_gb >= 0.0+ assert source in _ALLOWED_SOURCES+ if source == "none":+ assert free_gb == 0.0+++def test_probe_reports_unknown_not_an_error_without_nvidia_tooling(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ real_import = builtins.__import__++ def _no_pynvml(name: str, *args: object, **kwargs: object) -> object:+ if name == "pynvml":+ raise ImportError("no pynvml on this host")+ return real_import(name, *args, **kwargs) # type: ignore[arg-type]++ monkeypatch.setattr(builtins, "__import__", _no_pynvml)+ monkeypatch.setattr(detection, "_run", lambda _cmd: "")++ assert detection.free_accelerator_gb() == (0.0, "none")+++def test_probe_parses_the_nvidia_smi_fallback(monkeypatch: pytest.MonkeyPatch) -> None:+ real_import = builtins.__import__++ def _no_pynvml(name: str, *args: object, **kwargs: object) -> object:+ if name == "pynvml":+ raise ImportError("no pynvml")+ return real_import(name, *args, **kwargs) # type: ignore[arg-type]++ monkeypatch.setattr(builtins, "__import__", _no_pynvml)+ # Two cards: the largest single device wins, matching the total probe.+ monkeypatch.setattr(detection, "_run", lambda _cmd: "1024\n8192\n")++ assert detection.free_accelerator_gb() == (8.0, "nvidia-smi")+++class TestSpawnGateContract:+ def test_a_provable_shortage_refuses(self, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(detection, "free_accelerator_gb", lambda: (1.3, "nvml"))+ assert supervisor._accelerator_memory_refusal() == "refused:accelerator-memory" # noqa: SLF001++ def test_enough_free_memory_allows(self, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(+ detection,+ "free_accelerator_gb",+ lambda: (supervisor.VOICE_STACK_RESERVE_GB + 0.1, "nvml"),+ )+ assert supervisor._accelerator_memory_refusal() == "" # noqa: SLF001++ def test_unknown_free_memory_never_refuses(self, monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(detection, "free_accelerator_gb", lambda: (0.0, "none"))+ assert supervisor._accelerator_memory_refusal() == "" # noqa: SLF001++ def test_a_broken_probe_never_vetoes_the_spawn(self, monkeypatch: pytest.MonkeyPatch) -> None:+ def _boom() -> tuple[float, str]:+ raise RuntimeError("driver went away")++ monkeypatch.setattr(detection, "free_accelerator_gb", _boom)+ assert supervisor._accelerator_memory_refusal() == "" # noqa: SLF001++ def test_the_reserve_now_covers_the_measured_tts_footprint(self) -> None:+ # BUG-204: Qwen3-TTS alone holds ~5.4 GB; a reserve below that never+ # actually reserved anything.+ assert supervisor.VOICE_STACK_RESERVE_GB >= 5.4diff --git a/tests/unit/realtime/local_server/test_voice_brain_context.py b/tests/unit/realtime/local_server/test_voice_brain_context.pyindex b2c6f980ea..68b01eeea0 100644--- a/tests/unit/realtime/local_server/test_voice_brain_context.py+++ b/tests/unit/realtime/local_server/test_voice_brain_context.py@@ -65,13 +65,17 @@ def test_ladder_helper_is_capped_by_native_window_and_budget() -> None:assert largest_context_for(size_gb=3.4, native_context=None, budget_gb=None) == 4096-def test_a_16gb_card_gets_a_64k_voice_context(monkeypatch) -> None:+def test_a_16gb_card_gets_a_32k_voice_context(monkeypatch) -> None:+ # 15.9 GB minus the MEASURED 6 GB STT/TTS reserve (BUG-204: the TTS alone+ # holds ~5.4 GB; the old 4 GB reserve never actually reserved) leaves+ # 9.9 GB — the 64k rung (11.1 GB) no longer pretends to fit beside the+ # voice stack, the 32k rung does._fake_ollama(monkeypatch, size_bytes=3_400_000_000, native=262_144, created=[])monkeypatch.setattr("jarvis.hardware.detection.usable_accelerator_gb", lambda: (15.9, "nvidia-smi"))tokens, why = supervisor.voice_brain_context_tokens("http://127.0.0.1:11434", "qwen3.5:4b")- assert tokens == 65_536+ assert tokens == 32_768assert "reserved for local STT/TTS" in why@@ -99,7 +103,7 @@ def test_no_accelerator_uses_the_ram_rule(monkeypatch) -> None:monkeypatch.setattr("jarvis.hardware.detection.usable_accelerator_gb", lambda: (0.0, "none"))monkeypatch.setattr("jarvis.hardware.detection.system_ram_gb", lambda: 32.0)tokens, why = supervisor.voice_brain_context_tokens("http://127.0.0.1:11434", "qwen3.5:4b")- # 60 % of 32 GB minus the 4 GB reserve = 15.2 GB -> the 64k rung fits (11.1 GB).+ # 60 % of 32 GB minus the 6 GB reserve = 13.2 GB -> the 64k rung fits (11.1 GB).assert tokens == 65_536assert "RAM" in why@@ -115,8 +119,8 @@ def test_prepare_creates_an_alias_named_after_the_chosen_context(monkeypatch) ->"--responses_api_base_url http://127.0.0.1:11434/v1 --responses_api_api_key ollama")out = supervisor.prepare_voice_brain_command(command)- assert "qwen3.5:4b-voice-64k" in out- assert created and created[0]["parameters"] == {"num_ctx": 65_536}+ assert "qwen3.5:4b-voice-32k" in out+ assert created and created[0]["parameters"] == {"num_ctx": 32_768}assert created[0]["from"] == "qwen3.5:4b"