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(overlay): pin repo root on sys.path so the bar and Conductor survive a restart

Ruben Lütke3ad3e4baf821
diff --git a/jarvis/core/config.py b/jarvis/core/config.py
index 4935c27249..97f955c96e 100644
--- a/jarvis/core/config.py
+++ b/jarvis/core/config.py
@@ -2143,6 +2143,16 @@ def ensure_project_root_cwd() -> Path:
— re-showing the first-run setup guide on every restart and splitting the
user's Chats/Sessions/Missions across two folders.
+ It also pins the repo root onto ``sys.path``. ``python -m`` seeds
+ ``sys.path[0]`` from the *start-time* cwd, and a later ``os.chdir`` does NOT
+ patch the import path. A start from a foreign cwd (manual launch / an in-app
+ restart inheriting the user home) therefore left the repo root off
+ ``sys.path``, so the ROOT packages ``ui`` and ``conductor`` — which live
+ outside the editable-installed ``jarvis`` package — failed to import
+ ("No module named 'ui'"), silently disabling the on-screen overlay
+ (whisper-bar) and the Conductor view. Putting the root on the path makes
+ those imports resolve regardless of how the process was started.
+
Call this once, as early as possible in every process entry point (before
``load_config`` and before the server touches any ``data/`` path). It is
idempotent and never raises: a chdir failure is logged and the process
@@ -2150,6 +2160,11 @@ def ensure_project_root_cwd() -> Path:
"""
import logging
+ root = str(PROJECT_ROOT)
+ if root not in sys.path:
+ # First, mirroring the `python -m` cwd seeding the working boots had.
+ sys.path.insert(0, root)
+
if Path.cwd() != PROJECT_ROOT:
try:
os.chdir(PROJECT_ROOT)
diff --git a/tests/unit/core/test_ensure_project_root_cwd.py b/tests/unit/core/test_ensure_project_root_cwd.py
index b4c50e475a..75b4473c82 100644
--- a/tests/unit/core/test_ensure_project_root_cwd.py
+++ b/tests/unit/core/test_ensure_project_root_cwd.py
@@ -10,6 +10,7 @@ re-appeared on every restart and Chats/Sessions/Missions split across two
folders. ``ensure_project_root_cwd`` pins the CWD to the repo root so every
CWD-relative path is deterministic.
"""
+import sys
from pathlib import Path
from jarvis.core import config
@@ -32,3 +33,35 @@ def test_ensure_project_root_cwd_idempotent_when_already_at_root(monkeypatch):
assert Path.cwd() == config.PROJECT_ROOT
assert result == config.PROJECT_ROOT
+
+
+def test_ensure_project_root_cwd_adds_root_to_sys_path(monkeypatch, tmp_path):
+ """The repo root must land in ``sys.path``, not just the CWD.
+
+ Root packages ``ui`` and ``conductor`` live OUTSIDE the editable-installed
+ ``jarvis`` package, so they import only when the repo root is on
+ ``sys.path``. ``python -m`` seeds ``sys.path[0]`` from the *start-time* CWD;
+ a later ``os.chdir`` does NOT fix it. A manual start / restart-app inheriting
+ the user home therefore left ``ui`` unimportable, and the on-screen overlay
+ (whisper-bar) silently failed to start ("No module named 'ui'"). Pinning the
+ CWD is not enough — the root must be put on the import path too.
+ """
+ root = str(config.PROJECT_ROOT)
+ monkeypatch.setattr(sys, "path", [p for p in sys.path if p != root])
+ monkeypatch.chdir(tmp_path)
+ assert root not in sys.path # precondition: started from a foreign sys.path
+
+ config.ensure_project_root_cwd()
+
+ assert root in sys.path
+
+
+def test_ensure_project_root_cwd_sys_path_idempotent(monkeypatch):
+ """A second call must not duplicate the repo root on ``sys.path``."""
+ root = str(config.PROJECT_ROOT)
+ monkeypatch.setattr(sys, "path", [p for p in sys.path if p != root])
+
+ config.ensure_project_root_cwd()
+ config.ensure_project_root_cwd()
+
+ assert sys.path.count(root) == 1