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.

feat(realtime): prestart the managed local server the moment the app boots

rubenluetke10-beepb51853d23ac7
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.py
index 371d3582be..1091d56e07 100644
--- a/jarvis/plugins/realtime/openai_realtime.py
+++ b/jarvis/plugins/realtime/openai_realtime.py
@@ -1578,6 +1578,16 @@ class LocalRealtimeProvider:
# and quietly routing a call into one the user did not pick is the opposite
# of what a local card is for.
implicit_usage_fallback_allowed = False
+ # Eagerly warmed even when configured as a FALLBACK. This card is a local
+ # process: warming costs no account round-trip and no metered tokens,
+ # while its cold start is the longest of any transport (45-90 s of model
+ # loading). Live 2026-08-10: with a subscription primary whose token had
+ # expired, the un-warmed local fallback was still stone cold when the
+ # first call arrived — the call died with "try again in about a minute"
+ # on a machine that could have answered it. The GPU-oversubscription
+ # caveat behind opt-in fallback warming targets stacking MULTIPLE native
+ # model stacks; this is the single local stack the user explicitly chose.
+ eager_warm_as_fallback = True
# Small self-hosted brains prefill the whole instruction block EVERY turn;
# the full ~24k-char profile cost 7.8 s of LLM time per answer against
# qwen2.5:7b (live 2026-08-07). The session builder honors this capability
@@ -1962,6 +1972,56 @@ class LocalRealtimeProvider:
log.info("local-realtime: revive skipped (%s)", outcome)
return False
+ @classmethod
+ async def prespawn_transport(cls, cfg: Any) -> bool:
+ """Spawn-only prestart, safe to fire the moment the app boots.
+
+ The managed local server pays the longest cold start of any transport
+ (measured 52-90 s of model loading, see the connect window above), and
+ it loads in its OWN process — so every second the warm worker spends
+ behind its voice gate is a second the local voice cannot answer for no
+ reason. This capability only STARTS the server and arms the crash
+ monitor; readiness, the smoke-marker repair, and brain residency stay
+ with :meth:`warm_transport`, which runs behind the gates exactly as
+ before. Discovered by name (AP-21); best-effort by contract — no
+ failure here may reach the caller.
+ """
+ try:
+ provider = cls.from_runtime_config(cfg)
+ if (
+ not provider._base_url
+ or not provider._launch_command
+ or not provider._server_is_local_process()
+ ):
+ return False
+ if _launch_command_target_state(provider._launch_command) == "missing":
+ # The regular warm logs the actionable "reinstall or clear it"
+ # message moments later; a second copy here would be noise.
+ return False
+ import importlib # lazy (AP-26)
+
+ def _spawn_only() -> bool:
+ supervisor = importlib.import_module("jarvis.realtime.local_server.supervisor")
+ outcome = str(
+ supervisor.ensure_running(
+ launch_command=provider._launch_command,
+ base_url=provider._base_url,
+ reason="boot-prespawn",
+ )
+ )
+ if outcome not in ("spawned", "already-running"):
+ return False
+ supervisor.start_runtime_monitor(
+ launch_command=provider._launch_command,
+ base_url=provider._base_url,
+ )
+ return True
+
+ return bool(await asyncio.to_thread(_spawn_only))
+ except Exception: # noqa: BLE001 — prespawning is best-effort by contract
+ log.debug("local-realtime: prespawn_transport failed", exc_info=True)
+ return False
+
@classmethod
async def warm_transport(cls, cfg: Any) -> bool:
"""Boot-time prewarm (called by the shared realtime warm worker).
diff --git a/jarvis/realtime/factory.py b/jarvis/realtime/factory.py
index a1347067bb..9e8a0f3bb7 100644
--- a/jarvis/realtime/factory.py
+++ b/jarvis/realtime/factory.py
@@ -305,6 +305,44 @@ async def realtime_warm_selected_transports(cfg: Any) -> None:
)
+async def realtime_prespawn_transports(cfg: Any) -> None:
+ """Fire the spawn-only prestart for every explicitly selected provider.
+
+ Runs BEFORE the warm worker's gates on purpose: the transport that
+ declares this capability today is the managed local server, whose models
+ load 45-90 s in a SEPARATE process — the earlier that spawn fires, the
+ earlier the first call can connect, and nothing on the boot path ever
+ waits for it. Unlike eager warming, position does not matter here: a
+ prespawn is bounded to starting a process, so an explicitly configured
+ FALLBACK is prestarted too — that fallback sitting stone cold is exactly
+ what stranded the first call of 2026-08-10, when the subscription primary
+ was down and the local fallback had never been started. A capability
+ probe, never a provider-id check (AP-21); an installed-but-unselected
+ plugin must never spawn a process on its own. Best-effort by contract —
+ one broken plugin never stops the others and no failure reaches the
+ caller.
+
+ Gated on the same voice-mode switch as warming: prestarting a server for
+ a feature this install runs through the classic pipeline is pure cost.
+ """
+ if not _realtime_is_the_configured_voice_mode(cfg):
+ log.debug(
+ "Realtime transport prespawn skipped: realtime is not the "
+ "configured voice mode."
+ )
+ return
+ for provider_id in _explicit_provider_ids(cfg):
+ try:
+ provider_cls = load(_GROUP, provider_id, protocol=RealtimeProvider)
+ prespawn = getattr(provider_cls, "prespawn_transport", None)
+ if callable(prespawn):
+ await prespawn(cfg)
+ except Exception as exc: # noqa: BLE001 - one broken plugin is skipped
+ log.warning(
+ "Realtime transport prespawn failed for %s: %s", provider_id, exc
+ )
+
+
#: The ChatGPT plan is its own quota pool, not metered platform usage. It is a
#: DISTINCT family from ``openai``: a 429 on one says nothing about the other.
_CHATGPT_SUBSCRIPTION_FAMILY = "openai-chatgpt-subscription"
@@ -455,5 +493,6 @@ __all__ = [
"realtime_available_provider",
"realtime_handshake_budget_s",
"realtime_implicit_usage_fallback_allowed",
+ "realtime_prespawn_transports",
"realtime_requires_webrtc_offer",
]
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.py
index c9122d9595..3a008fc42d 100644
--- a/jarvis/ui/desktop_app.py
+++ b/jarvis/ui/desktop_app.py
@@ -3154,6 +3154,29 @@ class DesktopApp:
"lifecycle; it will warm once and not re-arm after calls."
)
+ # Spawn-only prestart BEFORE the gates below. The managed local
+ # server's models load 45-90 s in a SEPARATE process, so parking its
+ # spawn behind the voice gate (+ delay) pushed local-voice readiness
+ # past the two-minute mark on every boot for nothing — the gate
+ # exists to keep the ChatGPT app-server spawn and account round trip
+ # out of the boot's CPU/disk window, and a prespawn is neither. The
+ # full warm (readiness, brain residency) stays behind the gates
+ # exactly as before, and AP-26 holds: nothing on the boot path awaits
+ # this worker.
+ try:
+ from jarvis.core.config import load_config
+ from jarvis.realtime.factory import realtime_prespawn_transports
+
+ prespawn_cfg = await asyncio.to_thread(load_config)
+ await realtime_prespawn_transports(prespawn_cfg)
+ except asyncio.CancelledError:
+ raise
+ except Exception: # noqa: BLE001 — prespawning is advisory, never fatal
+ _warm_log_exc.warning(
+ "Realtime transport prespawn failed; the local server starts "
+ "with the regular transport warm instead."
+ )
+
try:
await asyncio.wait_for(
voice_usable.wait(), timeout=_REALTIME_WARM_VOICE_GATE_S
diff --git a/jarvis/ui/web/server.py b/jarvis/ui/web/server.py
index 4660249aba..712b6fd7b9 100644
--- a/jarvis/ui/web/server.py
+++ b/jarvis/ui/web/server.py
@@ -2220,6 +2220,23 @@ class WebServer:
nothing except that the first call pays the cold start it pays today,
and it says so at warning level.
"""
+ try:
+ # Spawn-only prestart BEFORE the boot delay: the managed local
+ # server loads its models for 45-90 s in a SEPARATE process, so
+ # firing its spawn first costs the boot nothing and moves local
+ # voice readiness forward by the whole delay. The full warm below
+ # keeps its delay — it is what spawns app-servers and verifies
+ # accounts inside THIS process.
+ from jarvis.realtime.factory import realtime_prespawn_transports
+
+ await realtime_prespawn_transports(self.cfg)
+ except asyncio.CancelledError:
+ raise
+ except Exception as exc: # noqa: BLE001 -- prespawn is advisory, never fatal
+ logger.opt(exception=exc).debug(
+ "Realtime transport prespawn failed — the regular warm below "
+ "still covers the start."
+ )
try:
await asyncio.sleep(REALTIME_WARM_BOOT_DELAY_S)
from jarvis.realtime.factory import realtime_warm_selected_transports
diff --git a/tests/unit/realtime/test_factory.py b/tests/unit/realtime/test_factory.py
index 513e5bb5b0..ea603039de 100644
--- a/tests/unit/realtime/test_factory.py
+++ b/tests/unit/realtime/test_factory.py
@@ -369,6 +369,76 @@ async def test_warm_selected_transports_does_not_prewarm_a_heavy_fallback(
assert fallback.calls == 0
+class _PrespawnProbe:
+ """Minimal realtime provider exposing the spawn-only prestart."""
+
+ supports_realtime = True
+
+ def __init__(self) -> None:
+ self.calls = 0
+
+ async def prespawn_transport(self, cfg) -> bool: # noqa: ANN001 - probe shape
+ del cfg
+ self.calls += 1
+ return True
+
+
+async def test_prespawn_reaches_every_explicit_slot(monkeypatch) -> None:
+ """Unlike eager warming, the prestart is position-blind: a stone-cold
+ explicitly configured FALLBACK is what stranded the 2026-08-10 first call
+ when the primary was down. Providers without the capability are skipped
+ (AP-21), and one broken plugin never stops the others."""
+ primary = _PrespawnProbe()
+ fallback = _PrespawnProbe()
+ loaded = {"primary": primary, "plain": _NoWarmProbe(), "fallback": fallback}
+
+ def _load(_group, pid, protocol=None): # noqa: ANN001 - probe shape
+ if pid == "broken":
+ raise RuntimeError("plugin exploded")
+ return loaded[pid]
+
+ monkeypatch.setattr(
+ factory,
+ "_explicit_provider_ids",
+ lambda _cfg: ["primary", "plain", "broken", "fallback"],
+ )
+ monkeypatch.setattr(factory, "load", _load)
+
+ await factory.realtime_prespawn_transports(_cfg())
+
+ assert primary.calls == 1
+ assert fallback.calls == 1
+
+
+async def test_prespawn_skips_a_pipeline_mode_install(monkeypatch) -> None:
+ """A stale realtime pin must not spawn a server for a disabled feature."""
+ probe = _PrespawnProbe()
+ monkeypatch.setattr(factory, "_explicit_provider_ids", lambda _cfg: ["probe"])
+ monkeypatch.setattr(
+ factory, "load", lambda _group, _pid, protocol=None: probe
+ )
+
+ await factory.realtime_prespawn_transports(_cfg(mode="pipeline"))
+
+ assert probe.calls == 0
+
+
+async def test_prespawn_ignores_unselected_plugins(monkeypatch) -> None:
+ """An installed but unselected plugin must never spawn a process."""
+ probe = _PrespawnProbe()
+ monkeypatch.setattr(factory, "_explicit_provider_ids", lambda _cfg: [])
+ monkeypatch.setattr(
+ factory, "load", lambda _group, _pid, protocol=None: probe
+ )
+
+ await factory.realtime_prespawn_transports(_cfg())
+
+ assert probe.calls == 0
+
+
@pytest.mark.asyncio
async def test_warm_selected_transports_survives_one_broken_provider(
monkeypatch,
diff --git a/tests/unit/realtime/test_local_realtime.py b/tests/unit/realtime/test_local_realtime.py
index f33573b017..d1620ef097 100644
--- a/tests/unit/realtime/test_local_realtime.py
+++ b/tests/unit/realtime/test_local_realtime.py
@@ -1071,3 +1071,103 @@ async def test_warm_transport_requires_an_address_and_a_command() -> None:
async def test_warm_transport_never_raises(monkeypatch) -> None:
"""Best-effort by contract: no failure may reach the warm worker."""
assert await LocalRealtimeProvider.warm_transport(None) is False
+
+
+# ── Boot-time prespawn (prespawn_transport capability) ───────────────────
+def test_local_realtime_is_eagerly_warmed_as_a_fallback() -> None:
+ """Live 2026-08-10: with an expired subscription primary, the un-warmed
+ local FALLBACK was still stone cold when the first call arrived — the
+ call died on a machine that could have answered it. A local stack costs
+ no account round-trip to warm, so it must not sit out fallback warming."""
+ assert LocalRealtimeProvider.eager_warm_as_fallback is True
+
+
+async def test_prespawn_spawns_and_arms_the_monitor_without_waiting(
+ monkeypatch, tmp_path
+) -> None:
+ """The boot-time prestart only spawns: readiness and brain residency stay
+ with warm_transport, so the prespawn can run before the warm worker's
+ gates without ever blocking a boot."""
+ from jarvis.realtime.local_server import supervisor
+
+ calls: list[str] = []
+ monkeypatch.setattr(
+ supervisor,
+ "ensure_running",
+ lambda **kwargs: calls.append(f"run:{kwargs['reason']}") or "spawned",
+ )
+ monkeypatch.setattr(
+ supervisor,
+ "start_runtime_monitor",
+ lambda **kwargs: calls.append("monitor") or True,
+ )
+
+ def forbidden(*args: Any, **kwargs: Any) -> bool:
+ raise AssertionError("prespawn must never block on readiness or the brain")
+
+ monkeypatch.setattr(supervisor, "wait_until_ready", forbidden)
+ monkeypatch.setattr(supervisor, "warm_brain", forbidden)
+ exe = tmp_path / "server"
+ exe.write_bytes(b"")
+ cfg = _warm_cfg("http://localhost:8765", f'"{exe}" --model_name m')
+ assert await LocalRealtimeProvider.prespawn_transport(cfg) is True
+ assert calls == ["run:boot-prespawn", "monitor"]
+
+
+async def test_prespawn_does_not_arm_the_monitor_on_a_refused_spawn(
+ monkeypatch, tmp_path
+) -> None:
+ from jarvis.realtime.local_server import supervisor
+
+ calls: list[str] = []
+ monkeypatch.setattr(
+ supervisor, "ensure_running", lambda **kwargs: "refused:rate-limited"
+ )
+ monkeypatch.setattr(
+ supervisor,
+ "start_runtime_monitor",
+ lambda **kwargs: calls.append("monitor") or True,
+ )
+ exe = tmp_path / "server"
+ exe.write_bytes(b"")
+ cfg = _warm_cfg("http://localhost:8765", f'"{exe}" --model_name m')
+ assert await LocalRealtimeProvider.prespawn_transport(cfg) is False
+ assert calls == []
+
+
+async def test_prespawn_requires_an_address_and_a_local_command(
+ monkeypatch, tmp_path
+) -> None:
+ from jarvis.realtime.local_server import supervisor
+
+ def forbidden(**kwargs: Any) -> str:
+ raise AssertionError("nothing may spawn without a local endpoint")
+
+ monkeypatch.setattr(supervisor, "ensure_running", forbidden)
+ assert await LocalRealtimeProvider.prespawn_transport(_warm_cfg("", "serve")) is False
+ assert (
+ await LocalRealtimeProvider.prespawn_transport(
+ _warm_cfg("http://localhost:8765", "")
+ )
+ is False
+ )
+ # A LAN endpoint is never spawned here — wrong host.
+ assert (
+ await LocalRealtimeProvider.prespawn_transport(
+ _warm_cfg("http://gpu.lan:8443", "serve")
+ )
+ is False
+ )
+ # A deleted managed install must not burn the spawn rate limit at boot.
+ gone = tmp_path / "venv" / "Scripts" / "speech-to-speech.exe"
+ assert (
+ await LocalRealtimeProvider.prespawn_transport(
+ _warm_cfg("http://localhost:8765", f'"{gone}" --model_name m')
+ )
+ is False
+ )
+
+
+async def test_prespawn_never_raises() -> None:
+ """Best-effort by contract: no failure may reach the boot worker."""
+ assert await LocalRealtimeProvider.prespawn_transport(None) is False
diff --git a/tests/unit/ui/test_desktop_realtime_transport_warm.py b/tests/unit/ui/test_desktop_realtime_transport_warm.py
index d4bc2d38bf..c934d1db20 100644
--- a/tests/unit/ui/test_desktop_realtime_transport_warm.py
+++ b/tests/unit/ui/test_desktop_realtime_transport_warm.py
@@ -73,6 +73,15 @@ def recorder(monkeypatch):
return rec
+def prespawn_recorder(monkeypatch):
+ import jarvis.realtime.factory as factory_mod
+
+ rec = _WarmRecorder()
+ monkeypatch.setattr(factory_mod, "realtime_prespawn_transports", rec)
+ return rec
+
+
async def _start_worker(bus: _FakeBus) -> asyncio.Task[None]:
# The worker never touches ``self``; a bare instance keeps the test free of
# the desktop app's window/tray construction.
@@ -111,6 +120,31 @@ async def test_worker_waits_for_voice_usable_before_warming(fast_warm, recorder)
await _stop(task)
+async def test_prespawn_fires_before_the_voice_gate(
+ monkeypatch, recorder, prespawn_recorder
+):
+ """The managed local server loads its models for 45-90 s in its OWN
+ process, so its spawn must not sit behind the voice gate. Live
+ 2026-08-10: the pipeline never reported usable, the warm sat out the
+ full 45 s gate on every boot, and the server was first started by the
+ first call — which it then rejected with "try again in about a minute".
+ The full warm stays gated (AP-26); only the spawn-only prestart moves.
+ """
+ monkeypatch.setattr(da, "_REALTIME_WARM_DELAY_S", 0.0)
+ # A gate long enough that a leaked early WARM would be caught below.
+ monkeypatch.setattr(da, "_REALTIME_WARM_VOICE_GATE_S", 5.0)
+ monkeypatch.setattr(da, "_REALTIME_WARM_MIN_INTERVAL_S", 0.0)
+
+ bus = _FakeBus()
+ task = await _start_worker(bus)
+ try:
+ await asyncio.wait_for(prespawn_recorder.seen.wait(), timeout=2.0)
+ assert prespawn_recorder.calls == 1
+ assert recorder.calls == 0 # the full warm still waits on the gate
+ finally:
+ await _stop(task)
+
+
async def test_warm_happens_anyway_when_voice_never_becomes_usable(
fast_warm, recorder
):
diff --git a/tests/unit/ui/web/test_realtime_transport_warm_boot_hook.py b/tests/unit/ui/web/test_realtime_transport_warm_boot_hook.py
index 2dab5592e7..794578efbe 100644
--- a/tests/unit/ui/web/test_realtime_transport_warm_boot_hook.py
+++ b/tests/unit/ui/web/test_realtime_transport_warm_boot_hook.py
@@ -68,6 +68,41 @@ async def test_boot_hook_schedules_the_warm_with_the_server_config(
assert calls == [cfg]
+async def test_the_prespawn_runs_before_the_boot_delay(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """The managed local server loads its models for 45-90 s in its OWN
+ process; the spawn-only prestart must not sit behind the warm's boot
+ delay — every second of that delay was a second the local voice could
+ not answer, for nothing."""
+ monkeypatch.setattr(web_server, "REALTIME_WARM_BOOT_DELAY_S", 30.0)
+ warm_calls: list[Any] = []
+ _record_warm(monkeypatch, warm_calls)
+ prespawned = asyncio.Event()
+ prespawn_calls: list[Any] = []
+
+ async def _fake_prespawn(cfg: Any) -> None:
+ prespawn_calls.append(cfg)
+ prespawned.set()
+
+ monkeypatch.setattr(
+ realtime_factory, "realtime_prespawn_transports", _fake_prespawn
+ )
+ cfg = object()
+ srv = _StubServer(cfg)
+ srv._schedule_realtime_transport_warm()
+ task = srv._realtime_warm_task
+ assert task is not None
+ try:
+ await asyncio.wait_for(prespawned.wait(), timeout=2.0)
+ assert prespawn_calls == [cfg]
+ assert warm_calls == [] # the full warm still waits out the delay
+ finally:
+ task.cancel()
+ with pytest.raises(asyncio.CancelledError):
+ await task
+
+
async def test_repeated_scheduling_warms_exactly_once(
monkeypatch: pytest.MonkeyPatch,
) -> None: