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-07-14 15:26)

Ruben Lütke92fe2c91c0b3
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.py
index 54874742be..f679cd7b66 100644
--- a/jarvis/plugins/realtime/openai_realtime.py
+++ b/jarvis/plugins/realtime/openai_realtime.py
@@ -24,7 +24,19 @@ _INPUT_RATE = 24_000
_OUTPUT_RATE = 24_000
_HANDSHAKE_TIMEOUT_S = 12.0
_RESPONSE_REQUEST_METADATA_KEY = "jarvis_request_id"
-_RECOVERABLE_ERROR_CODES = frozenset({"conversation_already_has_active_response"})
+# Benign response-lifecycle races (BUG-053/BUG-056): both sides of the same
+# boundary. ``conversation_already_has_active_response`` = our response.create
+# arrived while one was still running; ``response_cancel_not_active`` = our
+# response.cancel arrived after the response already finished — the outcome the
+# cancel wanted has already happened, so it is an idempotent no-op, never a
+# broken connection. Labeling either terminal ended healthy live calls with
+# hangup_reason=error (barge-in 09:04 and scrub-cancel 15:13, 2026-07-14).
+_RECOVERABLE_ERROR_CODES = frozenset(
+ {
+ "conversation_already_has_active_response",
+ "response_cancel_not_active",
+ }
+)
@dataclass(frozen=True, slots=True)
@@ -368,6 +380,13 @@ class _OpenAIRealtimeSession:
self._tool_response_done_seen = False
self._pending_tool_call_ids.clear()
self._last_item_id = ""
+ # BUG-053 correction 2: with no response lifecycle in flight there is
+ # nothing to cancel — skip the wire call that could only ever produce
+ # the benign ``response_cancel_not_active`` error. The recoverable
+ # classification above stays necessary regardless: the provider can
+ # still finish between this local check and the wire operation.
+ if self._response_idle.is_set():
+ return
try:
await self._conn.response.cancel()
finally:
diff --git a/jarvis/sessions/constants.py b/jarvis/sessions/constants.py
index 352417b5ec..64183988d7 100644
--- a/jarvis/sessions/constants.py
+++ b/jarvis/sessions/constants.py
@@ -137,6 +137,12 @@ SPOKEN_KIND_PREAMBLE: Final[str] = "preamble"
SPOKEN_KIND_PROGRESS: Final[str] = "progress"
"""A 'still working' nudge while a long background mission runs."""
+SPOKEN_KIND_WITHHELD: Final[str] = "withheld"
+"""The safety scrubber cancelled an unsafe answer mid-output; this is the
+spoken fallback line. Recording it keeps the transcript honest about WHY the
+audible answer stopped (BUG-056: the 15:13 session showed a truncated reply
+with no trace of the abort)."""
+
SPOKEN_KIND_OTHER: Final[str] = "other"
"""Catch-all for any voiced phrase without a more specific tag."""
@@ -153,6 +159,7 @@ SPOKEN_KINDS: Final[tuple[str, ...]] = (
SPOKEN_KIND_ANNOUNCEMENT,
SPOKEN_KIND_PREAMBLE,
SPOKEN_KIND_PROGRESS,
+ SPOKEN_KIND_WITHHELD,
SPOKEN_KIND_OTHER,
)
"""All accepted ``SpeechSpoken.spoken_kind`` values. Order is stable for tests."""
diff --git a/tests/unit/realtime/test_openai_realtime.py b/tests/unit/realtime/test_openai_realtime.py
index d40a0bc80b..5b6a958f3d 100644
--- a/tests/unit/realtime/test_openai_realtime.py
+++ b/tests/unit/realtime/test_openai_realtime.py
@@ -788,3 +788,74 @@ async def test_live_session_update_replaces_tool_declarations(
assert update["tools"] == [{"type": "function", **declaration}]
assert update["tool_choice"] == "auto"
await session.close()
+
+
+async def test_response_cancel_not_active_error_is_recoverable(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """BUG-053/BUG-056: a cancel that loses the response-boundary race is a
+ benign no-op — the response it wanted dead is already gone. The provider's
+ ``response_cancel_not_active`` error must surface as RECOVERABLE so the
+ session pump warns and continues instead of ending the call (live
+ incidents 09:04 barge-in and 15:13 scrub-cancel, both 2026-07-14)."""
+ holder = _patch_openai_client(monkeypatch)
+ session = await OpenAIRealtimeProvider(api_key="test-key").open_session(
+ RealtimeSessionConfig()
+ )
+ conn = holder["client"].realtime.last_conn
+ conn._events = iter(
+ [
+ SimpleNamespace(
+ type="error",
+ error=SimpleNamespace(
+ code="response_cancel_not_active",
+ message="Cancellation failed: no active response found",
+ ),
+ ),
+ ]
+ )
+
+ events = [event async for event in session.receive()]
+
+ assert [event.type for event in events] == ["error"]
+ assert events[0].recoverable is True
+ await session.close()
+
+
+async def test_interrupt_skips_wire_cancel_when_no_response_active(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """BUG-053 correction 2: when the adapter already knows no response
+ lifecycle is active, ``interrupt()`` must not put ``response.cancel`` on
+ the wire at all — that request can only ever produce the benign error."""
+ holder = _patch_openai_client(monkeypatch)
+ session = await OpenAIRealtimeProvider(api_key="test-key").open_session(
+ RealtimeSessionConfig()
+ )
+ conn = holder["client"].realtime.last_conn
+
+ await session.interrupt()
+
+ assert conn.response_cancels == []
+ await session.close()
+
+
+async def test_interrupt_still_cancels_while_response_active(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """The skip above must never eat a REAL cancellation: with a response
+ lifecycle in flight, interrupt() still sends response.cancel."""
+ holder = _patch_openai_client(monkeypatch)
+ session = await OpenAIRealtimeProvider(api_key="test-key").open_session(
+ RealtimeSessionConfig()
+ )
+ conn = holder["client"].realtime.last_conn
+
+ await session.request_response()
+ await session.interrupt()
+
+ assert conn.response_cancels == ["<active>"]
+ await session.close()