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(realtime): tolerate slow managed cold starts

rubenluetke10-beepc9cba06c04a1
diff --git a/jarvis/plugins/realtime/openai_realtime.py b/jarvis/plugins/realtime/openai_realtime.py
index 74f8aef546..f55461c01b 100644
--- a/jarvis/plugins/realtime/openai_realtime.py
+++ b/jarvis/plugins/realtime/openai_realtime.py
@@ -1835,7 +1835,7 @@ class LocalRealtimeProvider:
ready = bool(
supervisor.wait_until_ready(
provider._base_url,
- timeout=provider._connect_retry_window_s(),
+ timeout=supervisor.RUNTIME_READY_TIMEOUT_S,
launch_command=provider._launch_command,
cleanup_on_timeout=True,
)
diff --git a/jarvis/realtime/local_server/supervisor.py b/jarvis/realtime/local_server/supervisor.py
index 4c61f926c9..30e55108e0 100644
--- a/jarvis/realtime/local_server/supervisor.py
+++ b/jarvis/realtime/local_server/supervisor.py
@@ -49,9 +49,13 @@ log = logging.getLogger(__name__)
#: historical revive rate limit.
SPAWN_MIN_INTERVAL_S = 60.0
-# Installed checkpoints are already local after the mandatory smoke boot;
-# 120 seconds still covers the measured 90-second CUDA graph cold start.
-RUNTIME_READY_TIMEOUT_S = 120.0
+# Installed checkpoints are already local after the mandatory smoke boot, but
+# imports, CUDA graph capture, STT warm-up and the local brain can still take
+# more than two minutes on a contended 16 GB host. This five-minute ceiling is
+# for background supervision only; an interactive call keeps its shorter
+# provider-owned connection budget. It is deliberately bounded so a genuine
+# native hang is still reclaimed.
+RUNTIME_READY_TIMEOUT_S = 300.0
RUNTIME_READY_POLL_S = 0.5
OWNED_STARTUP_TIMEOUT_S = RUNTIME_READY_TIMEOUT_S
diff --git a/tests/unit/realtime/local_server/test_supervisor.py b/tests/unit/realtime/local_server/test_supervisor.py
index ba2daa4b34..a4f3ae8002 100644
--- a/tests/unit/realtime/local_server/test_supervisor.py
+++ b/tests/unit/realtime/local_server/test_supervisor.py
@@ -262,6 +262,52 @@ def test_an_alive_owned_process_is_not_double_spawned(monkeypatch, tmp_path) ->
assert outcome == "already-running"
+def test_slow_managed_cold_start_survives_beyond_interactive_budget(
+ monkeypatch, tmp_path
+) -> None:
+ """A healthy cold boot observed at 122 s must not be mistaken for a zombie."""
+ from jarvis.realtime.local_server import install
+
+ supervisor._reset_for_tests()
+ monkeypatch.setenv("JARVIS_DATA_DIR", str(tmp_path))
+ entrypoint = install.install_root() / "venv" / "server.exe"
+ command = f'"{entrypoint}" --mode realtime --ws_host 127.0.0.1'
+ (tmp_path / "local_realtime_server.pid.json").write_text(
+ json.dumps(
+ {
+ "pid": 4711,
+ "create_time": 1000.0,
+ "spawned_at": time.time() - 180.0,
+ "port": 8765,
+ "command": command,
+ "spawn_token": "slow-cold-start",
+ }
+ ),
+ encoding="utf-8",
+ )
+ monkeypatch.setattr(supervisor, "probe_runtime", lambda *args, **kwargs: None)
+ monkeypatch.setattr(supervisor, "_port_open", lambda *args, **kwargs: False)
+ monkeypatch.setattr(supervisor, "_process_create_time", lambda pid: 1000.0)
+
+ def forbidden_kill(pid: int) -> bool:
+ raise AssertionError(f"progressing cold-start pid {pid} must stay alive")
+
+ def forbidden_spawn(candidate: str, **kwargs: Any) -> int:
+ raise AssertionError(f"must not double-spawn while {candidate!r} is loading")
+
+ monkeypatch.setattr(supervisor, "_kill_pid_tree", forbidden_kill)
+ monkeypatch.setattr(supervisor, "_spawn", forbidden_spawn)
+
+ outcome = supervisor.ensure_running(
+ launch_command=command,
+ base_url="http://127.0.0.1:8765",
+ reason="test",
+ )
+
+ assert supervisor.OWNED_STARTUP_TIMEOUT_S >= 300.0
+ assert outcome == "already-running"
+
+
def test_an_owned_managed_zombie_is_replaced_after_startup_deadline(
monkeypatch, tmp_path
) -> None:
diff --git a/tests/unit/realtime/test_local_realtime.py b/tests/unit/realtime/test_local_realtime.py
index 1aace74bfc..d9a0d0f35f 100644
--- a/tests/unit/realtime/test_local_realtime.py
+++ b/tests/unit/realtime/test_local_realtime.py
@@ -651,17 +651,21 @@ async def test_warm_transport_prewarms_via_the_supervisor(
from jarvis.realtime.local_server import install, supervisor
calls: list[str] = []
+ readiness_timeouts: list[float] = []
monkeypatch.setattr(
supervisor,
"ensure_running",
lambda **kwargs: calls.append(f"run:{kwargs['reason']}") or "spawned",
)
monkeypatch.setattr(supervisor, "is_managed_launch_command", lambda command: True)
- monkeypatch.setattr(
- supervisor,
- "wait_until_ready",
- lambda *args, **kwargs: calls.append("ready") or True,
- )
+
+ def wait_until_ready(*args: Any, **kwargs: Any) -> bool:
+ del args
+ calls.append("ready")
+ readiness_timeouts.append(float(kwargs["timeout"]))
+ return True
+
+ monkeypatch.setattr(supervisor, "wait_until_ready", wait_until_ready)
monkeypatch.setattr(
supervisor, "warm_brain", lambda **kwargs: calls.append("warm") or True
)
@@ -680,6 +684,8 @@ async def test_warm_transport_prewarms_via_the_supervisor(
cfg = _warm_cfg("http://localhost:8765", f'"{exe}" --model_name m')
assert await LocalRealtimeProvider.warm_transport(cfg) is True
assert calls == ["run:prewarm", "ready", "marker", "monitor", "warm"]
+ assert readiness_timeouts == [supervisor.RUNTIME_READY_TIMEOUT_S]
+ assert readiness_timeouts[0] >= 300.0
async def test_warm_transport_never_warms_the_brain_before_speech_is_ready(