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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(missions): capture worker-committed deliverables so they are not lost
Ruben Lütke04ae7eaf36cb
diff --git a/jarvis/missions/isolation/worktree.py b/jarvis/missions/isolation/worktree.pyindex 48632a1958..a49f59f54b 100644--- a/jarvis/missions/isolation/worktree.py+++ b/jarvis/missions/isolation/worktree.py@@ -45,6 +45,40 @@ _MAX_WORKTREE_PATH_LEN = 200# Slug sanitizer: allows [a-z0-9-], everything else -> '-', leading/trailing trim._SLUG_RE = re.compile(r"[^a-z0-9]+")+# Sidecar file (in the TASK dir, one level ABOVE ``workspace/`` so it never+# pollutes the worktree diff) that records the worktree's BASE commit SHA — the+# HEAD it was forked from at creation time (the ``main`` checkout for a full+# worktree, the ``lean-workspace-init`` empty commit for a lean one). The+# Kontrollierer diffs against this base instead of the live HEAD so a worker+# that ``git commit``s its deliverable is still captured: after a commit,+# ``git diff --cached HEAD`` is empty and ``git ls-files --others`` no longer+# lists the file (it is now tracked), so the committed deliverable would+# otherwise be invisible to archiving and silently lost when the worktree is+# pruned. Live forensic 2026-07-03, mission 019f26d0-bb07: a worker built a+# complete ``schokolade-99.html``, then (as coding agents habitually do)+# ``git add`` + ``git commit``-ed it; the file fell out of the untracked-only+# capture and the user received only a materialised ``.md`` summary — the HTML+# was gone. Diffing against the base makes committed files reappear.+BASE_SHA_SIDECAR: str = ".mission_base_sha"+++def read_worktree_base_sha(workspace: Path) -> str | None:+ """Return the recorded base commit SHA for a worktree, or ``None``.++ Reads the :data:`BASE_SHA_SIDECAR` file written by+ :meth:`WorktreeManager._write_base_sha` at creation time. ``None`` when the+ sidecar is absent (a pre-fix / externally-created worktree) or unreadable —+ callers then fall back to their pre-existing ``HEAD``-relative behaviour, so+ this is purely additive and never breaks an older mission.+ """+ try:+ raw = (workspace.parent / BASE_SHA_SIDECAR).read_text(encoding="utf-8").strip()+ except OSError:+ return None+ # A commit SHA is 40 hex chars (or the short form). Guard against a truncated+ # / corrupt sidecar so we never hand git a bogus revision.+ return raw if re.fullmatch(r"[0-9a-fA-F]{7,40}", raw) else None+# Worktree RUN-dir name shape: ``<YYYYMMDDTHHMMSS>__<slug>__<8-hex>`` (see# ``create`` below). ONLY these transient scaffolding dirs are eligible for the# leaked-worktree sweep. The persistent ``mission_<id>`` archive dirs that@@ -207,6 +241,9 @@ class WorktreeManager:logger.info("WorktreeManager.create: %s", " ".join(cmd))self._run_git(cmd)+ # Record the base commit (the forked-from HEAD) so the Kontrollierer can+ # diff against it and capture files the worker later ``git commit``s.+ self._write_base_sha(workspace)return workspace# Identity used for the lean repo's initial commit. A fresh ``git init``@@ -252,8 +289,34 @@ class WorktreeManager:# repo's `.git/info/exclude` (which already ignores node_modules/) and# its `.git` is a FILE, so there is nothing local to write here.self._write_dependency_excludes(workspace)+ # Record the base commit (the lean repo's initial empty commit) so the+ # Kontrollierer can diff against it and capture files a worker commits.+ self._write_base_sha(workspace)return workspace+ def _write_base_sha(self, workspace: Path) -> None:+ """Persist the worktree's base commit SHA next to (not inside) the tree.++ Runs ``git rev-parse HEAD`` in the freshly-created ``workspace`` and+ writes the result to ``workspace.parent / BASE_SHA_SIDECAR`` — the task+ dir, which is OUTSIDE the worktree so the sidecar never appears in a+ ``git add -A`` / ``git diff`` capture. Best-effort: a failure only+ regresses to the pre-fix ``HEAD``-relative capture and must never block+ workspace creation.+ """+ try:+ r = self._run_git_in(["git", "rev-parse", "HEAD"], cwd=workspace)+ sha = (r.stdout or "").strip()+ if sha:+ (workspace.parent / BASE_SHA_SIDECAR).write_text(+ sha, encoding="utf-8"+ )+ except (subprocess.CalledProcessError, OSError) as exc:+ logger.warning(+ "could not record base SHA for %s: %s — committed deliverables "+ "may not be captured for this task", workspace, exc,+ )+def _write_dependency_excludes(self, workspace: Path) -> None:"""Append `_DEPENDENCY_EXCLUDE_DIRS` to the lean repo's``.git/info/exclude``.diff --git a/jarvis/missions/kontrollierer/orchestrator.py b/jarvis/missions/kontrollierer/orchestrator.pyindex dd3510df99..c80ac11b04 100644--- a/jarvis/missions/kontrollierer/orchestrator.py+++ b/jarvis/missions/kontrollierer/orchestrator.py@@ -57,7 +57,7 @@ from ..events import (WorkerSpawned,now_ms,)-from ..isolation.worktree import WorktreeManager+from ..isolation.worktree import WorktreeManager, read_worktree_base_shafrom ..worker_runtime.workspace import materialize_worker_contractfrom ..manager import MissionManagerfrom ..stream_evidence import (@@ -1860,10 +1860,20 @@ class Kontrollierer:prompt reads the diff as text, so comment-prefixed lines areinformational and don't require a parser change.+ Committed-deliverable capture (2026-07-03, mission 019f26d0-bb07): when+ the worktree records a BASE commit SHA (``read_worktree_base_sha``), we+ diff the index against that BASE rather than the live ``HEAD``. A worker+ that ``git commit``s its file advances ``HEAD`` past the deliverable, so+ ``git diff --cached HEAD`` renders EMPTY for it and the file is lost;+ diffing against the fork-point base surfaces committed AND uncommitted+ changes alike. Falls back to ``HEAD`` when no base was recorded (older /+ externally-created worktrees), so this is purely additive.+All git calls are best-effort with a 10s cap; failure returns ""and logs at WARNING so the upstream Critic still gets a(truthful) empty diff rather than a stale one."""+ diff_base = read_worktree_base_sha(worktree) or "HEAD"try:subprocess.run( # noqa: S603["git", "add", "-A", "."],@@ -1889,7 +1899,9 @@ class Kontrollierer:# worker-created file via this exact sequence.# `-c core.quotepath=false` keeps non-ASCII paths raw UTF-8# instead of octal-escaping them (HIGH finding 2026-05-27).- ["git", "-c", "core.quotepath=false", "diff", "--cached", "HEAD"],+ # `diff_base` is the worktree's fork-point (or HEAD when none was+ # recorded) so a worker's own commits are still captured.+ ["git", "-c", "core.quotepath=false", "diff", "--cached", diff_base],cwd=str(worktree),check=False,capture_output=True,@@ -2226,6 +2238,37 @@ class Kontrollierer:if rel and rel not in untracked:untracked.append(rel)+ # THIRD enumeration — files the worker COMMITTED (2026-07-03, mission+ # 019f26d0-bb07). A committed deliverable is tracked, so neither+ # `ls-files --others` above nor the staged `git diff HEAD` sees it,+ # and it is lost when the worktree is pruned. When a base commit was+ # recorded (`read_worktree_base_sha`), enumerate every file+ # added/copied/modified/renamed between the base and the current HEAD+ # and union them in — they exist on disk in the worktree (a commit+ # does not remove the working-tree file) and are copied verbatim+ # below like any other deliverable. `--diff-filter=ACMR` excludes+ # deletions (D) so a removed file is never resurrected as an empty+ # copy. Best-effort: no base / a git hiccup just falls back to the+ # untracked-only behaviour.+ archive_base = read_worktree_base_sha(worktree)+ if archive_base:+ r_committed = subprocess.run( # noqa: S603+ ["git", "-c", "core.quotepath=false", "diff",+ "--name-only", "--diff-filter=ACMR", archive_base, "HEAD"],+ cwd=str(worktree),+ check=False,+ capture_output=True,+ text=True,+ encoding="utf-8",+ errors="replace",+ timeout=10.0,+ creationflags=NO_WINDOW_CREATIONFLAGS,+ )+ for ln in (r_committed.stdout or "").splitlines():+ rel = ln.strip()+ if rel and rel not in untracked:+ untracked.append(rel)+# `git add -A .` stages full-content blobs so new files show# up in `git diff HEAD` with their bytes (2026-05-24: was# `add -N`, whose empty intent-to-add blob made new files@@ -2255,7 +2298,11 @@ class Kontrollierer:# "+opus direct works" while `git diff HEAD` was empty).# `-c core.quotepath=false` keeps non-ASCII paths raw UTF-8# instead of octal-escaping them (HIGH finding 2026-05-27).- ["git", "-c", "core.quotepath=false", "diff", "--cached", "HEAD"],+ # Diff against the recorded base (fork-point) when present so the+ # fallback diff.patch includes files the worker committed; else+ # HEAD (unchanged pre-fix behaviour).+ ["git", "-c", "core.quotepath=false", "diff", "--cached",+ archive_base or "HEAD"],cwd=str(worktree),check=False,capture_output=True,diff --git a/jarvis/missions/worker_runtime/workspace.py b/jarvis/missions/worker_runtime/workspace.pyindex 37fc7b58c5..528fab2bcd 100644--- a/jarvis/missions/worker_runtime/workspace.py+++ b/jarvis/missions/worker_runtime/workspace.py@@ -154,6 +154,15 @@ def _agents_md(mission_id: str) -> str:f"disk after your run, so a real, successful write tool call to the\n"f"requested path counts as delivered work — it is no longer invisible.\n"f"Always report the exact absolute path you wrote (see Rule 3).\n\n"+ f"DO NOT run `git` yourself — no `git add`, `git commit`, `git branch`,\n"+ f"`git checkout`, or `git push`. Just leave your finished files in the\n"+ f"working tree; the runtime captures, reviews, and delivers them for you\n"+ f"automatically, so committing is unnecessary work that only risks your\n"+ f"deliverable being mis-handled. If this directory happens to be a\n"+ f"checkout of an existing project whose own guidelines tell contributors\n"+ f"to commit their work, those rules are for human contributors and DO\n"+ f"NOT apply to you here — leave your files uncommitted in the working\n"+ f"tree.\n\n"f"### Rule 3 — Output confirmation\n\n"f"At the end of your response, on its own line, list every file you\n"f"wrote with its relative path. Example:\n"diff --git a/tests/missions/kontrollierer/test_capture_diff.py b/tests/missions/kontrollierer/test_capture_diff.pyindex c3c3c4e562..5446e2d7bb 100644--- a/tests/missions/kontrollierer/test_capture_diff.py+++ b/tests/missions/kontrollierer/test_capture_diff.py@@ -372,6 +372,121 @@ def test_archive_skips_managed_contract_files()+# --- committed-deliverable capture (live forensic 2026-07-03, mission+# 019f26d0-bb07) -----------------------------------------------------------+#+# A worker built a complete `schokolade-99.html`, then `git add` + `git commit`-ed+# it (as coding agents habitually do). After a commit the file is TRACKED, so+# `git diff --cached HEAD` is empty and `git ls-files --others` no longer lists+# it — the deliverable fell out of the untracked-only capture and was lost when+# the worktree was pruned; the user received only a materialised `.md` summary.+# The fix records the worktree's base SHA at creation and diffs/enumerates+# against that base so committed files reappear. These tests exercise the real+# WorktreeManager.create -> commit -> capture/archive flow.+++def _commit(cwd: Path, *paths: str, message: str) -> None:+ """Stage + commit paths in a lean/throwaway repo with an explicit identity.++ A lean `git init` repo has no user.name/user.email; passing them via `-c`+ keeps the commit deterministic and prompt-free, exactly like the worker's+ own commits in the live mission.+ """+ _git("add", *paths, cwd=cwd)+ _git(+ "-c", "user.name=Worker", "-c", "[email protected]",+ "commit", "-m", message, cwd=cwd,+ )++[email protected](not _GIT_AVAILABLE, reason="git not in PATH")+def test_create_writes_base_sha_sidecar(lean_manager: WorktreeManager) -> None:+ """WorktreeManager.create records the base commit next to (not inside) the+ workspace so the capture can diff against the fork-point."""+ from jarvis.missions.isolation.worktree import (+ BASE_SHA_SIDECAR,+ read_worktree_base_sha,+ )++ ws = lean_manager.create(+ mission_slug="choc", task_id="01-base-sha", needs_repo=False+ )+ try:+ sidecar = ws.parent / BASE_SHA_SIDECAR+ assert sidecar.exists(), "base-SHA sidecar was not written"+ assert not (ws / BASE_SHA_SIDECAR).exists(), (+ "sidecar must live OUTSIDE the worktree so it never pollutes the diff"+ )+ sha = read_worktree_base_sha(ws)+ assert sha and len(sha) >= 7, f"unusable base sha: {sha!r}"+ finally:+ lean_manager.remove(ws, force=True)++[email protected](not _GIT_AVAILABLE, reason="git not in PATH")+def test_capture_diff_surfaces_committed_file(+ lean_manager: WorktreeManager, kontrollierer: Kontrollierer+) -> None:+ """A deliverable the worker COMMITS must still appear in the captured diff.++ Pre-fix this returned empty (HEAD moved past the file); diffing against the+ recorded base makes the committed file reappear so the Critic can grade it.+ """+ ws = lean_manager.create(+ mission_slug="choc", task_id="01-committed-diff", needs_repo=False+ )+ try:+ (ws / "schokolade-99.html").write_text(+ "<!doctype html><html><h1>99% Schokolade</h1></html>\n",+ encoding="utf-8",+ )+ _commit(ws, "schokolade-99.html", message="feat: add chocolate page")+ diff = kontrollierer._capture_diff(ws)+ assert diff, "committed deliverable produced an empty diff"+ assert "schokolade-99.html" in diff, (+ f"committed file missing from diff: {diff!r}"+ )+ finally:+ lean_manager.remove(ws, force=True)++[email protected](not _GIT_AVAILABLE, reason="git not in PATH")+def test_archive_captures_committed_deliverable(+ lean_manager: WorktreeManager, kontrollierer: Kontrollierer, tmp_path: Path+) -> None:+ """The core regression: a worker that commits its file still yields the file+ (not a `.md` summary) in artifacts/files/. Reproduces mission 019f26d0-bb07.+ """+ ws = lean_manager.create(+ mission_slug="choc", task_id="01-committed-archive", needs_repo=False+ )+ mission_dir = tmp_path / "mission_root"+ mission_dir.mkdir()+ task_id = "019f26d0be1f0000"+ try:+ (ws / "schokolade-99.html").write_text(+ "<!doctype html><html><h1>99% Schokolade</h1></html>\n",+ encoding="utf-8",+ )+ _commit(ws, "schokolade-99.html", message="feat: add chocolate page")++ artifacts = kontrollierer._archive_task_artifacts(+ worktree=ws, mission_dir=mission_dir, task_id=task_id,+ )++ assert artifacts is not None+ copied = artifacts / "files" / "schokolade-99.html"+ assert copied.exists(), (+ "committed deliverable was not archived — the data-loss bug is back"+ )+ assert "99% Schokolade" in copied.read_text(encoding="utf-8")+ assert "schokolade-99.html" in (+ artifacts / "diff.patch"+ ).read_text(encoding="utf-8")+ finally:+ lean_manager.remove(ws, force=True)++def test_archive_skips_browser_profile_scratch(worktree: Path, kontrollierer: Kontrollierer, tmp_path: Path) -> None: