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(voice): re-check the hangup gate at speaking time + add a voice-session auditor

Ruben Lütkedaa47b523974
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index 0fe1c68951..a54fb83b46 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -3260,6 +3260,21 @@ class SpeechPipeline:
event.text[:80],
)
return
+ # Re-check the hangup gate at the moment of SPEAKING, not only at
+ # arrival: the user can hang up during the seconds between the two
+ # (scrub, dedup, the realtime-delivery probe), and the entry check
+ # has already passed by then. A stale ephemeral line then plays into
+ # or right after the ended call as a phantom second voice (forensic
+ # 2026-07-13 18:37: hotkey hang-up landed 1.2 s after the preamble
+ # entered this handler). Owed readbacks still punch through, exactly
+ # like at the entry gate (AD-OE5/OE6).
+ if hangup is not None and hangup.is_set() and not is_readback:
+ log.info(
+ "Announcement dropped — session hung up while it was being "
+ "prepared: %r",
+ event.text[:80],
+ )
+ return
# We are now committed to actually speaking this announcement (past every
# suppression / defer / empty guard). Record it as voice activity so the
# idle-timeout branch in ``_active_session`` re-arms a fresh window: an
diff --git a/scripts/diag_voice_sessions.py b/scripts/diag_voice_sessions.py
new file mode 100644
index 0000000000..74a25a95f3
--- /dev/null
+++ b/scripts/diag_voice_sessions.py
@@ -0,0 +1,288 @@
+"""Audit recorded voice sessions against the known failure classes.
+
+Reads the flight recorder (``data/flight_recorder/YYYY-MM-DD.jsonl``), splits
+it into voice sessions, and checks every session for the failure patterns
+confirmed in the 2026-07-13 realtime forensics (BUG-047..BUG-050):
+
+- ``promise-without-action`` — a turn ends on a deferred-action claim while
+ its ``tool_calls`` are empty (the model promised and nothing ran).
+- ``voice-identity-break`` — a non-realtime layer spoke (classic pipeline
+ TTS) while a live realtime session owned the voice.
+- ``tool-retry-loop`` — the same tool failed three or more times inside one
+ session (the model grinding against a broken/lying tool).
+- ``exhausted-brain-turn`` — a brain turn died on ``budget_exceeded`` or
+ returned no text at all (outside the legitimate suppress paths).
+- ``silent-turn`` — a user turn completed without any assistant text.
+
+Usage::
+
+ python scripts/diag_voice_sessions.py # today's sessions
+ python scripts/diag_voice_sessions.py --date 2026-07-13
+ python scripts/diag_voice_sessions.py --last 3 # newest N sessions only
+
+Read-only developer diagnostic: no app, network, or config access.
+"""
+from __future__ import annotations
+
+import argparse
+import json
+import sys
+from collections import Counter
+from dataclasses import dataclass, field
+from datetime import date
+from pathlib import Path
+from typing import Any
+
+REPO_ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(REPO_ROOT))
+
+from jarvis.brain.action_honesty import has_deferred_action_claim # noqa: E402
+
+_MAX_PREVIEW_CHARS = 90
+_RETRY_LOOP_THRESHOLD = 3
+# Brain turns that legitimately produce no user-facing text.
+_SUPPRESSED_FINISH_REASONS = frozenset({"suppress_response", "voice_confirm_pending"})
+
+
+@dataclass(slots=True)
+class Finding:
+ severity: str # "high" | "warn" | "info"
+ kind: str
+ detail: str
+
+
+@dataclass(slots=True)
+class Session:
+ session_id: str
+ started_ts_ns: int
+ events: list[dict[str, Any]] = field(default_factory=list)
+ findings: list[Finding] = field(default_factory=list)
+
+ @property
+ def turn_count(self) -> int:
+ return sum(1 for e in self.events if e.get("event") == "VoiceTurnCompleted")
+
+
+def _preview(text: Any) -> str:
+ cleaned = " ".join(str(text or "").split())
+ if len(cleaned) <= _MAX_PREVIEW_CHARS:
+ return cleaned
+ return cleaned[: _MAX_PREVIEW_CHARS - 1] + "…"
+
+
+def _split_sessions(events: list[dict[str, Any]]) -> list[Session]:
+ """Assign events to sessions by id where present, else by time window."""
+ sessions: list[Session] = []
+ active: Session | None = None
+ for event in events:
+ payload = event.get("payload") or {}
+ name = event.get("event", "")
+ if name == "VoiceSessionStarted":
+ active = Session(
+ session_id=str(payload.get("session_id", "?")),
+ started_ts_ns=int(event.get("ts_ns", 0)),
+ )
+ sessions.append(active)
+ if active is not None:
+ event_session = payload.get("session_id")
+ if event_session is None or event_session == active.session_id:
+ active.events.append(event)
+ if name == "VoiceSessionEnded" and active is not None:
+ if payload.get("session_id") in (None, active.session_id):
+ active = None
+ return sessions
+
+
+def _check_promise_without_action(session: Session) -> None:
+ for event in session.events:
+ if event.get("event") != "VoiceTurnCompleted":
+ continue
+ payload = event.get("payload") or {}
+ jarvis_text = str(payload.get("jarvis_text", "") or "")
+ tool_calls = payload.get("tool_calls") or ()
+ if jarvis_text and not tool_calls and has_deferred_action_claim(jarvis_text):
+ session.findings.append(
+ Finding(
+ severity="high",
+ kind="promise-without-action",
+ detail=(
+ "turn ended on a future-work claim with no tool call: "
+ f"\"{_preview(jarvis_text)}\""
+ ),
+ )
+ )
+
+
+def _check_voice_identity(session: Session) -> None:
+ realtime_live = False
+ for event in session.events:
+ name = event.get("event", "")
+ if name == "RealtimeSessionReady":
+ realtime_live = True
+ elif name == "VoiceSessionEnded":
+ realtime_live = False
+ elif name == "SpeechSpoken" and realtime_live:
+ layer = str(event.get("layer", "") or "")
+ if layer and not layer.startswith("realtime."):
+ payload = event.get("payload") or {}
+ session.findings.append(
+ Finding(
+ severity="high",
+ kind="voice-identity-break",
+ detail=(
+ f"layer {layer!r} spoke into the live realtime call: "
+ f"\"{_preview(payload.get('text'))}\""
+ ),
+ )
+ )
+
+
+def _check_tool_retry_loops(session: Session) -> None:
+ failures: Counter[str] = Counter()
+ last_error: dict[str, str] = {}
+ for event in session.events:
+ if event.get("event") != "ActionExecuted":
+ continue
+ payload = event.get("payload") or {}
+ if payload.get("success"):
+ continue
+ tool = str(payload.get("tool_name", "?"))
+ failures[tool] += 1
+ last_error[tool] = _preview(payload.get("error"))
+ for tool, count in failures.items():
+ if count >= _RETRY_LOOP_THRESHOLD:
+ session.findings.append(
+ Finding(
+ severity="warn",
+ kind="tool-retry-loop",
+ detail=(
+ f"{tool} failed {count}x (last error: "
+ f"{last_error.get(tool, '?')})"
+ ),
+ )
+ )
+
+
+def _check_exhausted_brain_turns(session: Session) -> None:
+ for event in session.events:
+ if event.get("event") != "BrainTurnCompleted":
+ continue
+ payload = event.get("payload") or {}
+ finish = str(payload.get("finish_reason", "") or "")
+ text_len = int(payload.get("text_len", 0) or 0)
+ if finish == "budget_exceeded":
+ session.findings.append(
+ Finding(
+ severity="high",
+ kind="exhausted-brain-turn",
+ detail=(
+ "iteration budget exhausted before an answer "
+ f"(tokens_in={payload.get('tokens_in')})"
+ ),
+ )
+ )
+ elif text_len == 0 and finish not in _SUPPRESSED_FINISH_REASONS:
+ session.findings.append(
+ Finding(
+ severity="warn",
+ kind="empty-brain-turn",
+ detail=f"brain turn produced no text (finish_reason={finish!r})",
+ )
+ )
+
+
+def _check_silent_turns(session: Session) -> None:
+ for event in session.events:
+ if event.get("event") != "VoiceTurnCompleted":
+ continue
+ payload = event.get("payload") or {}
+ user_text = str(payload.get("user_text", "") or "").strip()
+ jarvis_text = str(payload.get("jarvis_text", "") or "").strip()
+ # A one/two-word interjection ("Hm?") legitimately gets no reply.
+ if jarvis_text or len(user_text.split()) < 3:
+ continue
+ session.findings.append(
+ Finding(
+ severity="info",
+ kind="silent-turn",
+ detail=f"no assistant text for: \"{_preview(user_text)}\"",
+ )
+ )
+
+
+_CHECKS = (
+ _check_promise_without_action,
+ _check_voice_identity,
+ _check_tool_retry_loops,
+ _check_exhausted_brain_turns,
+ _check_silent_turns,
+)
+
+
+def audit_events(events: list[dict[str, Any]]) -> list[Session]:
+ """Split raw flight-recorder events and run every check per session."""
+ sessions = _split_sessions(events)
+ for session in sessions:
+ for check in _CHECKS:
+ check(session)
+ return sessions
+
+
+def _load_events(path: Path) -> list[dict[str, Any]]:
+ events: list[dict[str, Any]] = []
+ with path.open(encoding="utf-8") as handle:
+ for line in handle:
+ try:
+ events.append(json.loads(line))
+ except json.JSONDecodeError:
+ continue
+ return events
+
+
+def _format_report(sessions: list[Session]) -> str:
+ lines: list[str] = []
+ total_findings = 0
+ for session in sessions:
+ header = (
+ f"session {session.session_id[:8]} turns={session.turn_count} "
+ f"findings={len(session.findings)}"
+ )
+ lines.append(header)
+ for finding in session.findings:
+ total_findings += 1
+ lines.append(f" [{finding.severity:4}] {finding.kind}: {finding.detail}")
+ lines.append(
+ f"\n{len(sessions)} session(s), {total_findings} finding(s)."
+ )
+ return "\n".join(lines)
+
+
+def main(argv: list[str] | None = None) -> int:
+ parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
+ parser.add_argument(
+ "--date",
+ default=date.today().isoformat(),
+ help="flight-recorder day to audit (YYYY-MM-DD, default: today)",
+ )
+ parser.add_argument(
+ "--last",
+ type=int,
+ default=0,
+ help="audit only the newest N sessions (default: all)",
+ )
+ args = parser.parse_args(argv)
+
+ recorder_path = REPO_ROOT / "data" / "flight_recorder" / f"{args.date}.jsonl"
+ if not recorder_path.exists():
+ print(f"no flight recorder file for {args.date}: {recorder_path}")
+ return 2
+
+ sessions = audit_events(_load_events(recorder_path))
+ if args.last > 0:
+ sessions = sessions[-args.last :]
+ print(_format_report(sessions))
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/tests/unit/scripts/test_diag_voice_sessions.py b/tests/unit/scripts/test_diag_voice_sessions.py
new file mode 100644
index 0000000000..d1a95d8a6a
--- /dev/null
+++ b/tests/unit/scripts/test_diag_voice_sessions.py
@@ -0,0 +1,177 @@
+"""The voice-session auditor must flag every confirmed failure class."""
+
+from __future__ import annotations
+
+import importlib.util
+import sys
+from pathlib import Path
+
+REPO_ROOT = Path(__file__).resolve().parents[3]
+_SPEC = importlib.util.spec_from_file_location(
+ "diag_voice_sessions", REPO_ROOT / "scripts" / "diag_voice_sessions.py"
+)
+diag = importlib.util.module_from_spec(_SPEC)
+sys.modules["diag_voice_sessions"] = diag
+_SPEC.loader.exec_module(diag)
+
+
+def _session_events(session_id: str, inner: list[dict]) -> list[dict]:
+ return [
+ {
+ "ts_ns": 1,
+ "event": "VoiceSessionStarted",
+ "layer": "speech.pipeline",
+ "payload": {"session_id": session_id},
+ },
+ {
+ "ts_ns": 2,
+ "event": "RealtimeSessionReady",
+ "layer": "realtime.fake",
+ "payload": {"session_id": session_id},
+ },
+ *inner,
+ {
+ "ts_ns": 99,
+ "event": "VoiceSessionEnded",
+ "layer": "speech.pipeline",
+ "payload": {"session_id": session_id},
+ },
+ ]
+
+
+def _kinds(sessions) -> set[str]:
+ return {f.kind for s in sessions for f in s.findings}
+
+
+def test_promise_without_action_is_flagged() -> None:
+ events = _session_events(
+ "s1",
+ [
+ {
+ "ts_ns": 10,
+ "event": "VoiceTurnCompleted",
+ "layer": "realtime.fake",
+ "payload": {
+ "session_id": "s1",
+ "user_text": "List my wiki files.",
+ "jarvis_text": (
+ "Einen Moment, ich werfe einen Blick in dein Wiki " # i18n-allow: forensic fixture
+ "und sage dir gleich, was drinsteht." # i18n-allow: forensic fixture
+ ),
+ "tool_calls": [],
+ },
+ }
+ ],
+ )
+ assert "promise-without-action" in _kinds(diag.audit_events(events))
+
+
+def test_backed_promise_is_not_flagged() -> None:
+ events = _session_events(
+ "s1",
+ [
+ {
+ "ts_ns": 10,
+ "event": "VoiceTurnCompleted",
+ "layer": "realtime.fake",
+ "payload": {
+ "session_id": "s1",
+ "user_text": "List my wiki files.",
+ "jarvis_text": "Ich schaue gleich in dein Wiki.", # i18n-allow: fixture
+ "tool_calls": ["jarvis_action"],
+ },
+ }
+ ],
+ )
+ assert "promise-without-action" not in _kinds(diag.audit_events(events))
+
+
+def test_classic_voice_inside_live_realtime_call_is_flagged() -> None:
+ events = _session_events(
+ "s1",
+ [
+ {
+ "ts_ns": 10,
+ "event": "SpeechSpoken",
+ "layer": "speech.pipeline",
+ "payload": {"text": "I am searching your wiki right now."},
+ }
+ ],
+ )
+ assert "voice-identity-break" in _kinds(diag.audit_events(events))
+
+
+def test_realtime_voice_is_not_flagged() -> None:
+ events = _session_events(
+ "s1",
+ [
+ {
+ "ts_ns": 10,
+ "event": "SpeechSpoken",
+ "layer": "realtime.openai-realtime",
+ "payload": {"text": "Here is your wiki."},
+ }
+ ],
+ )
+ assert "voice-identity-break" not in _kinds(diag.audit_events(events))
+
+
+def test_tool_retry_loop_and_budget_exhaustion_are_flagged() -> None:
+ failure = {
+ "event": "ActionExecuted",
+ "layer": "",
+ "payload": {
+ "tool_name": "run_shell",
+ "success": False,
+ "error": "Not found: [WinError 2]",
+ },
+ }
+ events = _session_events(
+ "s1",
+ [
+ {**failure, "ts_ns": 10},
+ {**failure, "ts_ns": 11},
+ {**failure, "ts_ns": 12},
+ {
+ "ts_ns": 13,
+ "event": "BrainTurnCompleted",
+ "layer": "",
+ "payload": {
+ "finish_reason": "budget_exceeded",
+ "text_len": 0,
+ "tokens_in": 404606,
+ },
+ },
+ ],
+ )
+ kinds = _kinds(diag.audit_events(events))
+ assert "tool-retry-loop" in kinds
+ assert "exhausted-brain-turn" in kinds
+
+
+def test_clean_session_yields_no_findings() -> None:
+ events = _session_events(
+ "s1",
+ [
+ {
+ "ts_ns": 10,
+ "event": "VoiceTurnCompleted",
+ "layer": "realtime.fake",
+ "payload": {
+ "session_id": "s1",
+ "user_text": "What time is it?",
+ "jarvis_text": "It is nine in the evening.",
+ "tool_calls": [],
+ },
+ },
+ {
+ "ts_ns": 11,
+ "event": "BrainTurnCompleted",
+ "layer": "",
+ "payload": {"finish_reason": "voice_confirm_pending", "text_len": 0},
+ },
+ ],
+ )
+ sessions = diag.audit_events(events)
+ assert len(sessions) == 1
+ assert sessions[0].findings == []
diff --git a/tests/unit/speech/test_realtime_announcement_bridge.py b/tests/unit/speech/test_realtime_announcement_bridge.py
index 4845cc384d..1fdfd9ecc4 100644
--- a/tests/unit/speech/test_realtime_announcement_bridge.py
+++ b/tests/unit/speech/test_realtime_announcement_bridge.py
@@ -150,6 +150,68 @@ async def test_busy_live_session_drops_ephemeral_preamble() -> None:
assert pipeline._deferred_announcements == []
+class _HangupDuringDeliveryHandle(_FakeRealtimeHandle):
+ """Simulates the 18:37 race: the user hangs up mid-delivery probe.
+
+ The desktop loop's ``finally`` clears ``_active_realtime_handle`` the
+ moment the call unwinds, so by the time the announcement reaches the
+ speaking stage the entry hangup gate has long been passed.
+ """
+
+ def __init__(self, pipeline, hangup_event) -> None:
+ super().__init__(accepted=False)
+ self._pipeline = pipeline
+ self._hangup_event = hangup_event
+
+ async def deliver_announcement(self, **kwargs: object) -> bool:
+ self._hangup_event.set()
+ self._pipeline._active_realtime_handle = None
+ return await super().deliver_announcement(**kwargs)
+
+
+async def test_hangup_during_delivery_drops_the_stale_preamble() -> None:
+ """A preamble whose call ended mid-preparation must never be spoken."""
+ pipeline, tts, player, _realtime = _pipeline(accepted=False)
+ hangup = asyncio.Event()
+ pipeline._hangup_event = hangup
+ handle = _HangupDuringDeliveryHandle(pipeline, hangup)
+ pipeline._active_realtime_handle = handle
+
+ await pipeline._on_announcement(
+ AnnouncementRequested(
+ text="I am searching the current data right now.",
+ language="en",
+ kind="preamble",
+ )
+ )
+
+ assert len(handle.calls) == 1
+ assert tts.calls == []
+ assert player.plays == 0
+
+
+async def test_hangup_during_delivery_keeps_the_owed_readback() -> None:
+ """An owed completion still punches through, like at the entry gate."""
+ pipeline, tts, player, _realtime = _pipeline(accepted=False)
+ hangup = asyncio.Event()
+ pipeline._hangup_event = hangup
+ handle = _HangupDuringDeliveryHandle(pipeline, hangup)
+ pipeline._active_realtime_handle = handle
+
+ await pipeline._on_announcement(
+ AnnouncementRequested(
+ text="The research report is ready.",
+ language="en",
+ kind="completion",
+ )
+ )
+
+ assert tts.calls == [("The research report is ready.", "en-US")]
+ assert player.plays == 1
+
+
@pytest.mark.asyncio
async def test_deferred_readback_is_replayed_to_the_idle_live_model() -> None:
"""At the turn boundary the parked readback reaches the live voice."""