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(voice): cancel discarded dictation and throttle failed model starts
rubenluetke10-beep36ff5e54ed89
diff --git a/jarvis/dictation/local_final.py b/jarvis/dictation/local_final.pyindex 4c13982e0f..bad0dd6093 100644--- a/jarvis/dictation/local_final.py+++ b/jarvis/dictation/local_final.py@@ -384,6 +384,10 @@ class LocalFinalSTT:self._spawn_in_flight = Falseif worker is None:self._last_refusal = "the dictation worker did not come up"+ # A cold build can outlast the retry interval. Start the cooldown+ # when it fails, or the very next transcription launches another+ # full build immediately after the warm-up already timed out.+ self._next_attempt_at = time.monotonic() + _RETRY_AFTER_Sreturn Nonedevice = str(getattr(worker, "device", "") or "")if device == "cpu" and not self._allow_cpu:diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.pyindex ffa0de5f3b..099aaab900 100644--- a/jarvis/speech/pipeline.py+++ b/jarvis/speech/pipeline.py@@ -11093,6 +11093,26 @@ class SpeechPipeline:self._dictation_discard_requested = Trueself._dictate_key_down = Falseself.stop_dictation()+ if discard:+ # The stop event only ends capture. After release the lane+ # may be waiting on model startup, STT or formatting, so an+ # explicit discard must cancel that work as well. The task's+ # completion handler closes the UI and releases the wake gate.+ task = getattr(self, "_dictation_task", None)+ if task is not None and not task.done():+ # Let a just-created session enter its cleanup scope+ # before cancellation; repeated X clicks must not cancel+ # the cleanup itself.+ def _cancel() -> None:+ if not task.done() and not task.cancelling():+ task.cancel()++ if current is not None or (+ owner is not None and owner.is_running()+ ):+ asyncio.get_running_loop().call_soon(_cancel)+ else:+ _cancel()except Exception: # noqa: BLE001 — a stop gesture must never crashlog.exception("request_dictation_stop dispatch failed")@@ -11889,6 +11909,7 @@ class SpeechPipeline:prefix_polish_deltas = 0prefix_polish_failed = Falseprefix_polish_task: asyncio.Task[None] | None = None+ probe_task: asyncio.Task[None] | None = Nonedef _append_unique(values: list[str], value: object) -> None:text = str(value or "").strip()@@ -13385,10 +13406,12 @@ class SpeechPipeline:# than awaited, because awaiting inside a cancelled task is not# reliable.#- # A hangup or a crash leaves prefetched final windows in flight;- # nothing will read their answers, so stop asking for them.- for pending in final_tasks.values():- if not pending.done():+ # Cancellation can interrupt capture, preview or formatting as well+ # as a final window. Retire every task owned by this recording so+ # discarded speech cannot keep decoding or formatting in the back.+ stop_event.set()+ for pending in (*final_tasks.values(), probe_task, prefix_polish_task):+ if pending is not None and not pending.done():pending.cancel()if not getattr(self, "_dictation_completion_published", True):self._dictation_completion_published = Truediff --git a/tests/unit/dictation/test_failed_worker_cooldown.py b/tests/unit/dictation/test_failed_worker_cooldown.pynew file mode 100644index 0000000000..86ae3e3ed1--- /dev/null+++ b/tests/unit/dictation/test_failed_worker_cooldown.py@@ -0,0 +1,25 @@+"""A timed-out cold build must not immediately start a second model load."""++from jarvis.dictation import local_final, local_preview+++def test_failed_cold_build_starts_cooldown_at_failure(monkeypatch):+ clock = [100.0]+ attempts = []++ def failed_spawn(*args, **kwargs):+ attempts.append(clock[0])+ clock[0] += 180.0+ return None++ monkeypatch.setattr(local_final.time, "monotonic", lambda: clock[0])+ monkeypatch.setattr(local_preview, "faster_whisper_available", lambda: True)+ monkeypatch.setattr(local_preview, "_spawn_worker_model", failed_spawn)+ provider = local_final.LocalFinalSTT(allow_cpu=True)+ provider.warm_up()+ assert not provider.is_warm+ assert provider._ensure_worker(blocking=False) is None+ assert len(attempts) == 1+ clock[0] += local_final._RETRY_AFTER_S + 1+ provider.warm_up()+ assert len(attempts) == 2diff --git a/tests/unit/speech/test_dictation_hold_watchdog.py b/tests/unit/speech/test_dictation_hold_watchdog.pyindex ad0961d919..5402d0066e 100644--- a/tests/unit/speech/test_dictation_hold_watchdog.py+++ b/tests/unit/speech/test_dictation_hold_watchdog.py@@ -115,9 +115,18 @@ async def test_no_live_trigger_means_no_watchdog() -> None:class _RunningTask:+ def __init__(self) -> None:+ self.cancel_count = 0+def done(self) -> bool:return False+ def cancelling(self) -> int:+ return self.cancel_count++ def cancel(self) -> None:+ self.cancel_count += 1+class _StopCounting(SpeechPipeline):def __init__(self) -> None: # noqa: D107 — bypasses the real ctor on purpose@@ -151,6 +160,7 @@ def test_request_dictation_stop_finishes_by_default_and_discards_for_the_x() ->assert pipe.request_dictation_stop(discard=True) is Trueassert pipe.stopped == 2assert pipe._dictation_discard_requested is True+ assert pipe._dictation_task.cancel_count == 1@pytest.mark.asynciodiff --git a/tests/unit/speech/test_dictation_lifecycle_events.py b/tests/unit/speech/test_dictation_lifecycle_events.pyindex 86275236eb..f3ced409af 100644--- a/tests/unit/speech/test_dictation_lifecycle_events.py+++ b/tests/unit/speech/test_dictation_lifecycle_events.py@@ -222,6 +222,43 @@ async def test_a_dictation_killed_mid_flight_still_closes_its_turn(assert pipe._activation_allowed() is True[email protected]("immediate", [False, True])+async def test_discard_cancels_work_and_releases_wake_gate(monkeypatch, immediate):+ bus = EventBus()+ seen = _Collector(bus)+ pipe = _dictation_pipeline(bus)+ monkeypatch.setattr(pipeline_mod, "MicrophoneCapture", _FakeMic)+ finishing = asyncio.Event()+ delivered = []++ async def finish(**kwargs):+ finishing.set()+ await asyncio.Event().wait()+ delivered.append(kwargs)+ return ""++ pipe._finish_dictation = finish+ assert pipe.start_dictation()+ task = pipe._dictation_task+ if not immediate:+ await _drain_bus()+ pipe.stop_dictation()+ await asyncio.wait_for(finishing.wait(), timeout=2)+ assert pipe.request_dictation_stop(discard=True)+ assert pipe.request_dictation_stop(discard=True)+ try:+ await asyncio.wait_for(asyncio.shield(task), timeout=2)+ except asyncio.CancelledError:+ pass+ await _drain_bus()+ assert not delivered+ assert len(seen.completed) == 1+ assert seen.completed[0].outcome == "cancelled"+ assert not pipe.dictation_active()+ assert pipe._activation_allowed()++@pytest.mark.asyncioasync def test_a_crashing_dictation_publishes_exactly_one_completion(monkeypatch,