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.

chore: auto-save WIP via Claude stop-hook safety net (2026-06-30 19:03)

Ruben Lütked84e60e41b82
diff --git a/jarvis/brain/output_filter.py b/jarvis/brain/output_filter.py
index 360525f14b..5eba92da91 100644
--- a/jarvis/brain/output_filter.py
+++ b/jarvis/brain/output_filter.py
@@ -646,6 +646,12 @@ def scrub_for_voice(
# ASCII '-' with no surrounding whitespace and are NOT in the class below,
# so they survive untouched.
new = re.sub(r"\s*[—–]\s*", ", ", out)
+ # ASCII double hyphen used as a dash-aside (" -- ") reads as the same hard
+ # TTS pause; collapse it too (2026-06-30: the Unicode-only scrub missed it,
+ # and several canned phrases / LLM outputs use " -- "). Require surrounding
+ # whitespace so hyphen compounds ("T-Shirt") and numeric ranges ("20-30") —
+ # which have no spaces — survive untouched.
+ new = re.sub(r"\s+-{2,}\s+", ", ", new)
if new != out:
actions.append("removed_em_dash")
out = new
diff --git a/jarvis/core/config.py b/jarvis/core/config.py
index d64d2e5666..a6814785e8 100644
--- a/jarvis/core/config.py
+++ b/jarvis/core/config.py
@@ -178,6 +178,16 @@ class TriggerConfig(BaseModel):
# 2026-05-18: single-turn is the canonical behaviour — open-mic mode
# made Jarvis trigger on every word in the room.
single_turn_mode: bool = True
+ # Silence window (seconds) after which a CONVERSATION-mode voice session
+ # (``single_turn_mode = false``) auto-hangs-up while waiting for the next
+ # user turn. Set to 0 — or any value <= 0 — to DISABLE the auto-hangup
+ # entirely: the session then stays active until you hang up manually (say
+ # "auflegen" or press the hangup hotkey). User mandate 2026-06-30. Has no
+ # effect in single-turn mode (each turn ends after Jarvis answers anyway).
+ # Wired into ``SpeechPipeline(idle_timeout_s=...)`` at every construction
+ # site; the constructor default (30 s) stays the safe baseline for a fresh
+ # download so an accidental wake never holds the mic open forever.
+ session_idle_timeout_s: float = 30.0
# When True (default, user mandate 2026-05-29), the configured ``hotkey`` is
# a true push-to-talk key: holding it records, releasing it submits the
# captured audio as one prompt (one-shot — Jarvis answers once, then the
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index 7a95e26048..d86cf713a2 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -1311,7 +1311,16 @@ class SpeechPipeline:
# re-enumerated PortAudio table (post-reboot idx-drift cure, BUG-014).
self._output_device = output_device
self._input_device = input_device
- self._idle_timeout_s = idle_timeout_s
+ # Idle/silence auto-hangup. A value <= 0 DISABLES it: the session then
+ # waits forever for the next utterance or a manual hangup (hotkey /
+ # "auflegen"), exactly the "stay active until I hang up" mandate
+ # (2026-06-30). ``_idle_timeout_s`` is kept at a sane POSITIVE value even
+ # when disabled because the re-arm grace fields below are derived from it
+ # and the grace math must never see a zero/negative window; those graces
+ # are only consulted on the idle-expiry branch, which is unreachable once
+ # the hangup is disabled (the loop passes ``timeout=None`` to asyncio.wait).
+ self._idle_hangup_enabled = idle_timeout_s > 0
+ self._idle_timeout_s = idle_timeout_s if idle_timeout_s > 0 else 30.0
# Monotonic timestamp of the last out-of-band announcement Jarvis
# actually SPOKE (mission/background readback, preamble) plus the grace
# window it grants. An async readback is delivered via ``_on_announcement``
@@ -1323,7 +1332,7 @@ class SpeechPipeline:
# idle_timeout hangup at :18). The idle-expiry branch re-arms a fresh
# window while within this grace. Bounded — one full window's worth.
self._last_announcement_spoken_monotonic: float | None = None
- self._post_readback_grace_s: float = idle_timeout_s
+ self._post_readback_grace_s: float = self._idle_timeout_s
# Monotonic timestamp of the moment Jarvis last STOPPED speaking an
# inline answer (SPEAKING -> LISTENING). A long turn dispatched OFF the
# ``_active_session`` loop — the delegation grace / completion timer buffers
@@ -4425,7 +4434,17 @@ class SpeechPipeline:
try:
done, _pending = await asyncio.wait(
{next_task, hangup_task},
- timeout=self._idle_timeout_s,
+ # Idle auto-hangup disabled (``session_idle_timeout_s``
+ # <= 0) → wait indefinitely for an utterance or a
+ # manual hangup; the idle-expiry branch below is then
+ # never reached, so the session stays active until the
+ # user hangs up. Otherwise bound the LISTENING window
+ # so a silent session hangs up after the timeout.
+ timeout=(
+ self._idle_timeout_s
+ if getattr(self, "_idle_hangup_enabled", True)
+ else None
+ ),
return_when=asyncio.FIRST_COMPLETED,
)
except asyncio.CancelledError:
@@ -7723,6 +7742,7 @@ async def _main() -> None:
tts=tts,
brain_callback=brain,
enable_whisper_wake=True,
+ idle_timeout_s=config.trigger.session_idle_timeout_s,
input_device=config.audio.input_device or None,
output_device=config.audio.output_device or None,
)
diff --git a/jarvis/speech/watchdog.py b/jarvis/speech/watchdog.py
index 96bd2f8692..75419b9d9d 100644
--- a/jarvis/speech/watchdog.py
+++ b/jarvis/speech/watchdog.py
@@ -138,6 +138,9 @@ async def _main() -> None:
# User-Mandat 2026-05-18: every turn requires a fresh wake. The Toml
# field ``[trigger].single_turn_mode`` is the canonical source.
continue_listening_after_response=not config.trigger.single_turn_mode,
+ # ``session_idle_timeout_s`` <= 0 keeps a conversation session active
+ # until a manual hangup; the 30 s default stays the safe baseline.
+ idle_timeout_s=config.trigger.session_idle_timeout_s,
bus=bus,
supervisor=supervisor,
input_device=config.audio.input_device or None,
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.py
index 8898d3f13b..d34d8442bd 100644
--- a/jarvis/ui/desktop_app.py
+++ b/jarvis/ui/desktop_app.py
@@ -2335,6 +2335,10 @@ class DesktopApp:
continue_listening_after_response=(
not self.cfg.trigger.single_turn_mode
),
+ # Conversation-mode idle auto-hangup. ``session_idle_timeout_s``
+ # <= 0 keeps the session active until a manual hangup (user
+ # mandate). The constructor default (30 s) is the safe baseline.
+ idle_timeout_s=self.cfg.trigger.session_idle_timeout_s,
bus=bus,
supervisor=supervisor,
input_device=self.cfg.audio.input_device or None,
diff --git a/tests/unit/brain/test_output_filter.py b/tests/unit/brain/test_output_filter.py
index f51235b0ec..803bcde4f1 100644
--- a/tests/unit/brain/test_output_filter.py
+++ b/tests/unit/brain/test_output_filter.py
@@ -353,6 +353,24 @@ def test_trailing_em_dash_leaves_no_dangling_comma() -> None:
assert not result.cleaned.endswith(",")
+def test_ascii_double_hyphen_dash_aside_becomes_comma() -> None:
+ """A ' -- ' dash-aside (ASCII double hyphen, space-surrounded) reads as the
+ same hard TTS pause as an em dash — collapse it to a comma too. The
+ Unicode-only scrub missed it, and several canned phrases / LLM outputs use
+ ' -- ' (live forensic 2026-06-30)."""
+ result = scrub_for_voice("Mach ich -- ich sage Bescheid, sobald es fertig ist.")
+ assert "--" not in result.cleaned
+ assert "Mach ich, ich sage Bescheid" in result.cleaned
+
+
+def test_ascii_hyphen_compound_and_range_survive_double_hyphen_filter() -> None:
+ """No false positive: a compound ('T-Shirt') or numeric range ('20-30') has
+ no surrounding spaces and must survive the double-hyphen scrub."""
+ result = scrub_for_voice("Dein T-Shirt kostet 20-30 Euro.")
+ assert "T-Shirt" in result.cleaned
+ assert "20-30" in result.cleaned
+
+
def test_fallback_used_true_only_for_stacktrace() -> None:
"""``fallback_used`` nur ``True`` wenn der gesamte Text durch Standard-
Phrase ersetzt wurde (Stacktrace), nicht bei Teil-Scrub."""
diff --git a/tests/unit/speech/test_idle_timeout_disabled.py b/tests/unit/speech/test_idle_timeout_disabled.py
new file mode 100644
index 0000000000..155f87081e
--- /dev/null
+++ b/tests/unit/speech/test_idle_timeout_disabled.py
@@ -0,0 +1,143 @@
+"""A conversation session must stay active until a MANUAL hangup when the idle
+timeout is disabled.
+
+User mandate 2026-06-30: in conversation mode (``single_turn_mode = false``) the
+only time-based auto-ender is the idle/silence timeout in ``_active_session``
+(default 30 s). The user wants the session to stay active indefinitely and end
+ONLY on an explicit hangup ("auflegen" / the hangup hotkey). Setting
+``[trigger] session_idle_timeout_s = 0`` (any value <= 0) disables the idle
+hangup: ``SpeechPipeline(idle_timeout_s=0)`` then never returns
+``HANGUP_IDLE_TIMEOUT`` on its own — it waits forever for the next utterance or a
+manual hangup.
+
+These guards pin that contract; pre-fix the session hung up on the first idle
+window.
+"""
+from __future__ import annotations
+
+import asyncio
+from collections.abc import AsyncIterator
+from dataclasses import dataclass, field
+
+import pytest
+
+from jarvis.core.bus import EventBus
+from jarvis.core.protocols import AudioChunk
+from jarvis.sessions.constants import HANGUP_HOTKEY, HANGUP_IDLE_TIMEOUT
+from jarvis.speech import pipeline as pipeline_mod
+from jarvis.speech.pipeline import SpeechPipeline
+
+
+@dataclass
+class FakeTTS:
+ name: str = "fake-tts"
+ supports_streaming: bool = True
+ calls: list[tuple[str, str | None]] = field(default_factory=list)
+
+ async def synthesize(
+ self, text: str, voice: str | None = None,
+ language_code: str | None = None,
+ ) -> AsyncIterator[AudioChunk]:
+ self.calls.append((text, language_code))
+ if False: # pragma: no cover
+ yield # type: ignore[unreachable]
+
+
+class _FakeMic:
+ async def __aenter__(self) -> "_FakeMic":
+ return self
+
+ async def __aexit__(self, *args: object) -> bool:
+ return False
+
+ def stream(self):
+ async def gen():
+ await asyncio.Event().wait() # pragma: no cover — never yields
+ yield b""
+ return gen()
+
+
+class _FakeVAD:
+ def utterances(self, stream):
+ async def gen():
+ await asyncio.Event().wait() # silence: never an utterance
+ yield b"" # pragma: no cover
+ return gen()
+
+
+def _pipeline(idle_timeout_s: float) -> SpeechPipeline:
+ return SpeechPipeline(
+ tts=FakeTTS(),
+ bus=EventBus(),
+ enable_whisper_wake=False,
+ idle_timeout_s=idle_timeout_s,
+ )
+
+
+# ---------------------------------------------------------------------------
+# Config schema default + constructor flag
+# ---------------------------------------------------------------------------
+
+
+def test_trigger_config_session_idle_timeout_default() -> None:
+ # Downloaders keep the safe 30 s auto-hangup; only an explicit 0 disables it.
+ from jarvis.core.config import TriggerConfig
+
+ assert TriggerConfig().session_idle_timeout_s == 30.0
+
+
+ "value,enabled",
+ [(30.0, True), (0.0, False), (-1.0, False)],
+)
+def test_idle_hangup_enabled_flag(value: float, enabled: bool) -> None:
+ pipe = _pipeline(value)
+ assert pipe._idle_hangup_enabled is enabled
+
+
+# ---------------------------------------------------------------------------
+# Behavioural: the real bug repro (drives the actual ``_active_session`` loop)
+# ---------------------------------------------------------------------------
+
+
+async def test_active_session_never_idle_hangs_up_when_disabled(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """With the idle timeout disabled, a silent session must NOT hang up — it
+ stays open until a manual hangup. Pre-fix (``timeout=0``) the idle branch
+ fired immediately and returned ``HANGUP_IDLE_TIMEOUT``."""
+ pipe = _pipeline(0)
+ monkeypatch.setattr(
+ pipeline_mod, "MicrophoneCapture", lambda device=None: _FakeMic(),
+ )
+ pipe._vad = _FakeVAD()
+
+ session = asyncio.create_task(pipe._active_session())
+ # Many "idle windows" worth of silence — the session must still be alive.
+ await asyncio.sleep(0.25)
+ assert not session.done(), (
+ "the session hung up by itself — with the idle timeout disabled it must "
+ "stay active until a manual hangup"
+ )
+
+ # A manual hangup (hotkey / 'auflegen' setting the event) ends it cleanly.
+ pipe._hangup_event.set()
+ reason = await asyncio.wait_for(session, timeout=2.0)
+ assert reason == HANGUP_HOTKEY
+
+
+async def test_active_session_still_idle_hangs_up_when_enabled(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """Regression guard the other way: a positive timeout still auto-hangs-up so
+ the default behaviour (and every downloader) is unchanged."""
+ pipe = _pipeline(0.05) # tiny positive window → fast test
+ monkeypatch.setattr(
+ pipeline_mod, "MicrophoneCapture", lambda device=None: _FakeMic(),
+ )
+ pipe._vad = _FakeVAD()
+
+ reason = await asyncio.wait_for(pipe._active_session(), timeout=2.0)
+ assert reason == HANGUP_IDLE_TIMEOUT