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(watchdog): say when a loop stall is the machine running out of memory

rubenluetke10-beep220ec926edab
diff --git a/jarvis/core/loop_watchdog.py b/jarvis/core/loop_watchdog.py
index 5588446eb5..b6da55fea0 100644
--- a/jarvis/core/loop_watchdog.py
+++ b/jarvis/core/loop_watchdog.py
@@ -173,14 +173,41 @@ class EventLoopWatchdog:
return "".join(traceback.format_stack(frame))
+def _memory_pressure_note() -> str:
+ """One sentence on system memory when it is nearly gone, else ``""``.
+
+ A process whose memory the OS has paged out stalls at whatever line touches
+ memory next. On 2026-09-30 three 15 s stalls landed in a log call, a
+ ``CreateProcess`` and an SSL context load while the machine had 1.5 GB of
+ 32 GB free and paged in ~4,000 pages a second; each stack read like the
+ culprit and none was. This line says when the stack is only where the
+ thread waited.
+ """
+ try:
+ import psutil
+
+ memory = psutil.virtual_memory()
+ except Exception: # noqa: BLE001 - no reading means no claim, not a failure
+ return ""
+ gib = 1024**3
+ if memory.available >= max(2 * gib, memory.total * 0.10):
+ return ""
+ return (
+ f" System memory is nearly exhausted ({memory.available / gib:.1f} GB of "
+ f"{memory.total / gib:.0f} GB free): the OS is likely paging this process, "
+ "so the stack may show where the loop waited, not what caused the stall."
+ )
+
+
def _log_stall(stalled_s: float, stack_text: str) -> None:
"""Default reporter: one warning naming the duration and the guilty stack."""
from loguru import logger
logger.warning(
"Event loop STALLED for {:.1f}s — every WebSocket, HTTP route and "
- "brain turn is blocked behind this call. Stack of the loop thread:\n{}",
+ "brain turn is blocked behind this call.{} Stack of the loop thread:\n{}",
stalled_s,
+ _memory_pressure_note(),
stack_text,
)
diff --git a/tests/unit/core/test_loop_watchdog.py b/tests/unit/core/test_loop_watchdog.py
index 3f3e0aaf13..072f383f91 100644
--- a/tests/unit/core/test_loop_watchdog.py
+++ b/tests/unit/core/test_loop_watchdog.py
@@ -180,3 +180,34 @@ def test_stack_is_reported_even_before_any_beat_landed(live_loop):
watchdog = EventLoopWatchdog(live_loop, interval_s=5.0, stall_s=5.0)
text = watchdog._loop_stack()
assert isinstance(text, str) and text
+
+def _fake_psutil(monkeypatch, *, available_gb: float, total_gb: float = 32.0) -> None:
+ import sys
+ from types import ModuleType, SimpleNamespace
+
+ fake = ModuleType("psutil")
+ fake.virtual_memory = lambda: SimpleNamespace( # type: ignore[attr-defined]
+ available=int(available_gb * 1024**3), total=int(total_gb * 1024**3)
+ )
+ monkeypatch.setitem(sys.modules, "psutil", fake)
+
+
+def test_a_stall_on_a_machine_out_of_memory_says_so(monkeypatch):
+ """2026-09-30: three stalls, three unrelated stacks, 1.5 GB of 32 GB free.
+ The report must point at the paging, not only at the random stack."""
+ from jarvis.core.loop_watchdog import _memory_pressure_note
+
+ _fake_psutil(monkeypatch, available_gb=1.5)
+
+ note = _memory_pressure_note()
+
+ assert "1.5 GB of 32 GB free" in note
+ assert "paging" in note
+
+
+def test_a_stall_with_memory_to_spare_blames_only_the_stack(monkeypatch):
+ from jarvis.core.loop_watchdog import _memory_pressure_note
+
+ _fake_psutil(monkeypatch, available_gb=12.0)
+
+ assert _memory_pressure_note() == ""