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): honest SETUP_FAILED when git is missing + UTF-8 git output decoding

Ruben Lütke9bb57c2b30c9
diff --git a/jarvis/missions/isolation/worktree.py b/jarvis/missions/isolation/worktree.py
index a49f59f54b..7831961d87 100644
--- a/jarvis/missions/isolation/worktree.py
+++ b/jarvis/missions/isolation/worktree.py
@@ -668,6 +668,13 @@ class WorktreeManager:
On ``CalledProcessError`` the stderr/stdout from git are logged
before re-raising so the underlying reason (path-length, lock,
existing branch, …) is visible in ``data/jarvis_desktop.log``.
+
+ Raises ``FileNotFoundError``/``OSError`` unmodified when the ``git``
+ executable itself is missing from PATH — the caller (currently
+ ``WorktreeManager.create()`` -> the orchestrator's task loop) is
+ responsible for turning that into an honest, actionable failure
+ (AP-23 wave-2 finding 1); this helper only shapes and logs the
+ command, it never swallows an exception.
"""
if cmd and cmd[0] == "git":
patched = ["git", "-c", "core.longpaths=true", *cmd[1:]]
@@ -680,6 +687,8 @@ class WorktreeManager:
check=True,
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
creationflags=NO_WINDOW_CREATIONFLAGS,
)
except subprocess.CalledProcessError as exc:
diff --git a/jarvis/missions/kontrollierer/orchestrator.py b/jarvis/missions/kontrollierer/orchestrator.py
index 89e3118b37..2ca5ac9f10 100644
--- a/jarvis/missions/kontrollierer/orchestrator.py
+++ b/jarvis/missions/kontrollierer/orchestrator.py
@@ -245,6 +245,38 @@ def _classify_worker_error(err: str, *, timed_out: bool = False) -> str | None:
return "provider_unreachable"
return None
+
+def _classify_worktree_setup_failure(exc: BaseException) -> str:
+ """Map a ``WorktreeManager.create()`` failure to an actionable reason code.
+
+ AP-23 wave-2 audit finding 1: a fresh, ZIP-downloaded, or PATH-broken
+ install used to make ``create()`` raise a raw ``FileNotFoundError`` (git
+ binary missing) that escaped the task loop entirely — every mission,
+ even a pure in-process API-worker task, crashed with no user-visible
+ reason because every task is wrapped in a worktree first. Distinguishes:
+
+ - ``git_missing``: no git executable on PATH at all
+ (``FileNotFoundError``/``OSError`` from the subprocess spawn itself).
+ - ``git_not_a_repository``: git IS present but ``repo_root`` has no
+ ``.git`` (the "Download ZIP" install facet) — ``git worktree add``
+ exits 128 with a "not a git repository" stderr.
+ - ``worktree_setup_failed``: the pre-existing generic fallback for
+ everything else (200-char path-length cap ``ValueError``, an
+ index-lock ``CalledProcessError``, etc.) — unchanged behaviour.
+
+ Pure + offline; never raises. Any exception type not explicitly handled
+ above falls through to the generic fallback so this is always safe to
+ call from an except clause.
+ """
+ if isinstance(exc, FileNotFoundError):
+ return "git_missing"
+ if isinstance(exc, subprocess.CalledProcessError):
+ stderr = exc.stderr if isinstance(exc.stderr, str) else ""
+ if exc.returncode == 128 and "not a git repository" in stderr.lower():
+ return "git_not_a_repository"
+ return "worktree_setup_failed"
+
+
# Mission-level wall-clock safety net. Bounds TOTAL execution time across all
# critic iterations + the critic subprocess + decomposition — the per-iteration
# worker cap does not. Measured AFTER the concurrency semaphore is acquired
@@ -681,6 +713,10 @@ class TaskOutcome:
# distinct outcome lets the failure-reason mapper surface
# `worktree_setup_failed` ("Could not create a workspace.") so the
# user hears an actionable cause instead of "The worker was aborted."
+ # AP-23 wave-2 finding 1 (2026-07-07): the same outcome now also covers
+ # a missing git binary and a ZIP/no-.git install — see
+ # `_classify_worktree_setup_failure` and `_setup_failure_reason`, which
+ # refine the surfaced reason to `git_missing` / `git_not_a_repository`.
SETUP_FAILED = "setup_failed"
# Live deep-dive 2026-06-07 (mission 019ea1da): a Computer-Use mission whose
# final iteration hit the 630s wall-clock cap returned the generic ERROR,
@@ -769,6 +805,15 @@ class Kontrollierer:
# Popped on BOTH terminal paths (fail + approve) so a retried-then-
# approved mission never leaks a stale context into a later run.
self._mission_failure_context: dict[str, dict[str, str | None]] = {}
+ # Per-mission classified worktree-setup-failure reason (AP-23 wave-2
+ # finding 1) — written by the except clause in
+ # `_run_task_with_critic_loop` when `WorktreeManager.create()` raises,
+ # consumed once (popped) by the `SETUP_FAILED` aggregation branch in
+ # `run_mission` so the terminal reason names the real cause
+ # ("git_missing" / "git_not_a_repository") instead of the generic
+ # "worktree_setup_failed" fallback. Last write wins, same convention
+ # as `_mission_failure_context`.
+ self._setup_failure_reason: dict[str, str] = {}
# Per-mission worker answers for read-only/informational tasks (empty
# diff + tool evidence). Surfaced as MissionApproved.summary_de so the
# voice readback speaks the actual answer instead of "Mission
@@ -1017,10 +1062,17 @@ class Kontrollierer:
mission_id, "critic_loop_exhausted", partial_artifacts=partial
)
elif TaskOutcome.SETUP_FAILED in task_outcomes:
- # Worktree-create failure (path cap / git index lock) — surface an
- # actionable cause instead of the generic "worker aborted" (#8).
+ # Worktree-create failure (path cap / git index lock / missing git
+ # binary / no .git repo) — surface an actionable cause instead of
+ # the generic "worker aborted" (#8). AP-23 wave-2 finding 1: the
+ # classified reason (git_missing / git_not_a_repository) set by
+ # `_run_task_with_critic_loop`'s except clause takes priority over
+ # the pre-existing generic fallback.
+ setup_reason = self.__dict__.get("_setup_failure_reason", {}).pop(
+ mission_id, "worktree_setup_failed"
+ )
await self._fail_mission(
- mission_id, "worktree_setup_failed", partial_artifacts=partial
+ mission_id, setup_reason, partial_artifacts=partial
)
elif TaskOutcome.TIMED_OUT in task_outcomes:
# Final-attempt wall-clock timeout — honest "timeout" reason instead
@@ -1077,8 +1129,19 @@ class Kontrollierer:
task_id=step.task_id,
needs_repo=step.needs_repo,
)
- except (subprocess.CalledProcessError, ValueError) as exc:
+ except (subprocess.CalledProcessError, ValueError, OSError) as exc:
+ # OSError added (AP-23 wave-2 finding 1): a missing git binary
+ # raises FileNotFoundError (an OSError subclass), which used
+ # to escape uncaught here and crash every mission — even a
+ # pure in-process API-worker task, since every task is
+ # wrapped in a worktree first. Classify the cause so the
+ # aggregation branch in ``run_mission`` can surface an
+ # actionable reason instead of the generic
+ # "worktree_setup_failed" for every facet.
logger.exception("Task %s: worktree-create failed: %s", step.task_id, exc)
+ self.__dict__.setdefault("_setup_failure_reason", {})[mission_id] = (
+ _classify_worktree_setup_failure(exc)
+ )
return TaskOutcome.SETUP_FAILED
# BUG-021 fix: materialise AGENTS.md contract into the worktree so
diff --git a/jarvis/missions/voice/readback.py b/jarvis/missions/voice/readback.py
index 7e6b248017..880a3a9a90 100644
--- a/jarvis/missions/voice/readback.py
+++ b/jarvis/missions/voice/readback.py
@@ -185,6 +185,11 @@ FAILURE_REASON_PHRASES: Final[dict[Lang, dict[str, str]]] = {
"empty_diff": "Es wurden keine Dateien geschrieben.", # i18n-allow
"critic_unavailable": "Der Prüfer ist abgestürzt, die Arbeit liegt im Worktree.", # i18n-allow
"worktree_setup_failed": "Ich konnte keinen Arbeitsbereich anlegen.", # i18n-allow
+ "git_missing": "Jarvis-Agents brauchen eine Git-Installation im PATH.", # i18n-allow
+ "git_not_a_repository": (
+ "Jarvis-Agents brauchen einen Git-Checkout, bitte über den " # i18n-allow
+ "Git-Installer installieren, nicht als ZIP." # i18n-allow
+ ),
},
"en": {
"critic_loop_exhausted": "Three attempts were not enough.",
@@ -200,6 +205,11 @@ FAILURE_REASON_PHRASES: Final[dict[Lang, dict[str, str]]] = {
"The reviewer crashed; the work is preserved in the worktree."
),
"worktree_setup_failed": "I could not create a workspace.",
+ "git_missing": "Jarvis-Agents require git to be installed and on PATH.",
+ "git_not_a_repository": (
+ "Jarvis-Agents require a git checkout (install via the "
+ "git-based installer, not a ZIP download)."
+ ),
},
}
diff --git a/tests/missions/kontrollierer/test_worktree_setup_failure.py b/tests/missions/kontrollierer/test_worktree_setup_failure.py
index 3eb0ebca2e..9cdd6f4568 100644
--- a/tests/missions/kontrollierer/test_worktree_setup_failure.py
+++ b/tests/missions/kontrollierer/test_worktree_setup_failure.py
@@ -43,6 +43,34 @@ class _GitLockWorktrees:
)
+class _GitMissingWorktrees:
+ """Simulates a fresh machine with no `git` binary on PATH."""
+
+ def create(
+ self, *, mission_slug: str, task_id: str, needs_repo: bool = True
+ ): # noqa: ANN201
+ raise FileNotFoundError(
+ 2, "The system cannot find the file specified", "git"
+ )
+
+
+class _NotAGitRepositoryWorktrees:
+ """Simulates the ZIP/'Download ZIP' install facet: git is present but
+ `repo_root` has no `.git`, so `git worktree add` exits 128."""
+
+ def create(
+ self, *, mission_slug: str, task_id: str, needs_repo: bool = True
+ ): # noqa: ANN201
+ raise subprocess.CalledProcessError(
+ 128,
+ ["git", "worktree", "add"],
+ stderr=(
+ "fatal: not a git repository (or any of the parent "
+ "directories): .git"
+ ),
+ )
+
+
@pytest.mark.asyncio
async def test_worktree_path_cap_failure_returns_setup_failed(
tmp_path: Path,
@@ -61,6 +89,8 @@ async def test_worktree_path_cap_failure_returns_setup_failed(
)
assert outcome == TaskOutcome.SETUP_FAILED
+ # Generic fallback reason — unrelated to git — must stay unchanged.
+ assert k._setup_failure_reason["m0"] == "worktree_setup_failed"
@pytest.mark.asyncio
@@ -81,3 +111,61 @@ async def test_worktree_git_lock_failure_returns_setup_failed(
)
assert outcome == TaskOutcome.SETUP_FAILED
+ # An index-lock CalledProcessError (exit 128, unrelated stderr) must
+ # NOT be misclassified as the "not a git repository" facet — only the
+ # generic fallback reason applies.
+ assert k._setup_failure_reason["m1"] == "worktree_setup_failed"
+
+
+# --- AP-23 wave-2 audit finding 1: honest git-specific facets ---------------
+
+
+async def test_worktree_missing_git_binary_yields_honest_setup_failed_reason(
+ tmp_path: Path,
+) -> None:
+ """A missing git binary must degrade to an honest SETUP_FAILED outcome
+ with an actionable reason — never a raw FileNotFoundError escaping the
+ task loop (which used to crash every mission, even pure in-process
+ API-worker tasks, since every task is wrapped in a worktree first)."""
+ k = object.__new__(Kontrollierer)
+ k._budget = _NoopBudget()
+ k._worktrees = _GitMissingWorktrees()
+
+ outcome = await k._run_task_with_critic_loop(
+ mission_id="m-git-missing",
+ mission_prompt="build a thing",
+ step=Step(slug="z", prompt="do z"),
+ mission_dir=tmp_path,
+ reflections=object(),
+ sem=asyncio.Semaphore(1),
+ )
+
+ assert outcome == TaskOutcome.SETUP_FAILED
+ assert k._setup_failure_reason["m-git-missing"] == "git_missing"
+
+
+async def test_worktree_not_a_git_repository_yields_zip_install_reason(
+ tmp_path: Path,
+) -> None:
+ """Facet of finding 1: a ZIP/'Download ZIP' install (no `.git`) makes
+ `git worktree add` exit 128 with a 'not a git repository' stderr. This
+ must be distinguished from the generic setup failure so the user hears
+ the actionable "install via git, not a ZIP" cause instead of the
+ unhelpful generic "I could not create a workspace."."""
+ k = object.__new__(Kontrollierer)
+ k._budget = _NoopBudget()
+ k._worktrees = _NotAGitRepositoryWorktrees()
+
+ outcome = await k._run_task_with_critic_loop(
+ mission_id="m-no-repo",
+ mission_prompt="build a thing",
+ step=Step(slug="w", prompt="do w"),
+ mission_dir=tmp_path,
+ reflections=object(),
+ sem=asyncio.Semaphore(1),
+ )
+
+ assert outcome == TaskOutcome.SETUP_FAILED
+ assert k._setup_failure_reason["m-no-repo"] == "git_not_a_repository"
diff --git a/tests/missions/test_voice_readback.py b/tests/missions/test_voice_readback.py
index 1e45773200..2313980060 100644
--- a/tests/missions/test_voice_readback.py
+++ b/tests/missions/test_voice_readback.py
@@ -96,6 +96,34 @@ def test_render_failed_maps_worktree_setup_failed() -> None:
assert "Arbeitsbereich" in out, f"expected actionable cause, got {out!r}"
+def test_render_failed_maps_git_missing_to_actionable_phrase() -> None:
+ """AP-23 wave-2 audit finding 1: a missing git binary must speak an
+ actionable cause, not the generic worktree_setup_failed phrase."""
+ rb = MissionReadback()
+ out_de = rb.render_failed(reason="git_missing", language="de")
+ assert "git_missing" not in out_de
+ assert "Git" in out_de, f"expected actionable git cause, got {out_de!r}"
+
+ out_en = rb.render_failed(reason="git_missing", language="en")
+ assert "git_missing" not in out_en
+ assert "git" in out_en.lower() and "path" in out_en.lower(), (
+ f"expected actionable git cause, got {out_en!r}"
+ )
+
+
+def test_render_failed_maps_git_not_a_repository_to_zip_install_phrase() -> None:
+ """Facet of finding 1: the ZIP/no-.git install must be distinguished
+ from a missing git binary with its own actionable phrase."""
+ rb = MissionReadback()
+ out_de = rb.render_failed(reason="git_not_a_repository", language="de")
+ assert "git_not_a_repository" not in out_de
+ assert "Git" in out_de, f"expected actionable git cause, got {out_de!r}"
+
+ out_en = rb.render_failed(reason="git_not_a_repository", language="en")
+ assert "git_not_a_repository" not in out_en
+ assert "zip" in out_en.lower(), f"expected the ZIP-install hint, got {out_en!r}"
+
+
def test_render_failed_maps_attempts_timed_out_to_honest_timeout_phrase() -> None:
"""Live deep-dive 2026-06-07 (mission 019ea1da): a Computer-Use mission
whose final iteration hit the 630s wall-clock cap was failed with the
diff --git a/tests/missions/test_worktree.py b/tests/missions/test_worktree.py
index 52141d03b1..57ce396439 100644
--- a/tests/missions/test_worktree.py
+++ b/tests/missions/test_worktree.py
@@ -311,6 +311,62 @@ def test_create_raises_when_path_too_long(tmp_git_repo: Path, tmp_path: Path) ->
mgr.create(mission_slug="m", task_id="01")
+# --- AP-23 wave-2 audit finding 1: missing git binary propagates honestly ----
+
+
+def test_create_propagates_filenotfounderror_when_git_missing(
+ manager: WorktreeManager, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """A missing git executable must not be swallowed at this layer.
+
+ `WorktreeManager.create()` is the choke point the orchestrator's task
+ loop wraps in a try/except (`_classify_worktree_setup_failure`) to turn
+ a missing git binary into an honest SETUP_FAILED reason. That only works
+ if `create()` itself lets `FileNotFoundError` propagate unmodified —
+ this guards against a future change accidentally catching and hiding it
+ here instead.
+ """
+ def fake_run_git(cmd: list[str]) -> subprocess.CompletedProcess[str]:
+ raise FileNotFoundError(2, "The system cannot find the file specified", "git")
+
+ monkeypatch.setattr(manager, "_run_git", fake_run_git)
+
+ with pytest.raises(FileNotFoundError):
+ manager.create(mission_slug="m", task_id="01-nogit")
+
+
+# --- AP-23 wave-2 audit finding 7: _run_git UTF-8 decoding parity ------------
+
+
+def test_run_git_uses_utf8_encoding_with_replace_errors(
+ manager: WorktreeManager, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """`_run_git` must decode subprocess output the same way its sibling
+ `_run_git_in` already does. Before this fix, `_run_git` omitted
+ `encoding="utf-8", errors="replace"` entirely (relying on the platform
+ default, cp1252 on Windows) — a non-cp1252 branch/file name in git's
+ stdout/stderr raised `UnicodeDecodeError` instead of being decoded (with
+ replacement chars in the worst case)."""
+ captured: dict[str, object] = {}
+
+ def fake_run(*args: object, **kwargs: object) -> subprocess.CompletedProcess[str]:
+ captured.update(kwargs)
+ return subprocess.CompletedProcess(args[0], 0, stdout="", stderr="")
+
+ monkeypatch.setattr(
+ "jarvis.missions.isolation.worktree.subprocess.run", fake_run
+ )
+
+ manager._run_git(["git", "status"])
+
+ assert captured.get("encoding") == "utf-8", (
+ f"expected encoding='utf-8', got kwargs={captured!r}"
+ )
+ assert captured.get("errors") == "replace", (
+ f"expected errors='replace', got kwargs={captured!r}"
+ )
+
+
# --- remove() ----------------------------------------------------------------