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(missions): worktree boot sweep degrades cleanly on a host with no git

Ruben Lütke5e6b66c31d52
diff --git a/jarvis/missions/isolation/worktree.py b/jarvis/missions/isolation/worktree.py
index 7831961d87..ebb44950fb 100644
--- a/jarvis/missions/isolation/worktree.py
+++ b/jarvis/missions/isolation/worktree.py
@@ -473,10 +473,26 @@ class WorktreeManager:
than a boot that crashes on housekeeping.
"""
report = {"pruned": 0, "swept_run_dirs": 0, "errors": 0}
+ # A worktree can only be CREATED via git, so on a host with no git on
+ # PATH none can exist and there is nothing to sweep. Skip cleanly with
+ # one honest log line instead of letting ``git worktree prune`` raise
+ # FileNotFoundError and dump a traceback at every headless boot (observed
+ # live on a bare python:3.11-slim container, 2026-07-08). Missions that
+ # genuinely need worktree isolation still fail with an actionable message
+ # at create-time; this is the best-effort boot-time housekeeping path.
+ if shutil.which("git") is None:
+ logger.info(
+ "WorktreeManager.prune_and_sweep_leaked: git not on PATH — "
+ "worktree sweep skipped (no git means no worktrees can exist here)."
+ )
+ report["skipped_no_git"] = 1
+ return report
try:
self.prune_orphans()
report["pruned"] = 1
- except subprocess.CalledProcessError as exc:
+ # OSError (incl. FileNotFoundError if git vanishes mid-run) as well as a
+ # non-zero git exit must never escape this best-effort housekeeping path.
+ except (subprocess.CalledProcessError, OSError) as exc:
logger.warning("prune_and_sweep_leaked: prune failed: %s", exc)
report["errors"] += 1
diff --git a/tests/missions/test_worktree_no_git.py b/tests/missions/test_worktree_no_git.py
new file mode 100644
index 0000000000..80e1d0e6dc
--- /dev/null
+++ b/tests/missions/test_worktree_no_git.py
@@ -0,0 +1,36 @@
+"""The boot-time worktree sweep must degrade cleanly on a host with NO git.
+
+Observed live on a bare python:3.11-slim container (2026-07-08): the mission
+bootstrap sweep called ``git worktree prune``; with no ``git`` on PATH that
+raised ``FileNotFoundError``, which escaped ``prune_and_sweep_leaked`` (it only
+caught ``CalledProcessError``) and dumped a full traceback at EVERY headless
+boot. A worktree can only be CREATED via git, so on a git-less host none can
+exist and there is nothing to sweep — the sweep must skip cleanly, never invoke
+git, never raise, and never log a traceback.
+"""
+from __future__ import annotations
+
+from jarvis.missions.isolation import worktree as wt
+from jarvis.missions.isolation.worktree import WorktreeManager
+
+
+def test_sweep_skips_cleanly_when_git_is_absent(tmp_path, monkeypatch) -> None:
+ # Simulate a host with no git binary on PATH.
+ monkeypatch.setattr(wt.shutil, "which", lambda name: None)
+
+ mgr = WorktreeManager(repo_root=tmp_path, outputs_root=tmp_path / "outputs")
+
+ called = {"git": False}
+
+ def _boom(cmd: list[str]):
+ called["git"] = True
+ raise FileNotFoundError(2, "No such file or directory", "git")
+
+ monkeypatch.setattr(mgr, "_run_git", _boom)
+
+ # Must NOT raise (today it propagates FileNotFoundError).
+ report = mgr.prune_and_sweep_leaked(max_age_hours=6.0)
+
+ assert called["git"] is False, "sweep must not invoke git when git is absent from PATH"
+ assert report["errors"] == 0
+ assert report.get("skipped_no_git") == 1