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: retry busy STT finalization

rubenluetke10-beep2071475057e8
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index 286e9da621..c5d26727f6 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -631,8 +631,16 @@ def _stt_error_status(exc: BaseException) -> int | None:
def _is_transient_stt_error(exc: BaseException) -> bool:
- """True when an STT error is a recoverable rate-limit / gateway blip."""
- return _stt_error_status(exc) in _STT_TRANSIENT_STATUS
+ """True when an STT error should clear without changing provider setup.
+
+ A busy local engine is the normal AP-24 handoff race: cancelling an
+ ``asyncio.to_thread`` wrapper cannot stop the native preview already using
+ the model, so the final call must retry after that preview releases it.
+ """
+ return (
+ _stt_error_status(exc) in _STT_TRANSIENT_STATUS
+ or classify_stt_failure(exc) == "engine_busy"
+ )
def _stt_crossover_would_leave_the_machine() -> bool:
diff --git a/tests/unit/plugins/stt/test_stt_cross_family_fallback.py b/tests/unit/plugins/stt/test_stt_cross_family_fallback.py
index ac072960e9..2657fd5339 100644
--- a/tests/unit/plugins/stt/test_stt_cross_family_fallback.py
+++ b/tests/unit/plugins/stt/test_stt_cross_family_fallback.py
@@ -321,6 +321,20 @@ class _WorkingSTT:
return Transcript(text=self.text, language="en", confidence=0.9)
+class _BusyThenWorkingSTT:
+ """A native engine whose cosmetic preview still owns its inference lock."""
+
+ def __init__(self, busy_calls: int = 2) -> None:
+ self.busy_calls = busy_calls
+ self.calls = 0
+
+ async def transcribe_pcm(self, pcm: bytes, **_kwargs: Any) -> Transcript:
+ self.calls += 1
+ if self.calls <= self.busy_calls:
+ raise RuntimeError("a transcription is already in flight on this model")
+ return Transcript(text="the final transcript", language="en", confidence=0.9)
+
+
def _voice_pipeline(primary: Any, *, fallback: str = "auto") -> SpeechPipeline:
"""A pipeline with just enough state for ``_transcribe_final``."""
pipe = SpeechPipeline.__new__(SpeechPipeline)
@@ -374,6 +388,21 @@ async def test_a_rate_limit_that_survives_the_ladder_crosses_family(
assert primary.calls == pipeline_mod._STT_FINAL_RETRIES + 1
+async def test_a_busy_native_preview_is_retried_instead_of_dropping_the_turn(
+ _instant_retries: None,
+) -> None:
+ """A cancelled asyncio wrapper does not stop an in-flight native preview."""
+ stt = _BusyThenWorkingSTT()
+ pipe = _voice_pipeline(stt)
+
+ result = await pipe._transcribe_final(b"\x00\x01" * 512)
+
+ assert result is not None
+ assert result.text == "the final transcript"
+ assert stt.calls == pipeline_mod._STT_FINAL_RETRIES + 1
+
+
@pytest.mark.asyncio
async def test_a_dead_key_crosses_immediately_without_retrying_it(
monkeypatch: pytest.MonkeyPatch,