The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(curator): keep the CLI prompt off the curator's critical path; stop snapshotting the ledger and .archive
teknium12a0a6c5c0820
diff --git a/agent/curator_backup.py b/agent/curator_backup.pyindex 842a67bbfc2..eca736af663 100644--- a/agent/curator_backup.py+++ b/agent/curator_backup.py@@ -34,8 +34,11 @@ DEFAULT_KEEP = 5# with the full history (once backups are committed back, each snapshot contains the prior ones: 38MB of skills inflated to 24GB# in weeks); .locks holds skill_manage's per-skill lock files — restoring them would swap a lock out from under a waiting# writer. The tar filter in ``snapshot_skills`` applies the same set to nested paths, so a nested ``.git`` is skipped too.-# See #91449.-_EXCLUDE_TOP_LEVEL = {".curator_backups", ".hub", ".locks", ".git"}+# See #91449. ``.curator_ledger.jsonl`` is the append-only audit log and ``.archive/`` the recoverable store the curator+# promises never to delete: rolling either back to an older copy LOSES entries/skills, and both grow without bound (a 650MB+# ledger made every snapshot 820MB — and every archive step gunzips the newest snapshot in full, so a pass that pruned 57+# skills held the CLI prompt for 6 minutes).+_EXCLUDE_TOP_LEVEL = {".curator_backups", ".hub", ".locks", ".git", ".archive", ".curator_ledger.jsonl"}# Snapshot id: UTC ISO with colons replaced by dashes (Windows-safe filename); optional ``-NN`` suffix for same-second snapshots._ID_RE = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}Z(-\d{2})?$")diff --git a/cli.py b/cli.pyindex 66ff1ad4b20..56819bb3154 100644--- a/cli.py+++ b/cli.py@@ -3752,7 +3752,14 @@ class HermesCLI(CLIProcessNotificationsMixin, CLIAgentSetupMixin, CLICommandsMixpassdef _tui_startup_background_maintenance(self):- """Best-effort startup passes: curator skill maintenance, personal + org skill sync."""+ """Best-effort startup passes: curator skill maintenance, personal + org skill sync.++ Off the main thread: the curator's deterministic pass snapshots and prunes the whole+ skills tree (a due weekly pass held the prompt for 6 minutes on a large library), and+ the sync pulls can hit the network. The REPL must never wait on housekeeping."""+ threading.Thread(target=self._run_startup_maintenance, name="startup-maintenance", daemon=True).start()++ def _run_startup_maintenance(self):with suppress(Exception):from agent.curator import maybe_run_curatormaybe_run_curator(diff --git a/tests/agent/test_curator_backup.py b/tests/agent/test_curator_backup.pyindex 12826e49b88..d273835fc70 100644--- a/tests/agent/test_curator_backup.py+++ b/tests/agent/test_curator_backup.py@@ -522,6 +522,32 @@ def test_snapshot_excludes_git_and_curator_backups_and_hub(backup_env):assert "alpha/SKILL.md" in members+def test_snapshot_and_rollback_leave_ledger_and_archive_alone(backup_env):+ """The audit ledger and ``.archive/`` are never rolled into a snapshot (every archive step+ gunzips the newest snapshot in full, and both grow without bound) and never rewound by a+ rollback (an older copy of either loses entries / archived skills)."""+ cb = backup_env["cb"]+ skills = backup_env["skills"]+ _write_skill(skills, "alpha", body="v1")+ (skills / ".curator_ledger.jsonl").write_text('{"id": "old"}\n', encoding="utf-8")+ (skills / ".archive").mkdir()+ _write_skill(skills / ".archive", "pruned", body="archived body")++ snap_dir = cb.snapshot_skills(reason="snap-v1")+ with tarfile.open(snap_dir / "skills.tar.gz", "r:gz") as tf:+ members = tf.getnames()+ assert "alpha/SKILL.md" in members+ assert not any(Path(n).parts[0] in {".archive", ".curator_ledger.jsonl"} for n in members), members++ # State moves on after the snapshot; rollback restores alpha but must not touch either.+ (skills / ".curator_ledger.jsonl").write_text('{"id": "old"}\n{"id": "new"}\n', encoding="utf-8")+ _write_skill(skills / ".archive", "pruned-later", body="archived later")+ ok, msg, _ = cb.rollback(snap_dir.name)+ assert ok, msg+ assert (skills / ".curator_ledger.jsonl").read_text(encoding="utf-8").count("\n") == 2+ assert (skills / ".archive" / "pruned-later" / "SKILL.md").exists()++def test_rollback_preserves_top_level_git(backup_env):"""Rollback must preserve repository .git metadata untouched in the skills root."""cb = backup_env["cb"]diff --git a/tests/hermes_cli/test_cli_startup_maintenance_off_main_thread.py b/tests/hermes_cli/test_cli_startup_maintenance_off_main_thread.pynew file mode 100644index 00000000000..1d00b09c00a--- /dev/null+++ b/tests/hermes_cli/test_cli_startup_maintenance_off_main_thread.py@@ -0,0 +1,36 @@+"""The CLI's startup housekeeping (curator pass, skill sync) must never hold the prompt.++A due weekly curator pass on a large library snapshotted and pruned the skills tree for+six minutes on the main thread, between the banner and the input box.+"""++import threading+import time+from unittest.mock import MagicMock++import agent.curator as curator_mod+++def test_startup_maintenance_returns_while_curator_still_running(monkeypatch):+ from cli import HermesCLI++ release, entered = threading.Event(), threading.Event()+ seen = {}++ def _slow_curator(**_kw):+ seen["thread"] = threading.current_thread()+ entered.set()+ release.wait(10)++ monkeypatch.setattr(curator_mod, "maybe_run_curator", _slow_curator)+ obj = HermesCLI.__new__(HermesCLI)+ obj._console_print = MagicMock()+ started = time.monotonic()+ try:+ obj._tui_startup_background_maintenance()+ elapsed = time.monotonic() - started+ assert entered.wait(5), "curator pass never started"+ finally:+ release.set()+ assert elapsed < 5, f"startup maintenance held the caller for {elapsed:.1f}s"+ assert seen.get("thread") is not threading.main_thread()diff --git a/website/docs/user-guide/features/curator.md b/website/docs/user-guide/features/curator.mdindex da624362cda..3cd5050e69e 100644--- a/website/docs/user-guide/features/curator.md+++ b/website/docs/user-guide/features/curator.md@@ -124,7 +124,7 @@ hermes curator purge [--days N] [--dry-run] # delete archived skills older than## Backups and rollback-Before every real curator pass, Hermes takes a tar.gz snapshot of `~/.hermes/skills/` at `~/.hermes/skills/.curator_backups/<utc-iso>/skills.tar.gz`. If a pass archives or consolidates something you didn't want touched, you can undo the whole run with one command:+Before every real curator pass, Hermes takes a tar.gz snapshot of `~/.hermes/skills/` at `~/.hermes/skills/.curator_backups/<utc-iso>/skills.tar.gz`. The snapshot covers the live skill tree only: `.archive/`, the audit ledger, `.hub/`, and the backups themselves are never rolled in, and a rollback never rewinds them (an older copy would lose archived skills or ledger entries). If a pass archives or consolidates something you didn't want touched, you can undo the whole run with one command:```bashhermes curator rollback # restore newest snapshot (with confirmation)