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(background): count only outside, switched-on channels as work

rubenluetke10-beep8ffd8dc079e3
diff --git a/jarvis/core/background_service.py b/jarvis/core/background_service.py
index d3bfc3fb10..32e2ef06fe 100644
--- a/jarvis/core/background_service.py
+++ b/jarvis/core/background_service.py
@@ -128,12 +128,35 @@ def work_from_state(state: Any) -> BackgroundWork:
started = getattr(manager, "started", None)
if callable(started):
try:
- channels = tuple(str(name) for name in started())
+ channels = tuple(
+ name
+ for name in (str(raw) for raw in started())
+ if _is_outside_channel(name, state)
+ )
except Exception: # noqa: BLE001 — same: unreadable means none to keep
logger.opt(exception=True).debug("background: channel state unreadable")
return BackgroundWork(routines=int(routines), running=int(running), channels=channels)
+#: Channels that only serve the app's own windows — nothing outside reaches them.
+_IN_APP_CHANNELS = frozenset({"web"})
+
+
+def _is_outside_channel(name: str, state: Any) -> bool:
+ """A channel someone outside the app can write to, and that is switched on.
+
+ ``ChannelManager.started()`` also lists the in-app ``web`` channel and a
+ channel whose ``[integrations.<name>] enabled`` is off (its ``start()``
+ returns early yet counts as started) — neither is work worth a background
+ process.
+ """
+ if name in _IN_APP_CHANNELS:
+ return False
+ cfg = getattr(state, "config", None) or getattr(state, "cfg", None)
+ section = getattr(getattr(cfg, "integrations", None), name, None)
+ return section is None or bool(getattr(section, "enabled", True))
+
+
def keep_running_enabled(cfg: Any) -> bool:
"""``[background] keep_agents_running`` (default on)."""
section = getattr(cfg, "background", None)
diff --git a/tests/unit/core/test_background_service.py b/tests/unit/core/test_background_service.py
index 341ce31e38..37a1b7f012 100644
--- a/tests/unit/core/test_background_service.py
+++ b/tests/unit/core/test_background_service.py
@@ -518,3 +518,18 @@ def test_tray_quit_all_skips_the_hand_off(monkeypatch) -> None:
item._action(None, item)
assert seen == ["quit_all", "stopped"]
assert isinstance(tray._command_queue.get_nowait(), TrayCommand)
+
+
+def test_in_app_and_switched_off_channels_are_not_work() -> None:
+ state = SimpleNamespace(
+ task_scheduler=_Scheduler(),
+ channel_manager=_Channels("discord", "telegram", "web"),
+ config=SimpleNamespace(
+ integrations=SimpleNamespace(
+ telegram=SimpleNamespace(enabled=True), discord=SimpleNamespace(enabled=False)
+ )
+ ),
+ )
+ assert bg.work_from_state(state).channels == ("telegram",)
+ state.config.integrations.telegram.enabled = False
+ assert not bg.work_from_state(state)