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(dictation): read the final pass on-device, out of process, in front of the cloud chain
rubenluetke10-beepaefe01672bd1
diff --git a/docs/os-parity.md b/docs/os-parity.mdindex f7fa334b3f..b7137620f1 100644--- a/docs/os-parity.md+++ b/docs/os-parity.md@@ -295,6 +295,7 @@ shortcuts it never created. Covered by| P-38 | Medium | Native installer / desktop window | The Linux AppImage and `.deb` have **no native desktop window**. Windows (WebView2) and macOS (WKWebView) get one from the frozen bundle; Linux does not, because pywebview's GTK backend needs PyGObject and a frozen interpreter can never import the distribution's `python3-gi` (it is compiled against the system CPython), while bundling GTK 3 + WebKit2GTK portably means shipping its helper processes, GIO modules, pixbuf loaders, GSettings schemas and typelibs. The Qt route is also closed today: the `[desktop]` extra installs `pyside6-essentials`, which has no QtWebEngine, and `jarvis.spec` excludes PySide6 outright. Adding `pyside6-addons` and dropping that exclusion is the realistic fix, at roughly +400 MB | `packaging/linux/README.md` ("The window question"), `jarvis/ui/desktop_app.py::_degrade_to_browser_ui`, `jarvis.spec` `excludes`, `pyproject.toml` `[desktop]` | Linux: honest degradation, verified against a real build — the app catches pywebview's `WebViewException`, keeps the backend serving, and `AppRun` waits for `/api/health` and opens the interface with `xdg-open`. Everything except the window frame works, including the whole CLI. A source/pipx install on a Linux desktop with `python3-gi` + `gir1.2-webkit2-4.1` still gets the native window; only the frozen build does not. Sub-gap: the app's fallback message advises installing those system packages, which does not help a frozen build || P-39 | Medium | Dictation hold-key watchdog | A HOLD-started dictation is owed a release edge, and that edge can be lost between the OS hotkey listener and the pipeline (a checker restart mid-hold, a re-arm, a handler that raised). The recording then ran to its 30-minute cap with the bar's X dead and every key press refused (BUG-191). The repair asks the keyboard instead of trusting edges: `HotkeyBackend.chord_is_down(combo)` is a three-way capability — `True`/`False` when the backend can see the keyboard, `None` when it cannot — and the recording finishes itself once the chord has read "up" for one second. The three OS backends can see different amounts: Windows reads `GetAsyncKeyState` (ground truth, the poller's own source); macOS answers from the event tap's held-set, whose modifier half is re-synced from every event's flags word; Linux/X11 answers from pynput's held-set, which is edge-fed like the matcher itself | `jarvis/trigger/backends/__init__.py::HotkeyBackend.chord_is_down`, `backends/global_hotkeys.py::chord_is_down`, `backends/quartz.py::chord_is_down`, `backends/pynput.py::chord_is_down`, `backends/noop.py`, `jarvis/speech/pipeline.py::_watch_dictation_hold_key`, `tests/contract/test_hotkey_backend_protocol.py` | Windows: the watchdog sees the physical key and ends a lost-release recording within ~1 s. macOS / Linux-X11: the watchdog runs on the listener's own bookkeeping — it catches a release the pipeline missed, not one the listener itself missed. Wayland / no listener: the backend answers `None`, the watchdog stands down, and the other stop gestures carry alone — the key (a press during a running dictation is its stop), the bar's X, the Dictation view, `jarvis api dictation stop`. On no host does `None` ever read as "up": a phantom release is the one failure this must never produce || P-40 | Low | JarvisBar | The Prompt Mode switch (`[dictation].prompt_mode`, every dictation comes out as a written prompt) is a control on the native bar since 2026-08-28: a sparkle in the resting pill's left slot, drawn ONLY while the SETTING is on (visible without a hover — the pill opens as it does for mute). A click PAUSES the rewriting rather than changing the setting: the mark goes red with a slash through it, jarvis.toml is untouched, and the same click brings it back. The pause is runtime-only and clears on restart or on any write of the setting. With the setting off nothing is drawn there and the spot starts a session as before. The glyph mirrors the mic's inset rather than the close-X's, which is left untouched on a live bar. The switch has ONE writer (`jarvis/dictation/prompt_mode_switch.py`) and one broadcast (`DictationPromptModeChanged`) that the bar, the front-page pill and the settings card all redraw from | `jarvis/ui/jarvisbar/renderer.py::_draw_sparkle`, `interaction.py::resolve_click` (`prompt_mode_toggle`), `overlay.py` / `qt_overlay.py` / `subprocess_overlay.py` (`set_prompt_mode`, `set_on_prompt_mode_toggle`), `host.py` (op `set_prompt_mode`, event `prompt_mode_toggle`), `ui/orb/bus_bridge.py` | Windows/Linux (Tk bar, in-process) and macOS (Qt bar in the companion host, over the existing IPC protocol): the same sparkle, the same click, the same event. Headless / `orb_style = none`: the NullOverlay accepts both methods as no-ops; the pill on the front page and the settings card remain the switch. Guards: `tests/unit/ui/jarvisbar/test_prompt_mode_button.py`, `test_prompt_mode_bridge.py`, `test_surface_contract.py`, `test_host_protocol.py` |+| P-41 | Medium | Dictation final pass | The dictation lane reads its final pass on the machine, in front of any configured cloud provider, through the same out-of-process worker the live preview uses (`jarvis.dictation.preview_worker`) with a stronger checkpoint (`[dictation].local_model`, default `large-v3-turbo`, `int8_float16`, beam 5). 2026-09-02 forensics: 220 of 220 dictations had run on a cloud recognizer the settings did not name, because the VOICE lane had been moved there to keep CUDA out of the desktop process, and the dictation lane inherited the move — round-trips as lag, near-empty answers on 25 s windows as "truncated window" repairs. The provider declines itself with a CROSSABLE failure (HTTP-503-shaped, `LocalEngineUnavailable`) so the configured provider is one step behind on every press and never a restart away: too little free accelerator memory (`[dictation].local_min_free_gb`, default 1.5; an UNKNOWN reading never blocks), a worker that only comes up on the CPU, a missing local runtime, a worker that died. A call abandoned at its ceiling leaves its answer in the pipe, so the next call kills that worker instead of reading it (AP-24) | `jarvis/dictation/local_final.py::LocalFinalSTT`, `jarvis/speech/pipeline.py::_dictation_local_final`, `_dictation_stt`, `jarvis/dictation/local_preview.py::_spawn_worker_model` (`compute`), `preview_worker.py` (`beam_size`, `segments`), `jarvis/hardware/detection.py::free_accelerator_gb` | Windows/Linux with an NVIDIA card and the local runtime: the final pass runs locally when ≥ 1.5 GB is free, else the cloud chain. macOS: no NVIDIA reading → the memory gate passes as unknown, and the worker's own device ladder decides; a CPU-only worker is declined for the final pass (a beam decode of a 25 s window on a CPU is slower than the cloud it would replace), so Apple Silicon stays on the configured provider until a Metal-backed runtime exists. Headless `python:3.11-slim` (no `faster-whisper`): the provider is never built and the chain is exactly what it was. Switch: `[dictation].local_engine = false`. Guards: `tests/unit/dictation/test_local_final.py`, `test_preview_worker.py` || P-41 | Low | CLI install / connect terminal | Pressing **Install** or **Connect** in the CLI section opens a REAL terminal window and runs the command there, because an interactive OAuth login belongs in a shell the user can see and type into. That spawn was Windows-only until 2026-08-28 (`wt` -> `pwsh` -> `powershell`), so on macOS and Linux the two buttons reported "No external terminal available" and no CLI could be installed from the app at all. macOS now goes through `osascript` to Terminal.app, Linux through the first of seven emulators that exists (Debian's `x-terminal-emulator` alternative first, so the user's own default wins), and the window is held open afterwards the way `-NoExit` holds it on Windows. One install click now carries all the way to signed in: the terminal runs the install, refreshes PATH in that same shell, and continues into the CLI's login command, stopping at the first step that fails. The chain operator differs per OS on purpose — Windows PowerShell 5.1 is a possible fallback shell and `&&` is a parser error there, so the Windows spelling nests `if ($?)` instead | `jarvis/clis/external_terminal.py` (`_spawn_windows`, `_spawn_macos`, `_spawn_linux`, `chain_commands`, `path_refresh_command`), `jarvis/ui/web/cli_routes.py::spawn_external`, `tests/unit/clis/test_install_path.py` | Windows: verified live (wt path, composed install+login command). macOS/Linux: same code path, the branch itself unverified from this machine. A box with no screen has no window to open, so there the endpoint falls back to the in-app streaming install job and the UI says so instead of claiming a terminal appeared — a headless server can still install a CLI, it just cannot run an interactive login |## Maintenancediff --git a/jarvis/core/config.py b/jarvis/core/config.pyindex 4d0d1c0fe5..ddfbdae685 100644--- a/jarvis/core/config.py+++ b/jarvis/core/config.py@@ -3540,6 +3540,25 @@ class DictationConfig(BaseModel):#: recovering half a word is not. ``0`` disables the overlap.final_overlap_seconds: float = Field(default=1.5, ge=0.0, le=5.0)+ #: Read the final pass on THIS machine, in a worker process, before any+ #: configured cloud provider — when the local speech engine is installed+ #: and the card has room. The worker declines itself (full card, CPU-only+ #: host, missing runtime) with a crossable failure, so the configured+ #: provider is one step behind on every press. Off = the configured+ #: provider is in front, as before.+ local_engine: bool = True++ #: faster-whisper checkpoint for the local final pass. ``large-v3-turbo``+ #: is the accuracy of ``large-v3`` at a fraction of the decode time and+ #: ~1 GB of accelerator memory. Independent of ``[stt].model``, which the+ #: voice lane owns.+ local_model: str = "large-v3-turbo"++ #: Free accelerator memory the local final pass needs before it starts;+ #: below it the configured provider takes the dictation. ``0`` skips the+ #: check. Unknown free memory (no NVIDIA tooling) never blocks the start.+ local_min_free_gb: float = Field(default=1.5, ge=0.0, le=64.0)+#: Allow the language to change WITHIN one dictation.#:#: While this is on (the default), the final pass asks the recognizer todiff --git a/jarvis/core/config_writer.py b/jarvis/core/config_writer.pyindex de5542c0c7..34606a1ed4 100644--- a/jarvis/core/config_writer.py+++ b/jarvis/core/config_writer.py@@ -867,6 +867,9 @@ DICTATION_SETTING_KEYS = ("final_quality_pass","final_window_seconds","final_overlap_seconds",+ "local_engine",+ "local_model",+ "local_min_free_gb","code_switching","history_enabled","history_max_entries",diff --git a/jarvis/dictation/local_final.py b/jarvis/dictation/local_final.pynew file mode 100644index 0000000000..ae17dee376--- /dev/null+++ b/jarvis/dictation/local_final.py@@ -0,0 +1,358 @@+"""The dictation lane's on-device final-pass recognizer, hosted out of process.++Why this exists (2026-09-02 forensics, 220 dictations over four days): every+one of them ran on a cloud Whisper although the settings named the local+engine, because a user-scope environment override had moved the VOICE lane to+the cloud — deliberately, to keep the CUDA DLL load and a second large model+out of the desktop process (the 15-30 s loader-lock freezes of BUG-189 and+the VRAM oversubscription of BUG-204). The cloud round-trip was the lag the+user felt, and the cloud model's near-empty answers on 25 s windows were the+"truncated window" repairs that doubled it.++The dictation lane does not need the voice lane's provider at all. It needs a+strong local model that never touches this process's loader lock or VRAM+budget on its own — which is exactly the shape the live-preview worker already+has (:mod:`jarvis.dictation.preview_worker`). This module reuses that worker+with a stronger checkpoint and beam search, and presents it as an ordinary+``transcribe_pcm`` provider so the existing cross-family chain+(:class:`jarvis.speech.stt_fallback.FallbackSTT`) can put it IN FRONT of the+configured cloud provider:++* the worker builds off the press path (``warm_up`` after boot) and, failing+ that, on the first press;+* a card without enough free memory, a host whose worker only comes up on+ the CPU, a missing local runtime or a wedged worker all raise a CROSSABLE+ failure, so the chain moves to the cloud for that call and comes back+ later — no press is ever lost to the local engine being unavailable;+* a call that outlives its ceiling leaves a response in the pipe; the next+ call kills the worker rather than reading someone else's answer (AP-24:+ a wedged native engine is recovered by replacing it, never by waiting).++Nothing here is Windows-specific: the worker is our own interpreter running+our own module, the free-memory probe reports "unknown" where there is no+NVIDIA tooling (and unknown ALLOWS the spawn, AP-22 shape), and a worker that+comes up on the CPU is declined because a beam-search turbo decode of a 25 s+window on a CPU is slower than the cloud it would replace.+"""++from __future__ import annotations++import asyncio+import logging+import threading+import time+from typing import Any++from jarvis.core.protocols import Transcript++log = logging.getLogger(__name__)++#: Checkpoint the final pass decodes with when the user has not chosen one.+#: ``large-v3-turbo`` is the accuracy of ``large-v3`` at a fraction of the+#: decode time and ~1 GB of VRAM at ``int8_float16``.+DEFAULT_FINAL_MODEL = "large-v3-turbo"++#: Compute type asked of the worker on CUDA. ``int8_float16`` halves the+#: weights against ``float16`` at no measurable accuracy cost, which matters+#: on a card that already holds the wake model, a local voice brain and the+#: local TTS server.+FINAL_COMPUTE = "int8_float16"++#: Beam width for the final pass. The preview decodes greedily (latency); the+#: final pass is read once after release and can afford the search.+FINAL_BEAM_SIZE = 5++#: Free accelerator memory the spawn asks for by default — the turbo weights+#: plus a CUDA context, with a little headroom.+DEFAULT_MIN_FREE_GB = 1.5++#: How long a refused or failed spawn is remembered before the next call may+#: try again. Free memory moves with every model load, so the door is not+#: closed for the process — but probing the card on every press would turn+#: a full card into a slow cloud.+_RETRY_AFTER_S = 60.0+++class LocalEngineUnavailable(RuntimeError):+ """The on-device final pass cannot take this call; another provider may.++ Carries ``status = 503`` so :func:`jarvis.speech.stt_failure.classify_stt_failure`+ reads it as ``unavailable`` — the crossable class — without this module+ importing the classifier or the classifier learning a new marker. A+ dictation must never end because the LOCAL engine is missing; the cloud+ behind it in the chain takes the call.+ """++ status = 503+++class LocalFinalSTT:+ """``transcribe_pcm`` provider whose decodes run in the dictation worker.++ Built once per pipeline and kept; the worker process it owns is spawned+ lazily (``warm_up`` off-path, else the first call) and replaced whenever+ it fails. Not safe for concurrent calls by design — the chain in front of+ it serialises callers because ``supports_concurrent_requests`` is False.+ """++ supports_concurrent_requests = False+ runs_on_device = True++ def __init__(+ self,+ model_name: str = DEFAULT_FINAL_MODEL,+ *,+ min_free_gb: float = DEFAULT_MIN_FREE_GB,+ compute: str = FINAL_COMPUTE,+ beam_size: int = FINAL_BEAM_SIZE,+ ) -> None:+ self._model_name = str(model_name or DEFAULT_FINAL_MODEL).strip()+ self._min_free_gb = max(0.0, float(min_free_gb))+ self._compute = compute+ self._beam_size = max(1, int(beam_size))+ self._worker: Any = None+ self._device = ""+ self._engine_compute = ""+ self._spawn_lock = threading.Lock()+ self._call_lock = threading.Lock()+ self._next_attempt_at = 0.0+ self._last_refusal = ""++ # ------------------------------------------------------------------+ # Identity — read by the chain, the history row and the health panel+ # ------------------------------------------------------------------++ @property+ def name(self) -> str:+ return "faster-whisper"++ @property+ def provider_label(self) -> str:+ return "faster-whisper"++ @property+ def last_used_model(self) -> str:+ return self._model_name++ @property+ def is_warm(self) -> bool:+ return self._worker is not None++ @property+ def device(self) -> str:+ """``"cuda"`` / ``"cpu"`` of the live worker, ``""`` without one."""+ return self._device++ @property+ def unavailable_reason(self) -> str:+ """Why the last spawn was declined, for the log and the status card."""+ return self._last_refusal++ # ------------------------------------------------------------------+ # Lifecycle+ # ------------------------------------------------------------------++ def warm_up(self) -> None:+ """Spawn the worker off the press path. BLOCKING — call from a thread.++ Quiet when the host declines: the reason is logged once and the first+ press asks again after :data:`_RETRY_AFTER_S`. Raising here would only+ turn a full card into a warning nobody can act on.+ """+ self._ensure_worker()++ def recover(self) -> None:+ """Drop the worker so the next call starts a fresh one (AP-24)."""+ with self._spawn_lock:+ self._drop_worker_locked()+ self._next_attempt_at = 0.0++ def close(self) -> None:+ self.recover()++ # ------------------------------------------------------------------+ # Transcription+ # ------------------------------------------------------------------++ async def transcribe_pcm(+ self,+ pcm_bytes: bytes,+ sample_rate: int = 16_000,+ language: str | None = None,+ ) -> Transcript:+ """int16 PCM bytes → transcript, decoded in the worker.++ A second caller while one is in flight means the previous call was+ abandoned at its ceiling and its answer is still in the pipe; that+ worker is replaced rather than read from, and THIS call crosses over.+ """+ if sample_rate != 16_000:+ raise LocalEngineUnavailable(+ f"the dictation worker takes 16 kHz audio, not {sample_rate} Hz"+ )+ if not self._call_lock.acquire(blocking=False):+ self.recover()+ raise LocalEngineUnavailable(+ "a previous call is still waiting on the dictation worker; "+ "it was replaced — this call goes to the next provider"+ )+ try:+ return await asyncio.to_thread(self._transcribe_blocking, pcm_bytes, language)+ finally:+ self._call_lock.release()++ def _transcribe_blocking(self, pcm_bytes: bytes, language: str | None) -> Transcript:+ worker = self._ensure_worker()+ if worker is None:+ raise LocalEngineUnavailable(self._last_refusal or "no local dictation worker")+ import numpy as np++ samples = np.frombuffer(pcm_bytes, dtype=np.int16).astype(np.float32) / 32768.0+ started = time.perf_counter()+ try:+ segments, info = worker.transcribe(+ samples, language=language or None, beam_size=self._beam_size+ )+ except Exception as exc: # noqa: BLE001 — classified as crossable below+ with self._spawn_lock:+ self._drop_worker_locked()+ self._next_attempt_at = time.monotonic() + _RETRY_AFTER_S+ self._last_refusal = f"{type(exc).__name__}: {exc}"+ log.warning(+ "Local dictation worker failed (%s) — replaced; this call crosses "+ "to the next provider.",+ self._last_refusal,+ )+ raise LocalEngineUnavailable(self._last_refusal) from exc+ # Whisper segment texts carry their own leading space, so a bare join+ # reproduces the decoder's spacing (a " " join would double it).+ text = "".join(str(getattr(seg, "text", "") or "") for seg in segments).strip()+ seg_dicts = tuple(+ {+ "start": getattr(seg, "start", None),+ "end": getattr(seg, "end", None),+ "text": str(getattr(seg, "text", "") or ""),+ }+ for seg in segments+ )+ detected = str(getattr(info, "language", "") or "") or (language or "")+ try:+ confidence = float(getattr(info, "language_probability", 0.0) or 0.0)+ except (TypeError, ValueError):+ confidence = 0.0+ log.debug(+ "Local dictation final pass: %.1fs of audio in %.2fs on %s (%s).",+ len(pcm_bytes) / 32_000.0,+ time.perf_counter() - started,+ self._device,+ self._engine_compute,+ )+ from jarvis.plugins.stt.transcript_filter import clean_stt_text++ return Transcript(+ text=clean_stt_text(text, language=detected),+ language=detected,+ confidence=confidence,+ is_partial=False,+ segments=seg_dicts,+ raw_text=text,+ )++ # ------------------------------------------------------------------+ # Worker ownership+ # ------------------------------------------------------------------++ def _ensure_worker(self) -> Any:+ """The live worker, spawning one when allowed; ``None`` when declined."""+ with self._spawn_lock:+ if self._worker is not None:+ return self._worker+ now = time.monotonic()+ if now < self._next_attempt_at:+ return None+ self._next_attempt_at = now + _RETRY_AFTER_S+ refusal = self._spawn_refusal()+ if refusal:+ self._last_refusal = refusal+ log.info("Local dictation engine not started: %s", refusal)+ return None+ from jarvis.dictation.local_preview import _spawn_worker_model++ worker = _spawn_worker_model(self._model_name, compute=self._compute)+ if worker is None:+ self._last_refusal = "the dictation worker did not come up"+ return None+ device = str(getattr(worker, "device", "") or "")+ if device == "cpu":+ # A beam-search turbo decode of a 25 s window on a CPU takes+ # longer than the cloud round-trip it would replace; the+ # preview keeps its own CPU floor, the final pass does not.+ worker.close()+ self._last_refusal = (+ "the local engine only runs on the CPU here, which is slower "+ "than the configured provider for a final pass"+ )+ log.info("Local dictation engine declined: %s", self._last_refusal)+ return None+ self._worker = worker+ self._device = device+ self._engine_compute = str(getattr(worker, "compute", "") or "")+ self._last_refusal = ""+ log.info(+ "Local dictation engine ready: %s on %s (%s), out of process.",+ self._model_name,+ self._device,+ self._engine_compute,+ )+ return worker++ def _spawn_refusal(self) -> str:+ """Why the worker must not be started right now, or ``""``."""+ try:+ from jarvis.dictation.local_preview import faster_whisper_available++ if not faster_whisper_available():+ return "the local speech engine (faster-whisper) is not installed here"+ except Exception as exc: # noqa: BLE001 — a broken probe reads as "absent"+ return f"the local engine probe failed ({type(exc).__name__}: {exc})"+ if self._min_free_gb <= 0.0:+ return ""+ try:+ from jarvis.hardware.detection import free_accelerator_gb++ free_gb, source = free_accelerator_gb()+ except Exception: # noqa: BLE001 — an unreadable card must not veto the spawn+ log.debug("local dictation: free-memory probe failed", exc_info=True)+ return ""+ if source == "none" or free_gb <= 0.0:+ # Unknown is not "full": Apple unified memory and ROCm have no cheap+ # reading here, and the worker's own device ladder still decides.+ return ""+ if free_gb >= self._min_free_gb:+ return ""+ return (+ f"only {free_gb:.1f} GB of accelerator memory is free ({source}) and "+ f"{self._model_name} needs ~{self._min_free_gb:.1f} GB; the configured "+ "provider takes this dictation"+ )++ def _drop_worker_locked(self) -> None:+ worker, self._worker = self._worker, None+ self._device = ""+ self._engine_compute = ""+ if worker is None:+ return+ try:+ worker.close()+ except Exception as exc: # noqa: BLE001 — a dead worker is the goal state+ log.debug("local dictation: worker close skipped (%s)", exc)+++__all__ = [+ "DEFAULT_FINAL_MODEL",+ "DEFAULT_MIN_FREE_GB",+ "FINAL_BEAM_SIZE",+ "FINAL_COMPUTE",+ "LocalEngineUnavailable",+ "LocalFinalSTT",+]diff --git a/jarvis/dictation/local_preview.py b/jarvis/dictation/local_preview.pyindex 379fb2a834..01328987c6 100644--- a/jarvis/dictation/local_preview.py+++ b/jarvis/dictation/local_preview.py@@ -132,7 +132,11 @@ class _WorkerModel:self.compute = computedef transcribe(- self, samples: Any, language: str | None = None, **_ignored: Any+ self,+ samples: Any,+ language: str | None = None,+ beam_size: int = 1,+ **_ignored: Any,) -> tuple[list[Any], Any]:import numpy as np@@ -142,7 +146,10 @@ class _WorkerModel:stdin, stdout = self._proc.stdin, self._proc.stdoutif stdin is None or stdout is None: # pragma: no cover — Popen(PIPE) guarantees bothraise RuntimeError("preview worker pipes are gone")- write_message(stdin, {"n": len(pcm), "language": language})+ request: dict[str, Any] = {"n": len(pcm), "language": language}+ if beam_size and int(beam_size) > 1:+ request["beam_size"] = int(beam_size)+ write_message(stdin, request)stdin.write(pcm)stdin.flush()response = read_message(stdout)@@ -150,7 +157,16 @@ class _WorkerModel:raise RuntimeError("preview worker exited")if "error" in response:raise RuntimeError(str(response["error"]))- segments = [SimpleNamespace(text=str(response.get("text", "")))]+ timings = response.get("segments") or []+ segments = [+ SimpleNamespace(+ start=item.get("start"),+ end=item.get("end"),+ text=str(item.get("text", "") or ""),+ )+ for item in timings+ if isinstance(item, dict)+ ] or [SimpleNamespace(start=None, end=None, text=str(response.get("text", "")))]info = SimpleNamespace(language=str(response.get("language", "") or ""),language_probability=float(response.get("probability", 0.0) or 0.0),@@ -165,19 +181,23 @@ class _WorkerModel:log.debug("Preview worker kill skipped: %s", exc)-def _spawn_worker_model(model_name: str) -> _WorkerModel | None:+def _spawn_worker_model(model_name: str, *, compute: str | None = None) -> _WorkerModel | None:"""Start the out-of-process engine; ``None`` when this host cannot.A refused spawn is not an error — the caller falls back to the in-processCPU floor, which never touches the CUDA DLLs and therefore never holds- the loader lock.+ the loader lock. ``compute`` pins the CUDA compute type for the worker+ (the dictation final pass shares the card and asks for ``int8_float16``)."""from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGSfrom jarvis.dictation.preview_worker import read_message+ argv = [_child_python(), "-X", "utf8", "-m", "jarvis.dictation.preview_worker", model_name]+ if compute:+ argv.append(compute)try:proc = subprocess.Popen( # noqa: S603 — our own interpreter + module, no user input- [_child_python(), "-X", "utf8", "-m", "jarvis.dictation.preview_worker", model_name],+ argv,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.DEVNULL,@@ -235,8 +255,18 @@ class LocalPreviewTranscriber:preview away is free; the next tick asks again."""- def __init__(self, model_name: str = PREVIEW_MODEL, *, prefer_worker: bool = False) -> None:+ def __init__(+ self,+ model_name: str = PREVIEW_MODEL,+ *,+ prefer_worker: bool = False,+ compute_override: str | None = None,+ ) -> None:self._model_name = model_name+ #: CUDA compute type to try first instead of the probe's pick — the+ #: dictation final pass asks for ``int8_float16`` so a second model+ #: fits beside the wake engine and the voice stack. CPU is unaffected.+ self._compute_override = (compute_override or "").strip() or None#: True in the DESKTOP process (set by the ``local_preview`` factory):#: the engine is hosted out of process so the CUDA DLL load never#: holds this process's loader lock. False inside the worker itself@@ -301,6 +331,8 @@ class LocalPreviewTranscriber:preferred = ("cpu", "int8")else:preferred = self._pick_device()+ if self._compute_override and preferred[0] == "cuda":+ preferred = ("cuda", self._compute_override)attempts = [preferred]if preferred == ("cuda", "float16"):# The quantized pair is the old GPU default and still the@@ -432,25 +464,40 @@ class LocalPreviewTranscriber:which no downstream text inspection can reconstruct once a providerhas translated the words."""+ text, detected, probability, _timings = self._transcribe_sync_detailed(pcm, language)+ return text, detected, probability++ def _transcribe_sync_detailed(+ self, pcm: bytes, language: str | None, *, beam_size: int = 1+ ) -> tuple[str, str, float, list[dict[str, Any]]]:+ """:meth:`_transcribe_sync` plus the decoder's own segment timings.++ ``beam_size`` defaults to greedy — the preview trades a little accuracy+ for latency — and the dictation final pass, read once after release,+ asks for a real beam. The segments carry ``start``/``end`` on the+ recognizer's clock so a caller can tell a dropped tail from a slow+ speaker, which the joined text alone cannot.+ """import numpy as npsamples = np.frombuffer(pcm, dtype=np.int16).astype(np.float32) / 32768.0if samples.size == 0:- return "", "", 0.0+ return "", "", 0.0, []model = self._modelif model is None: # pragma: no cover — transcribe() gates on ready- return "", "", 0.0+ return "", "", 0.0, []segments, info = model.transcribe(samples,language=language,- beam_size=1, # greedy: the preview trades a little accuracy for latency+ beam_size=max(1, int(beam_size)),# A tuple/default enables Whisper's temperature fallback ladder and- # may decode the same stale preview repeatedly. One fixed greedy- # pass keeps the measured path in the tens-of-milliseconds range.+ # may decode the same stale preview repeatedly. One fixed pass+ # keeps the measured preview path in the tens-of-milliseconds range.temperature=0.0,condition_on_previous_text=False,)- text = " ".join(seg.text for seg in segments).strip()+ decoded = list(segments)+ text = " ".join(seg.text for seg in decoded).strip()# A language the CALLER pinned is not a detection — reporting it back as# one would let a pin confirm itself forever.detected = "" if language else str(getattr(info, "language", "") or "")@@ -462,7 +509,15 @@ class LocalPreviewTranscriber:# reject the detection — the same outcome a log line would only# narrate, once per preview tick.probability = 0.0- return text, detected, probability+ timings = [+ {+ "start": getattr(seg, "start", None),+ "end": getattr(seg, "end", None),+ "text": str(getattr(seg, "text", "") or ""),+ }+ for seg in decoded+ ]+ return text, detected, probability, timingsasync def transcribe(self, pcm: bytes, language: str | None = None) -> str | None:"""Preview text, or ``None`` when this tick has none.diff --git a/jarvis/dictation/preview_worker.py b/jarvis/dictation/preview_worker.pyindex 68fda91f26..18c4eeba9c 100644--- a/jarvis/dictation/preview_worker.py+++ b/jarvis/dictation/preview_worker.py@@ -21,9 +21,13 @@ Protocol (stdin/stdout, binary, length-prefixed):* worker → parent, once, after the engine built and warmed:``{"ready": true, "device": ..., "compute": ...}`` or``{"ready": false, "error": ...}`` (the worker then exits)-* parent → worker: ``{"n": <pcm byte count>, "language": <code or null>}``-* worker → parent: ``{"text": ..., "language": ..., "probability": ...}``- or ``{"error": ...}``+* parent → worker: ``{"n": <pcm byte count>, "language": <code or null>}``,+ optionally with ``"beam_size"`` (default 1 — greedy, the preview's choice;+ the dictation final pass asks for a real beam)+* worker → parent: ``{"text": ..., "language": ..., "probability": ...,+ "segments": [{"start": s, "end": s, "text": ...}, ...]}`` or+ ``{"error": ...}`` — ``segments`` carry the decoder's own timings so the+ final pass can tell a dropped tail from a slow speakerstdout carries ONLY the protocol (stderr is discarded by the parent). Theworker exits when its stdin closes — parent exit or kill — so no orphan can@@ -69,11 +73,20 @@ def write_message(stream: IO[bytes], message: dict[str, Any]) -> None:stream.flush()-def serve(stdin: IO[bytes], stdout: IO[bytes], model_name: str) -> int:- """Build the engine, report readiness, then answer requests until EOF."""+def serve(stdin: IO[bytes], stdout: IO[bytes], model_name: str, compute: str | None = None) -> int:+ """Build the engine, report readiness, then answer requests until EOF.++ ``compute`` pins the CUDA compute type (``"int8_float16"`` for the final+ pass, which shares the card with the wake model and the voice stack);+ ``None`` keeps the preview's own ladder.+ """from jarvis.dictation.local_preview import LocalPreviewTranscriber- engine = LocalPreviewTranscriber(model_name)+ engine = (+ LocalPreviewTranscriber(model_name, compute_override=compute)+ if compute+ else LocalPreviewTranscriber(model_name)+ )engine._load_model() # noqa: SLF001 — the worker IS the engine's hostif not engine.ready:write_message(stdout, {"ready": False, "error": "no usable local engine"})@@ -94,12 +107,26 @@ def serve(stdin: IO[bytes], stdout: IO[bytes], model_name: str) -> int:if pcm is None:return 0try:- text, language, probability = engine._transcribe_sync( # noqa: SLF001- pcm, request.get("language") or None- )+ language_hint = request.get("language") or None+ beam_size = max(1, int(request.get("beam_size", 1) or 1))+ detailed = getattr(engine, "_transcribe_sync_detailed", None)+ segments: list[dict[str, Any]] = []+ if callable(detailed):+ text, language, probability, segments = detailed(+ pcm, language_hint, beam_size=beam_size+ )+ else: # an engine without timings still answers the preview+ text, language, probability = engine._transcribe_sync( # noqa: SLF001+ pcm, language_hint+ )write_message(stdout,- {"text": text, "language": language, "probability": probability},+ {+ "text": text,+ "language": language,+ "probability": probability,+ "segments": list(segments),+ },)except Exception as exc: # noqa: BLE001 — one bad clip must not kill the workerwrite_message(stdout, {"error": f"{type(exc).__name__}: {exc}"})@@ -107,7 +134,8 @@ def serve(stdin: IO[bytes], stdout: IO[bytes], model_name: str) -> int:def main() -> int:model_name = sys.argv[1] if len(sys.argv) > 1 else "base"- return serve(sys.stdin.buffer, sys.stdout.buffer, model_name)+ compute = sys.argv[2] if len(sys.argv) > 2 else None+ return serve(sys.stdin.buffer, sys.stdout.buffer, model_name, compute)if __name__ == "__main__":diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.pyindex 8a91467659..10972964c8 100644--- a/jarvis/speech/pipeline.py+++ b/jarvis/speech/pipeline.py@@ -10804,13 +10804,42 @@ class SpeechPipeline:configured = str(getattr(stt_cfg, "provider", "") or "").strip()alternates = list(_resolve_stt_fallback_chain(stt_cfg, configured))- if alternates:+ configured_instance = instance++ def _build(name: str) -> Any:+ if name == configured:+ return configured_instance+ return build_named_stt_provider(name, patched, dictionary_bias=False)++ # The on-device final pass goes IN FRONT of whatever the voice lane+ # uses, hosted out of process (2026-09-02 forensics: 220 of 220+ # dictations ran on a cloud recognizer the settings did not name,+ # because the voice lane had been moved there to keep CUDA out of+ # this process — the dictation lane inherited that move and paid+ # for it in round-trips and truncated windows). The worker declines+ # itself on a full card, a CPU-only host or a missing runtime with+ # a crossable failure, so the configured provider is one step+ # behind on every press (AP-22) and never a restart away.+ local_final = self._dictation_local_final(dictation_cfg)+ if local_final is not None:from jarvis.speech.stt_fallback import FallbackSTT- def _build(name: str) -> Any:- return build_named_stt_provider(- name, patched, dictionary_bias=False- )+ chain = [configured, *alternates] if configured else alternates+ instance = FallbackSTT(+ local_final,+ chain,+ _build,+ primary_name=local_final.provider_label,+ )+ log.info(+ "Dictation STT chain armed: %s/%s (out of process) -> %s "+ "(no voice bias prompt).",+ local_final.provider_label,+ local_final.last_used_model,+ ", ".join(chain) or "<no cloud family keyed>",+ )+ elif alternates:+ from jarvis.speech.stt_fallback import FallbackSTTinstance = FallbackSTT(instance, alternates, _build, primary_name=configured@@ -11023,6 +11052,42 @@ class SpeechPipeline:self._dictation_warmup_task = Nonereturn fresh+ def _dictation_local_final(self, dictation_cfg: Any) -> Any:+ """The out-of-process on-device final-pass provider, or ``None``.++ ``None`` when the user switched it off (``[dictation].local_engine``)+ or the local runtime is not importable here — the cheap, static+ reasons. The expensive, changing ones (free accelerator memory, a+ CPU-only worker, a spawn that fails) are the provider's own business:+ it answers every call it cannot take with a CROSSABLE failure, so the+ chain behind it decides per press, not per boot.+ """+ if not bool(getattr(dictation_cfg, "local_engine", True)):+ return None+ try:+ from jarvis.dictation.local_final import (+ DEFAULT_FINAL_MODEL,+ DEFAULT_MIN_FREE_GB,+ LocalFinalSTT,+ )+ from jarvis.dictation.local_preview import faster_whisper_available++ if not faster_whisper_available():+ log.info(+ "Dictation stays on the configured provider: the local speech "+ "engine (faster-whisper) is not installed in this Python."+ )+ return None+ model = str(getattr(dictation_cfg, "local_model", "") or "").strip()+ min_free = getattr(dictation_cfg, "local_min_free_gb", DEFAULT_MIN_FREE_GB)+ return LocalFinalSTT(+ model or DEFAULT_FINAL_MODEL,+ min_free_gb=float(min_free if min_free is not None else 0.0),+ )+ except Exception as exc: # noqa: BLE001 — the cloud chain is still a chain+ log.warning("Local dictation engine unavailable (%s); using the chain.", exc)+ return None+def _reset_dictation_stt(self) -> None:"""Drop every cached STT fallback so the next use resolves them again.diff --git a/jarvis/ui/web/dictation_routes.py b/jarvis/ui/web/dictation_routes.pyindex 7bc69e5a0e..f7bd215aa7 100644--- a/jarvis/ui/web/dictation_routes.py+++ b/jarvis/ui/web/dictation_routes.py@@ -458,6 +458,25 @@ class SettingsBody(BaseModel):default=None,description="Audio shared by adjacent final windows (0-5 seconds)",)+ local_engine: bool | None = Field(+ default=None,+ description=(+ "Read the final pass on this machine in a worker process before "+ "any configured cloud provider (declines itself on a full card, "+ "a CPU-only host or a missing local runtime)"+ ),+ )+ local_model: str | None = Field(+ default=None,+ description="faster-whisper checkpoint for the local final pass",+ )+ local_min_free_gb: float | None = Field(+ default=None,+ description=(+ "Free accelerator memory the local final pass needs before it "+ "starts (0-64 GB; 0 skips the check)"+ ),+ )code_switching: bool | None = Field(default=None,description=(diff --git a/jarvis/ui/web/frontend/src/hooks/useDictation.ts b/jarvis/ui/web/frontend/src/hooks/useDictation.tsindex c06157fc50..bba1ac3cf7 100644--- a/jarvis/ui/web/frontend/src/hooks/useDictation.ts+++ b/jarvis/ui/web/frontend/src/hooks/useDictation.ts@@ -286,6 +286,12 @@ export interface DictationSettings {final_window_seconds: number;/** Overlap between adjacent final windows in seconds. */final_overlap_seconds: number;+ /** Read the final pass on this machine (worker process) before any cloud provider. */+ local_engine: boolean;+ /** faster-whisper checkpoint for the local final pass. */+ local_model: string;+ /** Free accelerator memory the local final pass needs before it starts (GB). */+ local_min_free_gb: number;/** Auto-detect within the recording instead of sending a hard language lock. */code_switching: boolean;history_enabled: boolean;diff --git a/tests/unit/dictation/test_local_final.py b/tests/unit/dictation/test_local_final.pynew file mode 100644index 0000000000..7ddee290c8--- /dev/null+++ b/tests/unit/dictation/test_local_final.py@@ -0,0 +1,283 @@+"""The on-device final pass: spawn gating, crossable failures, worker replacement.++No subprocess and no model anywhere here — the worker proxy is a fake with the+``transcribe(samples, language, beam_size)`` surface of ``_WorkerModel``.+"""++from __future__ import annotations++import asyncio+from types import SimpleNamespace+from typing import Any++import numpy as np+import pytest++import jarvis.dictation.local_final as local_final_mod+from jarvis.dictation.local_final import (+ FINAL_BEAM_SIZE,+ FINAL_COMPUTE,+ LocalEngineUnavailable,+ LocalFinalSTT,+)+from jarvis.speech.stt_failure import classify_stt_failure, is_crossable_failure+++class _FakeWorker:+ def __init__(self, device: str = "cuda", *, fail: str = "") -> None:+ self.device = device+ self.compute = "int8_float16"+ self.calls: list[dict[str, Any]] = []+ self.closed = False+ self._fail = fail++ def transcribe(+ self, samples: Any, language: str | None = None, beam_size: int = 1, **_: Any+ ) -> tuple[list[Any], Any]:+ self.calls.append(+ {"n": int(np.asarray(samples).size), "language": language, "beam": beam_size}+ )+ if self._fail:+ raise RuntimeError(self._fail)+ segments = [+ SimpleNamespace(start=0.0, end=1.2, text=" Hallo"),+ SimpleNamespace(start=1.2, end=2.0, text=" Welt."),+ ]+ info = SimpleNamespace(language="de", language_probability=0.97)+ return segments, info++ def close(self) -> None:+ self.closed = True+++def _pcm(seconds: float = 1.0) -> bytes:+ return (np.zeros(int(16_000 * seconds), dtype="<i2") + 1000).tobytes()+++def _local_ok(monkeypatch: pytest.MonkeyPatch) -> dict[str, Any]:+ """faster-whisper present, plenty of free memory, a CUDA worker on spawn."""+ import jarvis.dictation.local_preview as preview_mod+ import jarvis.hardware.detection as detection++ spawned: dict[str, Any] = {"args": []}++ def _spawn(model_name: str, *, compute: str | None = None) -> _FakeWorker:+ spawned["args"].append((model_name, compute))+ return spawned.get("next") or _FakeWorker()++ monkeypatch.setattr(preview_mod, "faster_whisper_available", lambda: True)+ monkeypatch.setattr(preview_mod, "_spawn_worker_model", _spawn)+ monkeypatch.setattr(detection, "free_accelerator_gb", lambda: (6.0, "nvml"))+ return spawned+++def test_a_worker_error_is_a_crossable_failure() -> None:+ reason = classify_stt_failure(LocalEngineUnavailable("card is full"))+ assert reason == "unavailable"+ assert is_crossable_failure(reason)+++def test_the_final_pass_decodes_with_a_beam_and_keeps_the_timings(+ _local_ok: dict[str, Any],+) -> None:+ stt = LocalFinalSTT("large-v3-turbo")++ transcript = asyncio.run(stt.transcribe_pcm(_pcm(2.0), language=None))++ assert _local_ok["args"] == [("large-v3-turbo", FINAL_COMPUTE)]+ assert transcript.text == "Hallo Welt."+ assert transcript.raw_text == "Hallo Welt."+ assert transcript.language == "de"+ assert transcript.segments[-1]["end"] == 2.0+ worker = stt._worker+ assert worker.calls[0]["beam"] == FINAL_BEAM_SIZE+ assert worker.calls[0]["language"] is None+ assert stt.last_used_model == "large-v3-turbo"+ assert stt.provider_label == "faster-whisper"+ assert stt.is_warm+++def test_a_full_card_declines_the_spawn_and_crosses_over(+ _local_ok: dict[str, Any], monkeypatch: pytest.MonkeyPatch+) -> None:+ import jarvis.hardware.detection as detection++ monkeypatch.setattr(detection, "free_accelerator_gb", lambda: (0.8, "nvml"))+ stt = LocalFinalSTT(min_free_gb=1.5)++ with pytest.raises(LocalEngineUnavailable) as caught:+ asyncio.run(stt.transcribe_pcm(_pcm()))++ assert "0.8 GB" in str(caught.value)+ assert _local_ok["args"] == [] # never spawned+ assert not stt.is_warm+++def test_unknown_free_memory_never_blocks_the_spawn(+ _local_ok: dict[str, Any], monkeypatch: pytest.MonkeyPatch+) -> None:+ """Apple unified memory / ROCm have no cheap reading — refusing on a number+ nobody can read would brick every such box (AP-22 shape)."""+ import jarvis.hardware.detection as detection++ monkeypatch.setattr(detection, "free_accelerator_gb", lambda: (0.0, "none"))+ stt = LocalFinalSTT(min_free_gb=1.5)++ transcript = asyncio.run(stt.transcribe_pcm(_pcm()))++ assert transcript.text == "Hallo Welt."+++def test_a_cpu_only_worker_is_declined(_local_ok: dict[str, Any]) -> None:+ """A beam-search turbo decode of a 25 s window on a CPU is slower than the+ cloud it would replace; the preview keeps a CPU floor, the final pass not."""+ cpu_worker = _FakeWorker(device="cpu")+ _local_ok["next"] = cpu_worker+ stt = LocalFinalSTT()++ with pytest.raises(LocalEngineUnavailable):+ asyncio.run(stt.transcribe_pcm(_pcm()))++ assert cpu_worker.closed+ assert "CPU" in stt.unavailable_reason+++def test_a_missing_runtime_is_declined_without_probing_the_card(+ _local_ok: dict[str, Any], monkeypatch: pytest.MonkeyPatch+) -> None:+ import jarvis.dictation.local_preview as preview_mod++ monkeypatch.setattr(preview_mod, "faster_whisper_available", lambda: False)+ stt = LocalFinalSTT()++ stt.warm_up() # quiet — a warm-up must never raise++ assert not stt.is_warm+ assert "faster-whisper" in stt.unavailable_reason+++def test_a_failing_worker_is_replaced_and_the_call_crosses_over(+ _local_ok: dict[str, Any], monkeypatch: pytest.MonkeyPatch+) -> None:+ broken = _FakeWorker(fail="preview worker exited")+ _local_ok["next"] = broken+ stt = LocalFinalSTT()++ with pytest.raises(LocalEngineUnavailable):+ asyncio.run(stt.transcribe_pcm(_pcm()))++ assert broken.closed+ assert not stt.is_warm+ # The retry window keeps a dying worker from being respawned on every press…+ with pytest.raises(LocalEngineUnavailable):+ asyncio.run(stt.transcribe_pcm(_pcm()))+ assert len(_local_ok["args"]) == 1+ # …and ``recover()`` opens it again at once (AP-24: replace, never wait).+ _local_ok["next"] = None+ stt.recover()+ transcript = asyncio.run(stt.transcribe_pcm(_pcm()))+ assert transcript.text == "Hallo Welt."+ assert len(_local_ok["args"]) == 2+++def test_a_second_caller_replaces_an_abandoned_worker(+ _local_ok: dict[str, Any],+) -> None:+ """A call that outlived its ceiling left a response in the pipe; reading+ it as the answer to the NEXT press would deliver someone else's words."""+ stt = LocalFinalSTT()+ asyncio.run(stt.transcribe_pcm(_pcm()))+ first_worker = stt._worker+ assert stt._call_lock.acquire(blocking=False) # simulate the abandoned call+ try:+ with pytest.raises(LocalEngineUnavailable):+ asyncio.run(stt.transcribe_pcm(_pcm()))+ finally:+ stt._call_lock.release()+ assert first_worker.closed+ assert not stt.is_warm+++def test_warm_up_spawns_off_the_press_path(_local_ok: dict[str, Any]) -> None:+ stt = LocalFinalSTT()++ stt.warm_up()++ assert stt.is_warm+ assert stt.device == "cuda"+ assert _local_ok["args"] == [(local_final_mod.DEFAULT_FINAL_MODEL, FINAL_COMPUTE)]+++def test_the_lane_puts_the_local_engine_in_front_of_the_configured_provider(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Chain order: local worker → the configured cloud provider → the other+ keyed families. The configured instance is reused, never built twice."""+ import jarvis.plugins.stt as stt_plugins+ import jarvis.speech.pipeline as pipeline_mod+ import jarvis.speech.stt_dictionary as dictionary+ from jarvis.core.config import DictationConfig, STTConfig+ from jarvis.speech.pipeline import SpeechPipeline+ from jarvis.speech.stt_fallback import FallbackSTT++ configured = SimpleNamespace(name="groq-instance")+ built: list[str] = []+ monkeypatch.setattr(stt_plugins, "build_stt_from_config", lambda cfg, **_k: configured)+ monkeypatch.setattr(+ stt_plugins,+ "build_named_stt_provider",+ lambda name, cfg, **_k: built.append(name) or SimpleNamespace(name=name),+ )+ monkeypatch.setattr(+ pipeline_mod, "_resolve_stt_fallback_chain", lambda *_a, **_k: ("openai-api",)+ )+ monkeypatch.setattr(dictionary, "wrap_stt_with_dictionary", lambda provider: provider)+ import jarvis.dictation.local_preview as preview_mod++ monkeypatch.setattr(preview_mod, "faster_whisper_available", lambda: True)++ pipe = SpeechPipeline.__new__(SpeechPipeline)+ pipe._dictation_stt_instance = None+ pipe._utterance_stt = object()+ pipe._dictation_cfg = DictationConfig(local_model="small")+ pipe._config = SimpleNamespace(stt=STTConfig(provider="groq-api"))++ instance = pipe._dictation_stt()++ assert isinstance(instance, FallbackSTT)+ assert isinstance(instance._primary, LocalFinalSTT)+ assert instance._primary.last_used_model == "small"+ assert instance._alternate_names == ["groq-api", "openai-api"]+ assert instance._build("groq-api") is configured+ assert built == []+++def test_the_switch_keeps_the_configured_provider_in_front(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ import jarvis.plugins.stt as stt_plugins+ import jarvis.speech.pipeline as pipeline_mod+ import jarvis.speech.stt_dictionary as dictionary+ from jarvis.core.config import DictationConfig, STTConfig+ from jarvis.speech.pipeline import SpeechPipeline+ from jarvis.speech.stt_fallback import FallbackSTT++ configured = SimpleNamespace(name="groq-instance")+ monkeypatch.setattr(stt_plugins, "build_stt_from_config", lambda cfg, **_k: configured)+ monkeypatch.setattr(+ pipeline_mod, "_resolve_stt_fallback_chain", lambda *_a, **_k: ("openai-api",)+ )+ monkeypatch.setattr(dictionary, "wrap_stt_with_dictionary", lambda provider: provider)++ pipe = SpeechPipeline.__new__(SpeechPipeline)+ pipe._dictation_stt_instance = None+ pipe._utterance_stt = object()+ pipe._dictation_cfg = DictationConfig(local_engine=False)+ pipe._config = SimpleNamespace(stt=STTConfig(provider="groq-api"))++ instance = pipe._dictation_stt()++ assert isinstance(instance, FallbackSTT)+ assert instance._primary is configured+ assert instance._alternate_names == ["openai-api"]diff --git a/tests/unit/dictation/test_preview_worker.py b/tests/unit/dictation/test_preview_worker.pyindex c74e284d5f..1069dc8d71 100644--- a/tests/unit/dictation/test_preview_worker.py+++ b/tests/unit/dictation/test_preview_worker.py@@ -64,7 +64,12 @@ def test_serve_answers_ready_then_transcribes(monkeypatch: pytest.MonkeyPatch) -ready, first, second = _messages_from(stdout.getvalue())assert ready == {"ready": True, "device": "cpu", "compute": "int8"}- assert first == {"text": "heard 200 bytes", "language": "de", "probability": 0.9}+ assert first == {+ "text": "heard 200 bytes",+ "language": "de",+ "probability": 0.9,+ "segments": [],+ }assert second["text"] == "heard 0 bytes"assert engine.requests[0][1] == "de"diff --git a/tests/unit/dictation/test_stt_retry_and_isolation.py b/tests/unit/dictation/test_stt_retry_and_isolation.pyindex 489887f1a6..b360d059e2 100644--- a/tests/unit/dictation/test_stt_retry_and_isolation.py+++ b/tests/unit/dictation/test_stt_retry_and_isolation.py@@ -457,6 +457,11 @@ def test_the_dictation_provider_arms_the_cross_family_chain(# on whether THIS host has dictionary entries; stand it down so the test# asserts about the chain and not about the developer's vocabulary.monkeypatch.setattr(dictionary, "wrap_stt_with_dictionary", lambda provider: provider)+ # The on-device final pass would take the front of the chain on a host+ # with the local runtime; this test is about the CLOUD chain behind it.+ import jarvis.dictation.local_preview as preview_mod++ monkeypatch.setattr(preview_mod, "faster_whisper_available", lambda: False)pipe = _pipeline_with_config(provider="groq-api")instance = pipe._dictation_stt()