Skip to content

The agent that grows with you

fix(backup): propagate refused auth snapshot restore

Lion-Leporidae7ec4cd212323
diff --git a/hermes_cli/backup.py b/hermes_cli/backup.py
index 1c75ed8fd73..9e24f2435cc 100644
--- a/hermes_cli/backup.py
+++ b/hermes_cli/backup.py
@@ -1529,6 +1529,7 @@ def restore_quick_snapshot(
meta = json.load(f)
restored = 0
+ auth_restore_failed = False
for rel in meta.get("files", {}):
# Security: reject absolute paths and traversals in manifest entries
src = snap_dir / rel
@@ -1572,6 +1573,7 @@ def restore_quick_snapshot(
# while retaining that live single-use grant under the auth-store lock.
if not _restore_auth_json(src, dst):
logger.error("Failed to restore %s safely", rel)
+ auth_restore_failed = True
continue
else:
shutil.copy2(src, dst)
@@ -1580,7 +1582,7 @@ def restore_quick_snapshot(
logger.error("Failed to restore %s: %s", rel, exc)
logger.info("Restored %d files from snapshot %s", restored, snapshot_id)
- return restored > 0
+ return restored > 0 and not auth_restore_failed
def _count_cron_jobs(path: Path) -> Optional[int]:
diff --git a/tests/hermes_cli/test_snapshot_restore_oauth.py b/tests/hermes_cli/test_snapshot_restore_oauth.py
index bb2880c8a2c..5c135234115 100644
--- a/tests/hermes_cli/test_snapshot_restore_oauth.py
+++ b/tests/hermes_cli/test_snapshot_restore_oauth.py
@@ -524,3 +524,35 @@ def test_invalid_snapshot_auth_never_replaces_live_store(tmp_path, monkeypatch):
assert restore_quick_snapshot("bad", hermes_home=home) is False
assert live_path.read_bytes() == before
+
+
[email protected]("refusal", ["invalid-json", "hardlinked-store"])
+def test_auth_refusal_is_not_hidden_by_another_restored_file(tmp_path, monkeypatch, refusal):
+ """A partial restore must not report success after refusing the auth store (#127010)."""
+ from hermes_cli.backup import restore_quick_snapshot
+
+ home = tmp_path / "home"
+ snap_dir = home / "state-snapshots" / "partial"
+ snap_dir.mkdir(parents=True)
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ live_path = home / "auth.json"
+ live_path.write_text(json.dumps({"providers": {}, "sentinel": "live"}), encoding="utf-8")
+ before = live_path.read_bytes()
+ if refusal == "hardlinked-store":
+ try:
+ os.link(live_path, home / "shared-auth.json")
+ except (OSError, NotImplementedError) as exc:
+ pytest.skip(f"hardlink unavailable: {exc}")
+
+ (home / "config.yaml").write_text("model: live\n", encoding="utf-8")
+ (snap_dir / "config.yaml").write_text("model: snapshot\n", encoding="utf-8")
+ snapshot_auth = "{invalid-json" if refusal == "invalid-json" else json.dumps({"providers": {}})
+ (snap_dir / "auth.json").write_text(snapshot_auth, encoding="utf-8")
+ files = {name: (snap_dir / name).stat().st_size for name in ("auth.json", "config.yaml")}
+ (snap_dir / "manifest.json").write_text(json.dumps({"files": files}), encoding="utf-8")
+
+ result = restore_quick_snapshot("partial", hermes_home=home)
+
+ assert live_path.read_bytes() == before
+ assert (home / "config.yaml").read_text(encoding="utf-8") == "model: snapshot\n"
+ assert result is False