The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(backup): take the update pre-flight snapshot in one step
Chen Leshuf6ac7401e3cc
diff --git a/hermes_cli/backup_sqlite.py b/hermes_cli/backup_sqlite.pyindex f0c2d2f1ad7..9f5f0054036 100644--- a/hermes_cli/backup_sqlite.py+++ b/hermes_cli/backup_sqlite.py@@ -65,7 +65,9 @@ def _safe_copy_db(src: Path, dst: Path, *, timeout_seconds: float = 10.0) -> booelse:busy_deadline = now + max(0.0, timeout_seconds)- conn.backup(backup_conn, pages=256, progress=_check_backup_progress, sleep=0.1)+ # One step: SQLite restarts a multi-step backup whenever another connection writes the+ # source, so a live agent turn kept the 30s Desktop update pre-flight from ever finishing.+ conn.backup(backup_conn, pages=-1, progress=_check_backup_progress, sleep=0.1)return Trueexcept Exception as exc:logger.warning("SQLite safe copy failed for %s: %s", src, exc)diff --git a/tests/hermes_cli/test_backup_preflight.py b/tests/hermes_cli/test_backup_preflight.pyindex e5668288361..97b1f3f89da 100644--- a/tests/hermes_cli/test_backup_preflight.py+++ b/tests/hermes_cli/test_backup_preflight.py@@ -3,9 +3,42 @@ import jsonimport sqlite3import subprocessimport sys+import threadingfrom pathlib import Path+def test_preflight_finishes_while_another_connection_keeps_writing(tmp_path):+ # A stepped sqlite3 backup restarts on every foreign write and never finishes under load.+ home = tmp_path / "home"+ home.mkdir()+ db = home / "state.db"+ script = Path(__file__).resolve().parents[2] / "hermes_cli" / "backup_sqlite.py"+ with sqlite3.connect(db) as setup:+ setup.execute("PRAGMA journal_mode=WAL")+ setup.execute("CREATE TABLE messages (body TEXT)")+ setup.executemany("INSERT INTO messages VALUES (?)", [("x" * 4000,)] * 4000)+ stop = threading.Event()++ def write_continuously():+ with sqlite3.connect(db, timeout=5) as writer:+ while not stop.is_set():+ writer.execute("INSERT INTO messages VALUES ('live turn')")+ writer.commit()+ stop.wait(0.005)++ thread = threading.Thread(target=write_continuously)+ thread.start()+ try:+ result = subprocess.run([sys.executable, "-I", "-S", str(script), str(home)],+ capture_output=True, text=True, timeout=20)+ finally:+ stop.set()+ thread.join()+ assert result.returncode == 0, result.stderr+ with sqlite3.connect(json.loads(result.stdout)["path"]) as snapshot:+ assert snapshot.execute("PRAGMA integrity_check").fetchone() == ("ok",)++def test_preflight_captures_committed_wal_without_application_imports(tmp_path):home = tmp_path / "home"home.mkdir()