Skip to content

The agent that grows with you

fix: explain safe transcript salvage when canonical restore is refused

Tekniumc559236f6824
diff --git a/hermes_cli/backup.py b/hermes_cli/backup.py
index fbeaba2ea59..bb484d653ea 100644
--- a/hermes_cli/backup.py
+++ b/hermes_cli/backup.py
@@ -482,7 +482,14 @@ def _restore_epoch_source(src: Path, dst: Path):
if dst.name != 'state.db' and dst.resolve().name != 'state.db':
yield src
return
- floor = _restore_epoch(dst)
+ try:
+ floor = _restore_epoch(dst)
+ except (OSError, sqlite3.Error, ValueError) as exc:
+ raise OSError(
+ f"Cannot read the canonical runtime epoch at {dst}; refusing in-place restore. "
+ "Use `hermes sessions recover --source <snapshot> --output <separate-path>` "
+ "to salvage transcripts into a separate output."
+ ) from exc
if floor <= _restore_epoch(src):
yield src
return
diff --git a/tests/hermes_cli/test_restore_own_holder_guard.py b/tests/hermes_cli/test_restore_own_holder_guard.py
index 0535633d908..050500dec4c 100644
--- a/tests/hermes_cli/test_restore_own_holder_guard.py
+++ b/tests/hermes_cli/test_restore_own_holder_guard.py
@@ -107,7 +107,8 @@ def test_update_autorestore_refuses_under_own_live_connection(
def test_safe_restore_fallback_still_works_without_holder(tmp_path):
- dst = tmp_path / "state.db"
+ # A genuinely non-runtime store has no canonical authority epoch to preserve.
+ dst = tmp_path / "projects.db"
src = tmp_path / "snap.db"
_make_db(src, "snapshot-good")
_make_db(dst, "live-old")
@@ -118,6 +119,16 @@ def test_safe_restore_fallback_still_works_without_holder(tmp_path):
assert _read_marker(dst) == "snapshot-good"
+def test_safe_restore_refuses_unreadable_canonical_epoch(tmp_path, caplog):
+ dst, src = tmp_path / "state.db", tmp_path / "snapshot.db"
+ _make_db(src, "snapshot-good")
+ dst.write_bytes(b"unreadable canonical epoch")
+ before = dst.read_bytes(), src.read_bytes()
+ assert backup_mod._safe_restore_db(src, dst) is False
+ assert (dst.read_bytes(), src.read_bytes()) == before
+ assert "separate output" in caplog.text
+
+
def test_update_autorestore_still_works_without_holder(tmp_path):
dst = tmp_path / "state.db"
src = tmp_path / "snap.db"