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.

test(realtime): self-skipping E2E smoke + boot-budget/lint/type guards + cleanup fixes

Ruben Lütkec28ee43848db
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.py
index e5318b906b..4800ef891c 100644
--- a/jarvis/plugins/realtime/openai_realtime.py
+++ b/jarvis/plugins/realtime/openai_realtime.py
@@ -87,27 +87,29 @@ class OpenAIRealtimeProvider:
async def can_open_duplex_session(self) -> bool:
return bool(get_provider_secret("openai"))
- async def open_session(self, cfg: RealtimeSessionConfig):
+ async def open_session(self, cfg: RealtimeSessionConfig) -> _OpenAIRealtimeSession:
from openai import AsyncOpenAI # lazy (AP-26)
client = AsyncOpenAI(api_key=get_provider_secret("openai"))
conn = await client.realtime.connect(model=_MODEL).__aenter__()
- await conn.session.update(
- session={
- "instructions": cfg.instructions,
- "output_modalities": list(cfg.modalities),
- "audio": {
- "input": {
- "format": {"type": "audio/pcm", "rate": cfg.input_sample_rate},
- "turn_detection": {"type": cfg.turn_detection},
- },
- "output": {
- "format": {"type": "audio/pcm"},
- **({"voice": cfg.voice} if cfg.voice else {}),
- },
+ session_payload: dict[str, Any] = {
+ "instructions": cfg.instructions,
+ "output_modalities": list(cfg.modalities),
+ "audio": {
+ "input": {
+ "format": {"type": "audio/pcm", "rate": cfg.input_sample_rate},
+ "turn_detection": {"type": cfg.turn_detection},
},
- }
- )
+ "output": {
+ "format": {"type": "audio/pcm"},
+ **({"voice": cfg.voice} if cfg.voice else {}),
+ },
+ },
+ }
+ # The openai SDK's session.update() TypedDict shape is stricter than the
+ # GA over-the-wire schema we build here; a plain dict is what the API
+ # actually accepts.
+ await conn.session.update(session=session_payload) # type: ignore[arg-type]
import uuid
return _OpenAIRealtimeSession(conn, cfg, session_id=str(uuid.uuid4()))
diff --git a/jarvis/realtime/factory.py b/jarvis/realtime/factory.py
index 5fcce1174b..31fd5ba96f 100644
--- a/jarvis/realtime/factory.py
+++ b/jarvis/realtime/factory.py
@@ -22,10 +22,11 @@ def build_realtime_session(
mode = getattr(getattr(cfg, "voice", None), "mode", "pipeline")
if mode != "realtime":
return None
- if not get_provider_secret("openai"):
- log.info("realtime: no OpenAI key — falling back to the classic path")
- return None
try:
+ if not get_provider_secret("openai"):
+ log.info("realtime: no OpenAI key — falling back to the classic path")
+ return None
+
from jarvis.plugins.realtime.openai_realtime import OpenAIRealtimeProvider
from jarvis.realtime.session import RealtimeVoiceSession
diff --git a/jarvis/realtime/session.py b/jarvis/realtime/session.py
index fedf4bdb4b..fddd4e8c0f 100644
--- a/jarvis/realtime/session.py
+++ b/jarvis/realtime/session.py
@@ -89,10 +89,14 @@ class RealtimeVoiceSession:
if self._ended or self._session is None or not pcm_native:
return
try:
- pcm16 = bytes(pcm_native) if self.browser_sample_rate == STT_SAMPLE_RATE else self._in_resampler.process(bytes(pcm_native))
+ if self.browser_sample_rate == STT_SAMPLE_RATE:
+ pcm16 = bytes(pcm_native)
+ else:
+ pcm16 = self._in_resampler.process(bytes(pcm_native))
except Exception: # noqa: BLE001 — malformed frame, drop it
return
- await self._session.send_audio(AudioChunk(pcm=pcm16, sample_rate=STT_SAMPLE_RATE, timestamp_ns=0))
+ chunk = AudioChunk(pcm=pcm16, sample_rate=STT_SAMPLE_RATE, timestamp_ns=0)
+ await self._session.send_audio(chunk)
async def _pump(self) -> None:
from jarvis.telemetry.latency import LatencyPhase, mark_phase
@@ -104,17 +108,23 @@ class RealtimeVoiceSession:
if new_lang != self._language:
self._language = new_lang
self._gate = ScrubHoldGate(new_lang)
- await self._session.update_session(instructions=_INSTRUCTIONS, language=new_lang)
+ await self._session.update_session(
+ instructions=_INSTRUCTIONS, language=new_lang
+ )
mark_phase(LatencyPhase.REALTIME_INPUT_COMMITTED)
elif ev.type == "output_transcript_delta" and ev.text:
mark_phase(LatencyPhase.REALTIME_FIRST_TRANSCRIPT)
display = await self._gate.feed_transcript(ev.text)
if self._gate.hard_leak_pending():
await self._session.interrupt()
- await self._send_json({"type": "error_spoken", "text": self._gate.fallback_phrase()})
+ await self._send_json(
+ {"type": "error_spoken", "text": self._gate.fallback_phrase()}
+ )
self._gate.drain()
continue
- await self._send_json({"type": "transcript", "text": display, "is_final": False})
+ await self._send_json(
+ {"type": "transcript", "text": display, "is_final": False}
+ )
# Flush audio that this now-scrub-cleared transcript covers, so a
# LATER segment's first audio chunk is never released before its
# own transcript is scrubbed (closes the T4 one-chunk-boundary
@@ -144,16 +154,17 @@ class RealtimeVoiceSession:
try:
await self._bus.publish(AudioOutFirst())
- except Exception: # noqa: BLE001
+ except Exception: # noqa: BLE001, S110 — best-effort telemetry publish
pass
self._ms_sent += len(chunk.pcm)
await self._send_binary(chunk.pcm)
async def _barge_in(self) -> None:
self._gate.drain()
+ ms_played = self._ms_sent // (24000 * 2 // 1000) if self._ms_sent else 0
try:
- await self._session.truncate(audio_end_ms=self._ms_sent // (24000 * 2 // 1000) if self._ms_sent else 0)
- except Exception: # noqa: BLE001
+ await self._session.truncate(audio_end_ms=ms_played)
+ except Exception: # noqa: BLE001, S110 — best-effort truncate on barge-in
pass
self._ms_sent = 0
try:
@@ -170,6 +181,6 @@ class RealtimeVoiceSession:
if self._session is not None:
try:
await self._session.close()
- except Exception: # noqa: BLE001
+ except Exception: # noqa: BLE001, S110 — best-effort close on teardown
pass
log.info("realtime[%s] ended: reason=%s", self.session_id, reason)
diff --git a/jarvis/ui/web/frontend/src/lib/pcm-worklet.ts b/jarvis/ui/web/frontend/src/lib/pcm-worklet.ts
index 993e143e9f..08f6c8f8aa 100644
--- a/jarvis/ui/web/frontend/src/lib/pcm-worklet.ts
+++ b/jarvis/ui/web/frontend/src/lib/pcm-worklet.ts
@@ -26,7 +26,10 @@ function floatToInt16(float32: Float32Array): ArrayBuffer {
class PcmCapture extends AudioWorkletProcessor {
process(inputs: Float32Array[][]): boolean {
const ch = inputs[0]?.[0];
- if (ch && ch.length) this.port.postMessage(floatToInt16(ch), [floatToInt16(ch)]);
+ if (ch && ch.length) {
+ const buf = floatToInt16(ch);
+ this.port.postMessage(buf, [buf]);
+ }
return true;
}
}
diff --git a/tests/integration/realtime/test_realtime_smoke.py b/tests/integration/realtime/test_realtime_smoke.py
new file mode 100644
index 0000000000..f79c7015ef
--- /dev/null
+++ b/tests/integration/realtime/test_realtime_smoke.py
@@ -0,0 +1,49 @@
+"""Task 10 — end-to-end smoke test for the realtime provider.
+
+Self-skips cleanly when no OpenAI key is configured (CI / a fresh install
+without a key must never fail here — AP-23). With a key present it opens a
+real duplex session, drains one event with a timeout, and closes cleanly.
+"""
+
+from __future__ import annotations
+
+import asyncio
+
+import pytest
+
+from jarvis.core.config import get_provider_secret
+
+pytestmark = pytest.mark.integration
+
+
+async def test_can_open_duplex_session_returns_a_bool():
+ """Keyless-safe: the capability probe must never raise, key or no key."""
+ from jarvis.plugins.realtime.openai_realtime import OpenAIRealtimeProvider
+
+ prov = OpenAIRealtimeProvider()
+ assert isinstance(await prov.can_open_duplex_session(), bool)
+
+
[email protected](not get_provider_secret("openai"), reason="no OpenAI key")
+async def test_open_and_close_a_real_session():
+ from jarvis.plugins.realtime.openai_realtime import OpenAIRealtimeProvider
+ from jarvis.realtime.protocol import RealtimeSessionConfig
+
+ prov = OpenAIRealtimeProvider()
+ assert await prov.can_open_duplex_session() is True
+ sess = await prov.open_session(RealtimeSessionConfig(instructions="Say hi.", language="en"))
+
+ # Pull a couple of events with a timeout, then close cleanly.
+ async def _drain():
+ n = 0
+ async for _ in sess.receive():
+ n += 1
+ if n >= 1:
+ break
+
+ try:
+ await asyncio.wait_for(_drain(), timeout=10)
+ finally:
+ await sess.close()
diff --git a/tests/unit/realtime/test_session.py b/tests/unit/realtime/test_session.py
index 6b4b360edb..0f40c340df 100644
--- a/tests/unit/realtime/test_session.py
+++ b/tests/unit/realtime/test_session.py
@@ -3,7 +3,7 @@ import asyncio
import pytest
from jarvis.core.protocols import AudioChunk
-from jarvis.realtime.protocol import RealtimeEvent, RealtimeSessionConfig
+from jarvis.realtime.protocol import RealtimeEvent
from jarvis.realtime.session import RealtimeVoiceSession
@@ -57,14 +57,19 @@ class FakeProvider:
def _cfg():
from types import SimpleNamespace
- return SimpleNamespace(brain=SimpleNamespace(reply_language="en"), voice=SimpleNamespace(mode="realtime"))
+ return SimpleNamespace(
+ brain=SimpleNamespace(reply_language="en"), voice=SimpleNamespace(mode="realtime")
+ )
@pytest.mark.asyncio
async def test_clean_turn_streams_audio_and_transcript():
events = [
RealtimeEvent(type="output_transcript_delta", text="Hello there."),
- RealtimeEvent(type="audio_delta", audio=AudioChunk(pcm=b"\x01\x02" * 8, sample_rate=24000, timestamp_ns=0)),
+ RealtimeEvent(
+ type="audio_delta",
+ audio=AudioChunk(pcm=b"\x01\x02" * 8, sample_rate=24000, timestamp_ns=0),
+ ),
RealtimeEvent(type="turn_complete"),
]
binaries, jsons = [], []
@@ -86,8 +91,14 @@ async def test_clean_turn_streams_audio_and_transcript():
@pytest.mark.asyncio
async def test_hard_leak_transcript_drops_audio():
events = [
- RealtimeEvent(type="audio_delta", audio=AudioChunk(pcm=b"\x01\x02" * 8, sample_rate=24000, timestamp_ns=0)),
- RealtimeEvent(type="output_transcript_delta", text="Traceback (most recent call last):\n File a\nValueError: b\n\n"),
+ RealtimeEvent(
+ type="audio_delta",
+ audio=AudioChunk(pcm=b"\x01\x02" * 8, sample_rate=24000, timestamp_ns=0),
+ ),
+ RealtimeEvent(
+ type="output_transcript_delta",
+ text="Traceback (most recent call last):\n File a\nValueError: b\n\n",
+ ),
RealtimeEvent(type="turn_complete"),
]
binaries, jsons = [], []
@@ -117,9 +128,13 @@ async def test_later_segment_leak_audio_not_emitted():
a1 = b"\x11\x22" * 8
a2 = b"\x33\x44" * 8
events = [
- RealtimeEvent(type="audio_delta", audio=AudioChunk(pcm=a1, sample_rate=24000, timestamp_ns=0)),
+ RealtimeEvent(
+ type="audio_delta", audio=AudioChunk(pcm=a1, sample_rate=24000, timestamp_ns=0)
+ ),
RealtimeEvent(type="output_transcript_delta", text="A clean first sentence."),
- RealtimeEvent(type="audio_delta", audio=AudioChunk(pcm=a2, sample_rate=24000, timestamp_ns=0)),
+ RealtimeEvent(
+ type="audio_delta", audio=AudioChunk(pcm=a2, sample_rate=24000, timestamp_ns=0)
+ ),
RealtimeEvent(
type="output_transcript_delta",
text="Traceback (most recent call last):\n File x\nValueError: y\n\n",