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): keep browser-profile scratch out of mission deliverables
Ruben Lütke6b54d30cde50
diff --git a/jarvis/missions/kontrollierer/deliverable.py b/jarvis/missions/kontrollierer/deliverable.pyindex 637c6e6a77..b4dfdfa247 100644--- a/jarvis/missions/kontrollierer/deliverable.py+++ b/jarvis/missions/kontrollierer/deliverable.py@@ -38,6 +38,7 @@ from pathlib import Pathfrom typing import Finalfrom ..stream_evidence import clean_request_body+from .deliverable_paths import is_nondeliverable_scratchlogger = logging.getLogger(__name__)@@ -107,7 +108,9 @@ def build_deliverable_summary(mission_dir: Path) -> str:if not files_dir.exists() or not files_dir.is_dir():continuefor path in files_dir.rglob("*"):- if path.is_file():+ if path.is_file() and not is_nondeliverable_scratch(+ path.relative_to(files_dir).as_posix()+ ):names.append(path.name)except OSError:# Defensive: filesystem hiccups must not crash the readback path.@@ -141,7 +144,12 @@ def _existing_deliverable_files(mission_dir: Path) -> list[Path]:files_dir = task_dir / "artifacts" / "files"if not files_dir.is_dir():continue- out.extend(p for p in files_dir.rglob("*") if p.is_file())+ out.extend(+ p for p in files_dir.rglob("*")+ if p.is_file() and not is_nondeliverable_scratch(+ p.relative_to(files_dir).as_posix()+ )+ )except OSError:return outreturn out@@ -361,7 +369,9 @@ def deliver_to_user_folder(if not files_dir.is_dir():continuefor path in sorted(files_dir.rglob("*")):- if path.is_file():+ if path.is_file() and not is_nondeliverable_scratch(+ path.relative_to(files_dir).as_posix()+ ):sources.append(path)except OSError as exc:logger.warning("deliver: enumerating %s failed: %s", tasks_root, exc)diff --git a/jarvis/missions/kontrollierer/deliverable_paths.py b/jarvis/missions/kontrollierer/deliverable_paths.pynew file mode 100644index 0000000000..62ebccc6e3--- /dev/null+++ b/jarvis/missions/kontrollierer/deliverable_paths.py@@ -0,0 +1,163 @@+"""Single source of truth for "is this archive path a genuine deliverable?".++A worker runs in a fresh ``git worktree``; the Kontrollierer archives its+outputs into ``<mission_dir>/tasks/<id>/artifacts/files/<rel>`` by enumerating+untracked files (``git ls-files --others``) AND — since the 2026-05-27 hardening+audit — gitignored files (``git ls-files --others --ignored``, the "union" that+captures deliverables a worker named with an ignored pattern such as+``output.log`` or anything under ``dist/``). That union is deliberately broad,+so a denylist must keep tool-scratch out of ``artifacts/files/``.++Three layers consume this predicate, so it lives in ONE module to stop the+multi-layer drift bug class (CLAUDE.md / BUG-008):++ * the archive filter — :func:`Kontrollierer._archive_task_artifacts`+ (``orchestrator.py``) — keeps scratch out of the archive at the source;+ * the Outputs-view listing + download/raw/view guards+ (``ui/web/outputs_routes.py``) — hides scratch already on disk from+ pre-fix missions and any other archive path;+ * the user-folder mirror + voice readback+ (``deliverable.py``) — keeps the user's Downloads and the spoken+ "N Dateien gespeichert" count free of scratch.++Live forensic 2026-06-21 (mission_019eeb34-bb67): a browser/QA worker launched+four headless Chrome instances with profiles under+``qa-artifacts/chrome-profile-<hex>/`` and gitignored them (``chrome-profile-*/``).+The ``--ignored`` union re-imported all 199 cache / shader / journal blobs+(68 of them 0-byte) into ``artifacts/files/`` next to the 2 real deliverables;+the Outputs view (cap 200, sort-by-mtime) then buried the real files under the+fresher junk — the user saw "the files aren't shown" and "empty files". The+denylist below recognises browser user-data directories so the union can keep+capturing real ignored deliverables WITHOUT re-importing browser scratch.++Pure stdlib, pure-string, cross-platform (normalises ``\\`` to ``/``). It can+only ever REMOVE recognised scratch from a listing — never a real deliverable,+as long as the patterns stay tight (guarded by ``test_deliverable_paths.py``).+"""+from __future__ import annotations++import re+from typing import Final++# Directory-segment names whose contents are never worker deliverables: git+# internals, the materialized OpenClaw state, language/build dep caches, and+# browser-engine cache/state subdirectories. NOTE: build *output* dirs+# (``dist/``, ``build/``, ``.next/``) are intentionally NOT here — the+# ``--ignored`` union exists precisely to capture deliverables a worker emits+# there. Only add a name when it is unmistakably tool-scratch, never a result.+_JUNK_DIR_NAMES: Final[frozenset[str]] = frozenset({+ # git / project scaffolding + dependency / language caches (pre-2026-06-21)+ ".git",+ ".openclaw",+ "openclaw_state",+ "node_modules",+ "__pycache__",+ ".venv",+ ".pytest_cache",+ ".mypy_cache",+ ".ruff_cache",+ # Chromium / Chrome / Edge user-data-dir cache + state subdirectories.+ # A browser/QA worker (the browser-ui-checkup skill, Playwright, Puppeteer,+ # Selenium) launches a real browser with a ``--user-data-dir`` inside the+ # worktree; the engine writes hundreds of these. The names carry spaces /+ # camel-case that essentially never name a real deliverable, so excluding+ # them catches a browser profile even when its root dir is named+ # unconventionally (defence-in-depth behind _BROWSER_PROFILE_SEG_RE).+ "GrShaderCache",+ "GPUCache",+ "ShaderCache",+ "Code Cache",+ "DawnGraphiteCache",+ "DawnWebGPUCache",+ "GraphiteDawnCache",+ "Crashpad",+ "Crash Reports",+ "Service Worker",+ "Shared Dictionary",+ "Subresource Filter",+ "Safe Browsing",+ "component_crx_cache",+ "extensions_crx_cache",+ "segmentation_platform",+ "BrowserMetrics",+})+++# A path SEGMENT that is a browser user-data / automation profile ROOT. Matching+# the root catches the WHOLE profile subtree — including the top-level files+# (``Local State``, ``Last Browser``, ``Variations``, ``Preferences``,+# ``First Run``, ``*.db-journal``) that carry no cache-dir segment and would+# otherwise leak past the _JUNK_DIR_NAMES check. The worker's own ``.gitignore``+# in the live forensic used exactly ``chrome-profile-*/``.+_BROWSER_PROFILE_SEG_RE: Final[re.Pattern[str]] = re.compile(+ r"""^(+ # <engine>[-_.]?(profile|user-data|userdata)[-_.suffix] → chrome-profile-<hex>+ (?:chrome|chromium|edge|msedge|brave|opera|vivaldi|webkit|firefox)+ [._-]?(?:profile|user-?data)(?:[._-].*)?+ # explicit "...user-data-dir..." anywhere in the segment+ | .*[._-]user-data-dir.*+ # automation-harness temp profiles+ | puppeteer[._-]dev[._-]chrome[._-]profile.*+ | playwright[._-].*profile.*+ | selenium[._-].*profile.*+ # Chrome's own scratch profile dir (scoped_dir<pid>_<n>) — requires a+ # trailing digit so it can't swallow a real "scoped_directory/".+ | scoped_dir[0-9].*+ # macOS temp profile bundles+ | \.(?:org\.chromium\.Chromium|com\.google\.Chrome|com\.microsoft\.Edge)\..*+ )$""",+ re.IGNORECASE | re.VERBOSE,+)+++def is_browser_scratch_segment(segment: str) -> bool:+ """True iff *segment* is a browser user-data / automation profile root dir."""+ return bool(_BROWSER_PROFILE_SEG_RE.match(segment))+++def is_nondeliverable_scratch(rel: str) -> bool:+ """True iff a path is internal tool-scratch, not a genuine deliverable.++ Cross-platform: backslashes are normalised to ``/`` and leading/trailing+ slashes are stripped before the per-segment checks. An empty / root path is+ NOT scratch (returns False) — the caller decides what to do with it.++ A path is scratch iff ANY of its segments is a known junk directory+ (:data:`_JUNK_DIR_NAMES`) or a browser-profile root+ (:func:`is_browser_scratch_segment`).+ """+ norm = rel.replace("\\", "/").strip("/")+ if not norm:+ return False+ for seg in norm.split("/"):+ if not seg or seg == ".":+ continue+ if seg in _JUNK_DIR_NAMES:+ return True+ if is_browser_scratch_segment(seg):+ return True+ return False+++def is_deliverable_path(rel: str, *, managed_files: frozenset[str] = frozenset()) -> bool:+ """True iff a worktree-relative path is a genuine worker deliverable.++ False for an empty path, for a managed worker-contract file (``AGENTS.md``+ etc. — pass the caller's set via *managed_files*), and for any tool-scratch+ path (:func:`is_nondeliverable_scratch`). This is the full archive-side+ predicate; the read-side layers use :func:`is_nondeliverable_scratch`+ directly (managed contract files never reach ``artifacts/files/``).+ """+ norm = rel.replace("\\", "/").strip("/")+ if not norm:+ return False+ if norm in managed_files:+ return False+ return not is_nondeliverable_scratch(norm)+++__all__ = [+ "is_browser_scratch_segment",+ "is_deliverable_path",+ "is_nondeliverable_scratch",+]diff --git a/jarvis/missions/kontrollierer/orchestrator.py b/jarvis/missions/kontrollierer/orchestrator.pyindex e54f39af78..52b8511bcf 100644--- a/jarvis/missions/kontrollierer/orchestrator.py+++ b/jarvis/missions/kontrollierer/orchestrator.py@@ -73,6 +73,7 @@ from .deliverable import (deliver_to_user_folder,materialize_answer_document,)+from .deliverable_paths import is_deliverable_pathfrom ..safety import (extract_worker_authored_text,filter_diff_paths,@@ -189,39 +190,20 @@ _MANAGED_PERSONA_FILES: Final[frozenset[str]] = frozenset({".openclaw/workspace-state.json",})-# Directory names whose contents are never worker deliverables — git-# internals, the materialized OpenClaw state, and build/cache junk. The-# ``--ignored`` enumeration union in ``_archive_task_artifacts`` (added by-# the 2026-05-27 hardening audit to capture gitignored deliverables such as-# ``output.log``) would otherwise surface this noise into ``artifacts/files/``-# — the exact Outputs-UI garbage Wave 3 (2026-05-26) removed.-_JUNK_DIR_NAMES: Final[frozenset[str]] = frozenset({- ".git",- ".openclaw",- "openclaw_state",- "node_modules",- "__pycache__",- ".venv",- ".pytest_cache",- ".mypy_cache",- ".ruff_cache",-})--def _is_deliverable_path(rel: str) -> bool:"""True if a worktree-relative path is a genuine worker deliverable.- False for managed worker-contract files (``AGENTS.md`` etc.) and for- anything inside a git-internal / state / build-cache directory. Used to- filter the untracked-file enumeration before copying into- ``artifacts/files/`` so the Outputs UI shows only real deliverables.+ Thin wrapper over the shared :func:`deliverable_paths.is_deliverable_path`+ — the single source of truth shared with the Outputs view + the user-folder+ mirror (anti-drift, BUG-008 class). False for managed worker-contract files+ (``AGENTS.md`` etc.), git-internal / state / dep-cache dirs, AND browser+ user-data / profile scratch (the 2026-06-21 chrome-profile leak,+ mission_019eeb34-bb67: a QA worker's 4 gitignored Chrome profiles were+ re-imported by the ``--ignored`` enumeration union below and buried the 2+ real deliverables in the Outputs view). Used to filter the untracked ++ ``--ignored`` union before copying into ``artifacts/files/``."""- norm = rel.replace("\\", "/").strip("/")- if not norm:- return False- if norm in _MANAGED_PERSONA_FILES:- return False- return not any(seg in _JUNK_DIR_NAMES for seg in norm.split("/"))+ return is_deliverable_path(rel, managed_files=_MANAGED_PERSONA_FILES)def _real_diff_is_empty(diff_text: str) -> bool:diff --git a/tests/missions/kontrollierer/test_capture_diff.py b/tests/missions/kontrollierer/test_capture_diff.pyindex 4bee91e30f..fc7fa1257b 100644--- a/tests/missions/kontrollierer/test_capture_diff.py+++ b/tests/missions/kontrollierer/test_capture_diff.py@@ -370,3 +370,67 @@ def test_archive_skips_managed_contract_files(assert not (files_dir / "AGENTS.md").exists(), ("managed contract file AGENTS.md leaked into artifacts/files/")+++def test_archive_skips_browser_profile_scratch(+ worktree: Path, kontrollierer: Kontrollierer, tmp_path: Path+) -> None:+ """Live forensic 2026-06-21 (mission_019eeb34-bb67): a browser/QA worker+ launched headless Chrome with a ``--user-data-dir`` under ``qa-artifacts/``+ and correctly gitignored the profiles (``chrome-profile-*/``). The archive's+ ``--ignored`` enumeration union re-imported all 199 cache / journal blobs+ into ``artifacts/files/``, where the Outputs view (cap 200, sort-by-mtime)+ buried the 2 real deliverables — the user saw "files not shown" / "empty+ files". The archive must drop the browser-profile subtree while KEEPING the+ genuine deliverables, including a real artifact that lives inside the same+ ``qa-artifacts/`` dir next to the junk."""+ # Genuine deliverables (one of them sits INSIDE qa-artifacts next to junk).+ (worktree / "index.html").write_text("<h1>real</h1>\n", encoding="utf-8")+ qa = worktree / "qa-artifacts"+ qa.mkdir()+ (qa / ".gitignore").write_text("chrome-profile-*/\n", encoding="utf-8")+ (qa / "melbourne-plan-render.png").write_bytes(b"\x89PNG\r\n\x1a\n realdata")+ # Browser scratch the worker gitignored — 4 profiles' worth of cache junk,+ # incl. a 0-byte journal ("empty file") and a top-level profile file that+ # carries no cache-dir segment (only the profile-root match catches it).+ prof = qa / "chrome-profile-dd6355b81ddb49db87fc5045a7012b19"+ (prof / "GrShaderCache").mkdir(parents=True)+ (prof / "GrShaderCache" / "data_2").write_text("shadercache", encoding="utf-8")+ (prof / "Default" / "Shared Dictionary").mkdir(parents=True)+ (prof / "Default" / "Shared Dictionary" / "db-journal").write_text(+ "", encoding="utf-8"+ )+ (prof / "Last Browser").write_text("chrome\n", encoding="utf-8")++ # Sanity: the profile really is gitignored (so only the --ignored union+ # could resurrect it), mirroring the live mission.+ chk = _git("check-ignore", "qa-artifacts/chrome-profile-dd6355b81ddb49db87fc5045a7012b19/Last Browser", cwd=worktree)+ if chk.returncode != 0:+ pytest.skip(+ "chrome-profile not gitignored in this worktree state — "+ f"check-ignore rc={chk.returncode}"+ )++ mission_dir = tmp_path / "mission_root"+ mission_dir.mkdir()+ task_id = "beefcafe98760000"++ artifacts = kontrollierer._archive_task_artifacts(+ worktree=worktree,+ mission_dir=mission_dir,+ task_id=task_id,+ )++ assert artifacts is not None+ files_dir = artifacts / "files"+ # Real deliverables survive.+ assert (files_dir / "index.html").exists(), "genuine deliverable missing"+ assert (files_dir / "qa-artifacts" / "melbourne-plan-render.png").exists(), (+ "real artifact inside qa-artifacts/ was wrongly dropped"+ )+ # The whole browser-profile subtree is gone — no chrome-profile dir at all.+ leaked = [+ p for p in files_dir.rglob("*")+ if "chrome-profile-dd6355b81ddb49db87fc5045a7012b19" in p.parts+ ]+ assert not leaked, f"browser-profile scratch leaked into archive: {leaked}"diff --git a/tests/missions/kontrollierer/test_deliver_to_user_folder.py b/tests/missions/kontrollierer/test_deliver_to_user_folder.pyindex df5d35092e..5ceaf9d84a 100644--- a/tests/missions/kontrollierer/test_deliver_to_user_folder.py+++ b/tests/missions/kontrollierer/test_deliver_to_user_folder.py@@ -98,3 +98,32 @@ def test_build_delivered_summary_single(tmp_path: Path) -> None:def test_build_delivered_summary_empty() -> None:assert build_delivered_summary([]) == ""+++def test_skips_browser_profile_scratch(tmp_path: Path) -> None:+ """Defence-in-depth for the chrome-profile leak (mission_019eeb34-bb67):+ the user-folder mirror must NOT flood Downloads with a browser/QA worker's+ gitignored Chrome user-data profiles that a pre-fix archive captured. The+ real deliverable (incl. one inside qa-artifacts/ next to the junk) must+ still be delivered."""+ mission = tmp_path / "mission_abc"+ files = mission / "tasks" / "019eeb34-bc50" / "artifacts" / "files"+ # Genuine deliverables.+ _make_artifact(mission, "019eeb34-bc50", "index.html", "<h1>real</h1>")+ (files / "qa-artifacts").mkdir(parents=True, exist_ok=True)+ (files / "qa-artifacts" / "melbourne-plan-render.png").write_bytes(b"PNGdata")+ # Browser scratch the archive should never have copied.+ prof = files / "qa-artifacts" / "chrome-profile-dd6355b81ddb49db87fc5045a7012b19"+ (prof / "GrShaderCache").mkdir(parents=True, exist_ok=True)+ (prof / "GrShaderCache" / "data_2").write_text("junk", encoding="utf-8")+ (prof / "Last Browser").write_text("chrome", encoding="utf-8")++ target = tmp_path / "delivered"+ delivered = deliver_to_user_folder(+ mission, mission_short_id="019eeb34", override_dir=str(target)+ )++ names = sorted(p.name for p in delivered)+ assert names == ["index.html", "melbourne-plan-render.png"], names+ assert not (target / "data_2").exists()+ assert not (target / "Last Browser").exists()diff --git a/tests/missions/kontrollierer/test_deliverable_paths.py b/tests/missions/kontrollierer/test_deliverable_paths.pynew file mode 100644index 0000000000..f5031b853c--- /dev/null+++ b/tests/missions/kontrollierer/test_deliverable_paths.py@@ -0,0 +1,111 @@+"""Unit tests for the shared deliverable-path predicate.++Single source of truth that tells a genuine worker deliverable from internal+tool-scratch in a mission's ``artifacts/files/`` subtree. The archive filter+(orchestrator), the Outputs-view listing + download guards (outputs_routes),+and the user-folder mirror (deliverable) all consume it — so this is the+anti-drift guard for "what is an output".++Live forensic 2026-06-21 (mission_019eeb34-bb67): a browser/QA worker launched+four headless Chrome instances with profiles under ``qa-artifacts/chrome-profile-*``+and the archive's ``--ignored`` enumeration union re-imported all 199 cache /+journal blobs (68 of them 0-byte) into ``artifacts/files/`` alongside the 2 real+deliverables, which the Outputs view (cap 200, sort-by-mtime) then buried. The+worker had correctly gitignored the profiles (``chrome-profile-*/``); the+denylist just didn't know browser profiles were scratch.+"""+from __future__ import annotations++import pytest++from jarvis.missions.kontrollierer.deliverable_paths import (+ is_nondeliverable_scratch,+)+++# Real junk paths copied verbatim from mission_019eeb34-bb67's archive — every+# one of these must be recognised as scratch (NOT a deliverable).+_REAL_JUNK = [+ "qa-artifacts/chrome-profile-dd6355b81ddb49db87fc5045a7012b19/GrShaderCache/data_2",+ "qa-artifacts/chrome-profile-dd6355b81ddb49db87fc5045a7012b19/Default/Cache/Cache_Data/data_3",+ "qa-artifacts/chrome-profile-dd6355b81ddb49db87fc5045a7012b19/Default/Shared Dictionary/db-journal",+ "qa-artifacts/chrome-profile-dd6355b81ddb49db87fc5045a7012b19/Default/Web Data-journal",+ "qa-artifacts/chrome-profile-215c81b1bed945dbb720aeb3f32b38d3/Last Browser",+ "qa-artifacts/chrome-profile-215c81b1bed945dbb720aeb3f32b38d3/Variations",+ "qa-artifacts/chrome-profile-53f907ebce1e41fe82c76f8894c64cf0/first_party_sets.db-journal",+ "qa-artifacts/chrome-profile-2889ad51367a4d8c9ae31efac95bb17f/Crashpad/settings.dat",+]++# Real genuine deliverables from the SAME mission — every one must survive+# (False == "is a deliverable"). Note: melbourne-plan-render.png lives INSIDE+# qa-artifacts/ next to the junk, so we must exclude the chrome-profile subtrees+# WITHOUT excluding all of qa-artifacts/.+_REAL_DELIVERABLES = [+ "index.html",+ "scripts/qa.mjs",+ "qa-artifacts/melbourne-plan-render.png",+ "qa-artifacts/.gitignore",+]++# Legit names that merely resemble browser/cache nomenclature — must NOT be+# misclassified as scratch (false-positive guard; the fix must only ever+# *remove* genuine junk, never a real deliverable).+_LEGIT_LOOKALIKES = [+ "user-profile/index.tsx", # a UI "user profile" component+ "src/profile.py", # a module literally named profile+ "data/cache.json", # a file named cache, not a cache dir+ "components/ProfileCard.tsx",+ "dist/app.js", # gitignored build output IS a deliverable+ "output.log", # gitignored log IS a deliverable+ "data_0", # a bare data_N file outside a profile+ "scoped_directory/main.py", # 'scoped_dir' prefix but not a temp profile+]++[email protected]("rel", _REAL_JUNK)+def test_real_chrome_profile_junk_is_scratch(rel: str) -> None:+ assert is_nondeliverable_scratch(rel) is True, rel++[email protected]("rel", _REAL_DELIVERABLES)+def test_real_deliverables_survive(rel: str) -> None:+ assert is_nondeliverable_scratch(rel) is False, rel++[email protected]("rel", _LEGIT_LOOKALIKES)+def test_legit_lookalikes_are_not_scratch(rel: str) -> None:+ assert is_nondeliverable_scratch(rel) is False, rel+++def test_windows_backslash_paths_normalised() -> None:+ win = r"qa-artifacts\chrome-profile-deadbeef\GrShaderCache\data_2"+ assert is_nondeliverable_scratch(win) is True+++def test_pre_existing_junk_dirs_still_filtered() -> None:+ # The dirs that were already in _JUNK_DIR_NAMES must keep being filtered.+ for rel in (+ ".git/config",+ "node_modules/react/index.js",+ "__pycache__/foo.pyc",+ ".venv/lib/site.py",+ "openclaw_state/workspace.json",+ ):+ assert is_nondeliverable_scratch(rel) is True, rel+++def test_other_browser_profile_roots() -> None:+ # Profile roots named by other engines / automation harnesses are scratch+ # even when the inner cache-dir name is unconventional.+ for rel in (+ "chromium-profile-xyz/Local State",+ "puppeteer_dev_chrome_profile-abc/Default/Preferences",+ "edge-profile-1/Last Version",+ "tmp/chrome-user-data/Default/Cookies",+ ):+ assert is_nondeliverable_scratch(rel) is True, rel+++def test_empty_and_root_paths() -> None:+ assert is_nondeliverable_scratch("") is False+ assert is_nondeliverable_scratch("/") is False