The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(doctor): reuse the repair holder-check wrapper and keep the honest disjunction in the warning
kshitijk4poor7af776db620c
diff --git a/hermes_cli/doctor_state.py b/hermes_cli/doctor_state.pyindex 9a5f4d7512b..5f31934189c 100644--- a/hermes_cli/doctor_state.py+++ b/hermes_cli/doctor_state.py@@ -302,20 +302,19 @@ def _state_db_wal(f: Finding, should_fix: bool, state_db_path: Path) -> None:# joins the live WAL — under a running gateway that second-writer handling corrupts state.db.# Holder scan first (any other process holding the DB, or an unknown, fails closed), then run the# checkpoint on the exclusive repair guard so an opener arriving in between is refused, not joined.- from hermes_state_holders import live_writer_holds_db- from hermes_state_repair import _connect_repair_durable, _exclusive_repair_db_guard- # Honest disjunction (gate C1): a True here means "held OR unprovable" — never assert a live- # writer as fact.- held = live_writer_holds_db(state_db_path, connect_repair_durable=_connect_repair_durable)+ from hermes_state_repair import _exclusive_repair_db_guard, _live_writer_holds_db+ title = f"WAL file is large ({size // (1024*1024)} MB)"_SKIP = ("Large WAL file — cannot prove state.db is quiet (stop the profile's gateway first, then ""re-run 'hermes doctor --fix' to checkpoint)")- if held:+ # Honest disjunction (gate C1): a True here means "held OR unprovable" — never assert a live+ # writer as fact.+ if _live_writer_holds_db(state_db_path):# A large WAL is normal while Desktop or the gateway is running; a bare "run --fix" here sent# users straight into the second-writer trap (#110054).- check_warn(f"WAL file is large ({size // (1024*1024)} MB)",- "(normal while Desktop or the gateway is running — only checkpoint with them stopped)")+ check_warn(title, "(normal while Desktop or the gateway is running, or state.db cannot be "+ "inspected — checkpoint only with them stopped)")return f.issues.append(_SKIP)- check_warn(f"WAL file is large ({size // (1024*1024)} MB)", "(may indicate missed checkpoints)")+ check_warn(title, "(may indicate missed checkpoints)")if not should_fix:return f.issues.append("Large WAL file — stop the profile's gateway, then run 'hermes doctor --fix' to checkpoint")diff --git a/tests/hermes_cli/test_doctor_wal_checkpoint_guard.py b/tests/hermes_cli/test_doctor_wal_checkpoint_guard.pyindex 26667ef7308..8b97789e3b3 100644--- a/tests/hermes_cli/test_doctor_wal_checkpoint_guard.py+++ b/tests/hermes_cli/test_doctor_wal_checkpoint_guard.py@@ -11,7 +11,7 @@ from hermes_cli.doctor_report import Findingfrom hermes_cli.doctor_state import _state_db_wal-def test_doctor_checkpoint_runs_only_on_the_exclusive_repair_guard(tmp_path, monkeypatch):+def _large_wal_db(tmp_path):db = tmp_path / "state.db"setup = sqlite3.connect(str(db))setup.execute("CREATE TABLE t(x)")@@ -19,9 +19,13 @@ def test_doctor_checkpoint_runs_only_on_the_exclusive_repair_guard(tmp_path, monsetup.execute("INSERT INTO t VALUES (1)")setup.commit()setup.close()- wal = Path(f"{db}-wal")- with open(wal, "ab") as handle:+ with open(Path(f"{db}-wal"), "ab") as handle:handle.truncate(51 * 1024 * 1024)+ return db+++def test_doctor_checkpoint_runs_only_on_the_exclusive_repair_guard(tmp_path, monkeypatch):+ db = _large_wal_db(tmp_path)bare_connects: list[str] = []real_connect = sqlite3.connect@@ -66,19 +70,6 @@ def test_session_count_reads_a_home_with_uri_reserved_characters(tmp_path):assert _session_count(db) == 2-def _large_wal_db(tmp_path):- db = tmp_path / "state.db"- setup = sqlite3.connect(str(db))- setup.execute("CREATE TABLE t(x)")- setup.execute("PRAGMA journal_mode=WAL")- setup.execute("INSERT INTO t VALUES (1)")- setup.commit()- setup.close()- with open(Path(f"{db}-wal"), "ab") as handle:- handle.truncate(51 * 1024 * 1024)- return db--def test_large_wal_warning_under_a_live_writer_never_suggests_a_bare_fix(tmp_path, monkeypatch, capsys):"""`hermes doctor` (no --fix) on a large WAL while Desktop/gateway hold the DB must say it is normal andorder "stop" before any `--fix` — the bare "run 'hermes doctor --fix'" nudge is how users became the@@ -89,7 +80,7 @@ def test_large_wal_warning_under_a_live_writer_never_suggests_a_bare_fix(tmp_patfinding = Finding()_state_db_wal(finding, False, _large_wal_db(tmp_path))assert len(finding.issues) == 1 and not finding.fixed- assert "normal while Desktop or the gateway is running" in capsys.readouterr().out+ assert "normal while Desktop or the gateway is running, or state.db cannot be inspected" in capsys.readouterr().outassert finding.issues[0].index("stop the profile's gateway") < finding.issues[0].index("hermes doctor --fix")