diff --git a/hermes_cli/doctor.py b/hermes_cli/doctor.py index cba4ebcdd..0655c9adf 100644 --- a/hermes_cli/doctor.py +++ b/hermes_cli/doctor.py @@ -595,10 +595,9 @@ def run_doctor(args): if state_db_path.exists(): try: import sqlite3 - conn = sqlite3.connect(str(state_db_path)) - cursor = conn.execute("SELECT COUNT(*) FROM sessions") - count = cursor.fetchone()[0] - conn.close() + with sqlite3.connect(str(state_db_path)) as conn: + cursor = conn.execute("SELECT COUNT(*) FROM sessions") + count = cursor.fetchone()[0] check_ok(f"{_DHH}/state.db exists ({count} sessions)") except Exception as e: check_warn(f"{_DHH}/state.db exists but has issues: {e}") @@ -617,9 +616,8 @@ def run_doctor(args): ) if should_fix: import sqlite3 - conn = sqlite3.connect(str(state_db_path)) - conn.execute("PRAGMA wal_checkpoint(PASSIVE)") - conn.close() + with sqlite3.connect(str(state_db_path)) as conn: + conn.execute("PRAGMA wal_checkpoint(PASSIVE)") new_size = wal_path.stat().st_size if wal_path.exists() else 0 check_ok(f"WAL checkpoint performed ({wal_size // 1024}K → {new_size // 1024}K)") fixed_count += 1