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(dictation): stop waiting on a busy GPU after release (#988)
Ruben Lütke91fbd5954761
diff --git a/dodaios/dictation/local_final.py b/dodaios/dictation/local_final.pyindex cefe20c710..7fdd675c5b 100644--- a/dodaios/dictation/local_final.py+++ b/dodaios/dictation/local_final.py@@ -62,6 +62,29 @@ FINAL_COMPUTE = "int8_float16"#: final pass is read once after release and can afford the search.FINAL_BEAM_SIZE = 5+#: Decode speed (seconds of decode per second of audio) above which a beam+#: decode counts as running on a CONTENDED card. An idle mid-range card reads a+#: turbo beam-5 pass at well under 0.1; a card another program saturates+#: (a renderer, a local LLM) read 0.9 live on 2026-10-27, so a 15 s dictation+#: waited 13 s after release. Above this line the next calls decode greedily,+#: which measured roughly twice as fast on the same saturated card.+CONTENDED_BEAM_RTF = 0.2++#: Greedy decode speed below which the card counts as free again, and the+#: beam search comes back. Lower than the line above on purpose (hysteresis),+#: so one quick call on a still-busy card does not flip the width back.+UNCONTENDED_GREEDY_RTF = 0.06++#: How long a busy card hands dictations to the cloud provider behind it before+#: the local engine is tried again. The retry is what notices the card is free+#: once the other program finishes; it decodes greedily, so it costs at most+#: the greedy wait on a card that is still busy.+_BUSY_RECHECK_S = 90.0++#: Audio shorter than this never moves the decode width: a one-word clip is+#: dominated by fixed per-call overhead and says nothing about the card.+_MIN_RTF_SAMPLE_S = 2.0+#: 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@@ -134,6 +157,13 @@ class LocalFinalSTT:self._compute = computeself._allow_cpu = allow_cpuself._beam_size = max(1, int(beam_size))+ #: True after a decode measured the card as contended; the next calls+ #: decode greedily until a greedy decode measures it free again.+ self._contended = False+ self._contended_at = 0.0+ #: Set by the dictation lane: True when a cloud provider stands behind+ #: this one in the chain. Only then may a busy card hand calls over.+ self.cloud_behind = Falseself._worker: Any = Noneself._device = ""self._engine_compute = ""@@ -236,9 +266,7 @@ class LocalFinalSTT:)if not self._call_lock.acquire(blocking=False):if self.is_loading:- raise LocalEngineUnavailable(- "the local dictation engine is still starting"- )+ raise LocalEngineUnavailable("the local dictation engine is still starting")await asyncio.to_thread(self.recover)raise LocalEngineUnavailable("a previous call is still waiting on the dictation worker; "@@ -276,6 +304,16 @@ class LocalFinalSTT:raisedef _transcribe_blocking(self, pcm_bytes: bytes, language: str | None) -> Transcript:+ if (+ self._contended+ and self.cloud_behind+ and time.monotonic() - self._contended_at < _BUSY_RECHECK_S+ ):+ # A saturated card decodes at speech speed: the cloud behind us+ # answers in about a second. Crossable, so the chain moves on.+ raise LocalEngineUnavailable(+ "the card is busy with another program; the next provider takes this dictation"+ )worker = self._ensure_worker(blocking=False)if worker is None:raise LocalEngineUnavailable(self._last_refusal or "no local dictation worker")@@ -283,11 +321,10 @@ class LocalFinalSTT:samples = np.frombuffer(pcm_bytes, dtype=np.int16).astype(np.float32) / 32768.0asked_for = _concrete_language(language)+ beam_size = self.current_beam_sizestarted = time.perf_counter()try:- segments, info = worker.transcribe(- samples, language=asked_for, beam_size=self._beam_size- )+ segments, info = worker.transcribe(samples, language=asked_for, beam_size=beam_size)except Exception as exc: # noqa: BLE001 — classified as crossable belowfailure = f"{type(exc).__name__}: {exc}"with self._spawn_lock:@@ -319,12 +356,16 @@ class LocalFinalSTT: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,+ audio_s = len(pcm_bytes) / 32_000.0+ decode_s = time.perf_counter() - started+ self._note_decode_speed(audio_s, decode_s, beam_size)+ log.info(+ "Local dictation final pass: %.1fs of audio in %.2fs on %s (%s, beam %d).",+ audio_s,+ decode_s,self._device,self._engine_compute,+ beam_size,)from dodaios.plugins.stt.transcript_filter import clean_stt_text@@ -341,6 +382,43 @@ class LocalFinalSTT:# Worker ownership# ------------------------------------------------------------------+ @property+ def current_beam_size(self) -> int:+ """Beam width the next decode uses: greedy while the card is contended."""+ return 1 if self._contended else self._beam_size++ def _note_decode_speed(self, audio_s: float, decode_s: float, beam_size: int) -> None:+ """Move the decode width from how fast the last decode actually ran.++ Measured rather than probed: asking the driver for its utilisation took+ 0.3-0.7 s on a saturated card, which is longer than the saving on a+ short clip. The decode we just ran is free and says exactly how busy+ the card is for THIS model.+ """+ if audio_s < _MIN_RTF_SAMPLE_S or self._beam_size <= 1:+ return+ rtf = decode_s / audio_s+ if self._contended and beam_size == 1 and rtf >= UNCONTENDED_GREEDY_RTF:+ self._contended_at = time.monotonic() # still busy: hand over again+ elif not self._contended and beam_size > 1 and rtf > CONTENDED_BEAM_RTF:+ self._contended = True+ self._contended_at = time.monotonic()+ log.info(+ "Local dictation: the card is busy (%.1fs of audio took %.1fs); "+ "%s until it is free again.",+ audio_s,+ decode_s,+ "the cloud provider takes dictations" if self.cloud_behind else "decoding greedily",+ )+ elif self._contended and beam_size == 1 and rtf < UNCONTENDED_GREEDY_RTF:+ self._contended = False+ log.info(+ "Local dictation: the card is free again (%.1fs of audio in "+ "%.2fs); beam search is back.",+ audio_s,+ decode_s,+ )+def _ensure_worker(self, *, blocking: bool = True) -> Any:"""The live worker, spawning one when allowed; ``None`` when declined.@@ -460,10 +538,12 @@ class LocalFinalSTT:__all__ = [+ "CONTENDED_BEAM_RTF","DEFAULT_FINAL_MODEL","DEFAULT_MIN_FREE_GB","FINAL_BEAM_SIZE","FINAL_COMPUTE","LocalEngineUnavailable","LocalFinalSTT",+ "UNCONTENDED_GREEDY_RTF",]diff --git a/dodaios/speech/pipeline.py b/dodaios/speech/pipeline.pyindex e7bfa0a0c0..d9eb3990bb 100644--- a/dodaios/speech/pipeline.py+++ b/dodaios/speech/pipeline.py@@ -12070,6 +12070,11 @@ class SpeechPipeline:# only already-authorized cloud alternates may receive audio.chain = [name for name in chain if stt_family_id(name) != "local"]local_final._allow_cpu = not chain+ # A card another program saturates does not refuse the worker,+ # it just decodes at speech speed; the local pass then hands+ # dictations to the cloud provider behind it (2026-10-27: 15 s+ # spoken, 13 s wait with three renders on the card).+ local_final.cloud_behind = bool(chain)instance = FallbackSTT(local_final,chain,diff --git a/tests/unit/dictation/test_local_final.py b/tests/unit/dictation/test_local_final.pyindex 36f223388f..433f019aa3 100644--- a/tests/unit/dictation/test_local_final.py+++ b/tests/unit/dictation/test_local_final.py@@ -522,3 +522,118 @@ def test_the_switch_keeps_the_configured_provider_in_front(assert callable(instance.transcribe_pcm)assert instance._primary is configuredassert instance._alternate_names == ["openai-api"]+++# ---------------------------------------------------------------------------+# A busy card (2026-10-27: three renders on the GPU, 15 s spoken -> 13 s wait)+# ---------------------------------------------------------------------------+++class _Clock:+ """Stands in for ``time`` inside the module so decode speed is scripted."""++ def __init__(self) -> None:+ self.now = 1000.0++ def perf_counter(self) -> float:+ return self.now++ def monotonic(self) -> float:+ return self.now+++class _TimedWorker(_FakeWorker):+ """A decode costs ``rtf[beam]`` seconds per second of audio on the clock."""++ def __init__(self, clock: _Clock, rtf: dict[int, float]) -> None:+ super().__init__()+ self._clock = clock+ self.rtf = rtf++ def transcribe(+ self, samples: Any, language: str | None = None, beam_size: int = 1, **kw: Any+ ) -> tuple[list[Any], Any]:+ self._clock.now += self.rtf[beam_size] * np.asarray(samples).size / 16_000+ return super().transcribe(samples, language=language, beam_size=beam_size, **kw)+++def _clocked(+ _local_ok: dict[str, Any], monkeypatch: pytest.MonkeyPatch+) -> tuple[_Clock, _TimedWorker]:+ clock = _Clock()+ worker = _TimedWorker(clock, {FINAL_BEAM_SIZE: 0.9, 1: 0.5})+ _local_ok["next"] = worker+ monkeypatch.setattr(local_final_mod, "time", clock)+ return clock, worker+++def test_a_busy_card_switches_the_next_decodes_to_greedy(+ _clocked: tuple[_Clock, _TimedWorker],+) -> None:+ _clock, worker = _clocked+ stt = LocalFinalSTT()++ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))+ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))++ assert [c["beam"] for c in worker.calls] == [FINAL_BEAM_SIZE, 1]+++def test_a_free_card_brings_the_beam_back(_clocked: tuple[_Clock, _TimedWorker]) -> None:+ _clock, worker = _clocked+ stt = LocalFinalSTT()+ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))+ worker.rtf = {FINAL_BEAM_SIZE: 0.04, 1: 0.02} # the render finished++ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))+ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))++ assert [c["beam"] for c in worker.calls] == [FINAL_BEAM_SIZE, 1, FINAL_BEAM_SIZE]+++def test_a_short_clip_never_moves_the_decode_width(+ _clocked: tuple[_Clock, _TimedWorker],+) -> None:+ _clock, worker = _clocked+ stt = LocalFinalSTT()++ asyncio.run(stt.transcribe_pcm(_pcm(1.0), language="de"))+ asyncio.run(stt.transcribe_pcm(_pcm(1.0), language="de"))++ assert [c["beam"] for c in worker.calls] == [FINAL_BEAM_SIZE, FINAL_BEAM_SIZE]+++def test_a_busy_card_hands_dictations_to_the_cloud_behind_it(+ _clocked: tuple[_Clock, _TimedWorker],+) -> None:+ clock, worker = _clocked+ stt = LocalFinalSTT()+ stt.cloud_behind = True+ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))++ with pytest.raises(LocalEngineUnavailable) as caught:+ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))+ assert is_crossable_failure(classify_stt_failure(caught.value))+ assert len(worker.calls) == 1++ # After the recheck interval the local engine is tried again, greedily.+ clock.now += local_final_mod._BUSY_RECHECK_S + 1+ worker.rtf = {FINAL_BEAM_SIZE: 0.04, 1: 0.02}+ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))+ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))+ assert [c["beam"] for c in worker.calls] == [FINAL_BEAM_SIZE, 1, FINAL_BEAM_SIZE]+++def test_without_a_cloud_behind_a_busy_card_still_decodes_locally(+ _clocked: tuple[_Clock, _TimedWorker],+) -> None:+ """A user who keeps audio on the machine never has it sent anywhere."""+ _clock, worker = _clocked+ stt = LocalFinalSTT()+ asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))++ transcript = asyncio.run(stt.transcribe_pcm(_pcm(10.0), language="de"))++ assert transcript.text == "Hallo Welt."+ assert len(worker.calls) == 2