Skip to content

The agent that grows with you

fix(backup): keep durable cache/ artifacts (images, citation ledger) in full backups

teknium1535fd88c701d
diff --git a/hermes_cli/backup.py b/hermes_cli/backup.py
index f3ab2bcc9f4..19d7ec9bd2d 100644
--- a/hermes_cli/backup.py
+++ b/hermes_cli/backup.py
@@ -60,20 +60,28 @@ _EXCLUDED_DIRS = {
".cache", ".tox", ".nox", ".pytest_cache", ".mypy_cache", ".ruff_cache",
}
-# Hermes-managed runtime downloads (GGUF models, llama.cpp runtimes, managed Node) and caches are
-# regenerable. Runtime trees routinely reach tens to hundreds of GB; live browser/tool caches may
-# also contain locked SQLite databases that cannot be snapshotted consistently. Match these names
-# ONLY at the root of HERMES_HOME and at ``profiles/<name>/`` — a deeper directory of the same name
-# (for example, a skill's ``models/`` or ``cache/``) is user data and must survive.
-_EXCLUDED_ROOT_DIRS = {"cache", "models", "runtimes", "node"}
+# Hermes-managed runtime downloads (GGUF models, llama.cpp runtimes, managed Node): re-downloaded
+# on demand and routinely tens to hundreds of GB. Matched ONLY at the root of HERMES_HOME and at
+# ``profiles/<name>/`` — a deeper dir of the same name (a skill's ``models/``) is user data.
+_EXCLUDED_ROOT_DIRS = {"models", "runtimes", "node"}
+
+# ``cache/`` at those same roots mixes regenerable state (model/plugin catalogs, stamps, browser
+# profiles with locked SQLite, tool-output spill) with durable artifacts nothing can rebuild: media
+# the gateway delivered to or received from the user (``gateway.platforms.base``'s media-delivery
+# subdirs) and the grounded-citations evidence ledger. Only these subdirs are archived.
+_KEPT_CACHE_SUBDIRS = {"images", "audio", "videos", "documents", "screenshots", "citations"}
def _in_excluded_root_dir(rel_path: Path) -> bool:
"""True when *rel_path* is inside a regenerable tree at a profile-home root."""
parts = rel_path.parts
- return bool(parts) and (
- parts[0] in _EXCLUDED_ROOT_DIRS
- or (len(parts) >= 3 and parts[0] == "profiles" and parts[2] in _EXCLUDED_ROOT_DIRS))
+ if len(parts) >= 3 and parts[0] == "profiles":
+ parts = parts[2:]
+ if not parts:
+ return False
+ if parts[0] in _EXCLUDED_ROOT_DIRS:
+ return True
+ return parts[0] == "cache" and len(parts) >= 2 and parts[1] not in _KEPT_CACHE_SUBDIRS
# SQLite sidecars are excluded because ``*.db`` is snapshotted via ``sqlite3.backup()``:
diff --git a/tests/hermes_cli/test_backup.py b/tests/hermes_cli/test_backup.py
index 57ff336dc88..5b438e953fb 100644
--- a/tests/hermes_cli/test_backup.py
+++ b/tests/hermes_cli/test_backup.py
@@ -172,11 +172,15 @@ class TestShouldExclude:
assert _should_exclude(Path("profiles/clean/models/big.gguf"))
assert _should_exclude(Path("profiles/clean/runtimes/llamacpp/x.dll"))
- def test_excludes_regenerable_cache_at_profile_roots(self):
- """Live browser/tool caches are mutable and unsafe to snapshot."""
+ def test_excludes_regenerable_cache_but_keeps_durable_artifacts(self):
+ """Catalogs and live browser profiles are rebuilt on demand; delivered media and the
+ citation ledger are not, so they stay in the archive."""
from hermes_cli.backup import _should_exclude
+ assert _should_exclude(Path("cache/model_catalog.json"))
assert _should_exclude(Path("cache/chrome-debug/Default/Cookies"))
assert _should_exclude(Path("profiles/sage/cache/chrome-debug/cache.db"))
+ assert not _should_exclude(Path("cache/images/x.png"))
+ assert not _should_exclude(Path("profiles/sage/cache/citations/ledger.json"))
assert not _should_exclude(Path("skills/example/cache/notes.md"))
def test_keeps_nested_dirs_named_like_runtime_trees(self):
@@ -240,29 +244,31 @@ class TestIterBackupFiles:
assert str(Path("models/big.gguf")) not in selected
assert not any(s.startswith("hermes-agent") for s in selected)
- def test_prunes_profile_root_caches_but_keeps_nested_user_cache(self, tmp_path):
+ def test_prunes_regenerable_caches_but_keeps_durable_and_nested(self, tmp_path):
from hermes_cli.backup import _iter_backup_files
root = tmp_path / ".hermes"
root.mkdir()
- root_cache = root / "cache" / "browser"
- profile_cache = root / "profiles" / "sage" / "cache" / "browser"
- nested_cache = root / "skills" / "example" / "cache"
- for directory in (root_cache, profile_cache, nested_cache):
- directory.mkdir(parents=True)
- (directory / "state.db").write_bytes(b"cache contents")
+ files = {
+ "cache/model_catalog.json": False,
+ "cache/chrome-debug/Default/Cookies": False,
+ "profiles/sage/cache/chrome-debug/cache.db": False,
+ "cache/images/x.png": True,
+ "cache/citations/ledger.json": True,
+ "profiles/sage/cache/images/y.png": True,
+ "skills/example/cache/state.db": True,
+ }
+ for rel in files:
+ (root / rel).parent.mkdir(parents=True, exist_ok=True)
+ (root / rel).write_bytes(b"x")
skipped: set = set()
- selected = {
- str(rel)
- for _, rel in _iter_backup_files(root, tmp_path / "out.zip", skipped)
- }
+ selected = {str(rel) for _, rel in _iter_backup_files(root, tmp_path / "out.zip", skipped)}
- assert str(Path("cache/browser/state.db")) not in selected
- assert str(Path("profiles/sage/cache/browser/state.db")) not in selected
- assert str(Path("skills/example/cache/state.db")) in selected
- assert "cache" in skipped
- assert str(Path("profiles/sage/cache")) in skipped
+ assert {rel for rel, keep in files.items() if keep} == {s.replace(os.sep, "/") for s in selected}
+ assert str(Path("cache/chrome-debug")) in skipped
+ assert str(Path("profiles/sage/cache/chrome-debug")) in skipped
+ assert "cache" not in skipped
def test_skipped_dirs_collected_for_summary(self, tmp_path):
from hermes_cli.backup import _iter_backup_files
diff --git a/website/docs/reference/cli-commands.md b/website/docs/reference/cli-commands.md
index bf2a75d7df4..9e712c55884 100644
--- a/website/docs/reference/cli-commands.md
+++ b/website/docs/reference/cli-commands.md
@@ -980,7 +980,8 @@ The backup uses SQLite's `backup()` API for safe copying, so it works correctly
- `*.db-wal`, `*.db-shm`, `*.db-journal` — SQLite's WAL / shared-memory / journal sidecars. The `*.db` file already got a consistent snapshot via `sqlite3.backup()`; shipping the live sidecars alongside it would let a restore see a half-committed state.
- `checkpoints/` — per-session trajectory caches. Hash-keyed and regenerated per session; wouldn't port cleanly to another install anyway.
-- `cache/`, `models/`, `runtimes/`, `node/` at the root of `~/.hermes` (and of each `profiles/<name>/`) — regenerable downloads and tool caches, often tens of GB. Deeper directories with the same names (a skill's `cache/`) are kept.
+- `models/`, `runtimes/`, `node/` at the root of `~/.hermes` (and of each `profiles/<name>/`) — regenerable runtime downloads, often tens of GB. Deeper directories with the same names (a skill's `models/`) are kept.
+- Regenerable entries of `cache/` at those same roots — model/plugin catalogs, stamps, browser profiles, tool-output spill. Durable artifacts stay in: `cache/images`, `cache/audio`, `cache/videos`, `cache/documents`, `cache/screenshots` (media delivered to or received from you) and `cache/citations` (the grounded-citations ledger). A deeper `cache/` (inside a skill) is kept whole.
- Unix sockets, devices, and symlinks — a zip cannot hold them; before they were excluded, a stray `gateway.sock` made every full backup report `Backup incomplete`.
- The `hermes-agent` code itself (this is a user-data backup, not a repo snapshot).