Skip to content

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

fix(dictation): the local final pass was the lag it was built to remove

rubenluetke10-beep43842da94454
diff --git a/docs/BUGS.md b/docs/BUGS.md
index 48f66adb4a..8c165207d0 100644
--- a/docs/BUGS.md
+++ b/docs/BUGS.md
@@ -14930,3 +14930,46 @@ app-wide one), `tests/unit/workflows/test_brain_prompt_isolated.py`,
**Related.** ADR-0005 (misfire handling was listed as "not required" — it
was), AU-02 (the one cron seed that ships on), AP-31 (the grace is a module
constant, not a config field nobody reads).
+
+## BUG-213: dictation waited 8-45 s for a cloud that answers in 0.6 s (HIGH, FIXED 2026-09-03)
+
+**Symptom.** Every dictation felt slow, and some lost their audio outright:
+`dictation ended (0 chars, 4.8s spoken / 13.8s elapsed, stt error: unavailable
+(the provider did not answer within 10s for 4.8s of audio), LOST 3.3s)`, up to
+`68.9s elapsed` for 23.9 s of speech. The configured cloud recogniser was
+measured at **0.57 s** for the same audio from the same box, so the wait was
+never the network.
+
+**Root cause.** The on-device final pass (`jarvis/dictation/local_final.py`,
+built the day before) is the only module that drives faster-whisper DIRECTLY;
+every STT *plugin* normalises the recognition setting `"auto"` away before the
+call (`groq_api._detect_or`, `fwhisper`, `gemini_api`, `deepgram_api`), and
+this one did not. faster-whisper answers the word itself with
+`ValueError: 'auto' is not a valid language code`, and the dictation lane
+resolves `[stt].language = "auto"` into exactly that string. So on every press:
+
+1. the local worker spawned and loaded its CUDA model (the expensive part,
+ ~11 s cold),
+2. the first decode raised, so the worker was replaced and the local engine
+ locked out for `_RETRY_AFTER_S` (60 s),
+3. only then did the call cross to the cloud — inside a timeout ceiling that
+ had already been burning, which is why calls hit `wait_for` and the tail of
+ the recording was dropped.
+
+The local pass was not merely inert; it was the delay it existed to remove.
+Eight of eight calls in one live session took that path.
+
+**Fix.** `_concrete_language()` in `local_final.py` maps `"auto"` and the empty
+value to `None` — "detect it yourself", which is what faster-whisper accepts —
+and the detected code, not the setting, is reported back as the transcript's
+language. A pinned language still reaches the decoder untouched.
+
+**Guard.** `tests/unit/dictation/test_local_final.py`: the fake worker now
+holds faster-whisper's real contract (an ISO code or nothing; anything else is
+a `ValueError`), which is what let the bug through, plus
+`test_auto_recognition_reaches_the_decoder_as_detect_it_yourself` and
+`test_a_pinned_language_still_reaches_the_decoder`.
+
+**Related.** AP-24 (a wedged native engine is replaced, never waited on — the
+replacement worked, it was the call that was wrong), AP-22 (the local pass
+declines crossably, so the chain behind it always had a provider).
diff --git a/jarvis/dictation/local_final.py b/jarvis/dictation/local_final.py
index ae17dee376..fdc33e4b20 100644
--- a/jarvis/dictation/local_final.py
+++ b/jarvis/dictation/local_final.py
@@ -66,6 +66,16 @@ FINAL_BEAM_SIZE = 5
#: plus a CUDA context, with a little headroom.
DEFAULT_MIN_FREE_GB = 1.5
+#: The recognition setting a user picks when they want per-utterance detection.
+#: Every cloud STT plugin normalises it away before the call (``groq_api``,
+#: ``fwhisper``, ``gemini_api``, ``deepgram_api``); this module is the only one
+#: that drives faster-whisper DIRECTLY, and the library rejects the word with a
+#: ``ValueError`` listing its 99 codes. Passing it through cost every dictation
+#: on this box: the local pass died on its first decode, the worker was replaced
+#: and locked out for a minute, and the call crossed to the cloud round-trip the
+#: local pass exists to avoid (live logs 2026-09-03, 8 of 8 calls).
+AUTO_LANGUAGE = "auto"
+
#: 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
@@ -73,6 +83,18 @@ DEFAULT_MIN_FREE_GB = 1.5
_RETRY_AFTER_S = 60.0
+def _concrete_language(language: str | None) -> str | None:
+ """A decoder-ready language code, or ``None`` to let Whisper detect one.
+
+ ``None`` for both the empty value and :data:`AUTO_LANGUAGE`, which mean the
+ same thing to faster-whisper and only one of which it accepts.
+ """
+ value = str(language or "").strip()
+ if not value or value.lower() == AUTO_LANGUAGE:
+ return None
+ return value
+
+
class LocalEngineUnavailable(RuntimeError):
"""The on-device final pass cannot take this call; another provider may.
@@ -208,10 +230,11 @@ class LocalFinalSTT:
import numpy as np
samples = np.frombuffer(pcm_bytes, dtype=np.int16).astype(np.float32) / 32768.0
+ asked_for = _concrete_language(language)
started = time.perf_counter()
try:
segments, info = worker.transcribe(
- samples, language=language or None, beam_size=self._beam_size
+ samples, language=asked_for, beam_size=self._beam_size
)
except Exception as exc: # noqa: BLE001 — classified as crossable below
with self._spawn_lock:
@@ -235,7 +258,7 @@ class LocalFinalSTT:
}
for seg in segments
)
- detected = str(getattr(info, "language", "") or "") or (language or "")
+ detected = str(getattr(info, "language", "") or "") or (asked_for or "")
try:
confidence = float(getattr(info, "language_probability", 0.0) or 0.0)
except (TypeError, ValueError):
diff --git a/tests/unit/dictation/test_local_final.py b/tests/unit/dictation/test_local_final.py
index cb2cd7aba3..d6827fe013 100644
--- a/tests/unit/dictation/test_local_final.py
+++ b/tests/unit/dictation/test_local_final.py
@@ -22,6 +22,9 @@ from jarvis.dictation.local_final import (
)
from jarvis.speech.stt_failure import classify_stt_failure, is_crossable_failure
+#: The slice of faster-whisper's accepted codes these tests speak.
+_KNOWN_LANGUAGE_CODES = frozenset({"de", "en", "es"})
+
class _FakeWorker:
def __init__(self, device: str = "cuda", *, fail: str = "") -> None:
@@ -37,6 +40,14 @@ class _FakeWorker:
self.calls.append(
{"n": int(np.asarray(samples).size), "language": language, "beam": beam_size}
)
+ # faster-whisper takes an ISO code or nothing, and answers anything else
+ # with a ValueError listing its 99 codes. The fake used to accept every
+ # string, which is why "auto" reached the live worker on every press.
+ if language is not None and language not in _KNOWN_LANGUAGE_CODES:
+ raise ValueError(
+ f"{language!r} is not a valid language code "
+ "(accepted language codes: de, en, es, ...)"
+ )
if self._fail:
raise RuntimeError(self._fail)
segments = [
@@ -98,6 +109,32 @@ def test_the_final_pass_decodes_with_a_beam_and_keeps_the_timings(
assert stt.is_warm
+def test_auto_recognition_reaches_the_decoder_as_detect_it_yourself(
+ _local_ok: dict[str, Any],
+) -> None:
+ """ "auto" is a SETTING, not a language. faster-whisper answers the word
+ itself with a ValueError, which killed the worker, locked the local pass
+ out for a minute and sent every press to the cloud (live logs 2026-09-03)."""
+ stt = LocalFinalSTT()
+
+ transcript = asyncio.run(stt.transcribe_pcm(_pcm(), language="auto"))
+
+ assert stt._worker.calls[0]["language"] is None
+ assert transcript.text == "Hallo Welt."
+ assert transcript.language == "de" # what the decoder detected, not "auto"
+ assert stt.is_warm # the worker survived — nothing crossed to the cloud
+
+
+def test_a_pinned_language_still_reaches_the_decoder(
+ _local_ok: dict[str, Any],
+) -> None:
+ stt = LocalFinalSTT()
+
+ asyncio.run(stt.transcribe_pcm(_pcm(), language="de"))
+
+ assert stt._worker.calls[0]["language"] == "de"
+
+
def test_a_full_card_declines_the_spawn_and_crosses_over(
_local_ok: dict[str, Any], monkeypatch: pytest.MonkeyPatch
) -> None: