Skip to content

The agent that grows with you

fix(doctor): warn when database.journal_mode=delete never applied to a WAL database

John Paul Solivab4a6958129c9
diff --git a/hermes_cli/doctor_platform.py b/hermes_cli/doctor_platform.py
index 59baa04bf72..5a4df2670db 100644
--- a/hermes_cli/doctor_platform.py
+++ b/hermes_cli/doctor_platform.py
@@ -90,10 +90,14 @@ def _format_db_size(db_path: Path) -> str:
def _report_database_journal_modes(hermes_home: Path | None = None, version_info: tuple[int, ...] | None = None) -> None:
- """List each database's journal mode; warn on WAL under a vulnerable SQLite."""
+ """List each database's journal mode; warn on WAL under a vulnerable SQLite, and on a configured
+ ``database.journal_mode: delete`` that never took effect."""
from hermes_cli.doctor import HERMES_HOME
- from hermes_state_wal import _path_on_cross_vm_fs, _wal_reset_repair_hint, is_sqlite_wal_reset_vulnerable
+ from hermes_state_wal import (
+ _path_on_cross_vm_fs, _wal_reset_repair_hint, is_sqlite_wal_reset_vulnerable, resolve_journal_mode,
+ )
vulnerable = is_sqlite_wal_reset_vulnerable(version_info)
+ configured = resolve_journal_mode()
try:
databases = _hermes_database_paths(hermes_home if hermes_home is not None else HERMES_HOME)
except Exception as exc:
@@ -105,7 +109,20 @@ def _report_database_journal_modes(hermes_home: Path | None = None, version_info
continue
mode, error = _read_journal_mode(path)
size = _format_db_size(path)
- if error is not None:
+ if error is None and mode == "wal" and configured == "delete":
+ # The operator configured `delete` because WAL is unsafe on their filesystem, but the runtime never
+ # live-downgrades an existing WAL database (#68545: a downgrade under open connections corrupts it)
+ # and says so only once per process in the gateway log (#85608). Doctor is the surface they check;
+ # a plain "WAL journal mode" line here reads as protected. Outranks the sibling WAL messages: the
+ # cross-VM hint's remedy ("set journal_mode: delete") is already applied.
+ if vulnerable:
+ exposed.append(name)
+ check_warn(f"{name} is in WAL mode ({size}) despite database.journal_mode=delete",
+ "(the setting never applied: an existing WAL database is never live-downgraded"
+ + ("; also exposed to the WAL-reset bug" if vulnerable else "")
+ + ". Stop every Hermes process for this profile, then run a one-time offline "
+ "'PRAGMA journal_mode=DELETE' on the file)")
+ elif error is not None:
if vulnerable:
check_warn(f"{name}: journal mode could not be read", f"({error}; cannot rule out WAL exposure)")
else:
diff --git a/tests/hermes_cli/test_doctor_journal_modes.py b/tests/hermes_cli/test_doctor_journal_modes.py
index 401fecb1bf7..d0e19f3a901 100644
--- a/tests/hermes_cli/test_doctor_journal_modes.py
+++ b/tests/hermes_cli/test_doctor_journal_modes.py
@@ -443,6 +443,35 @@ class TestReportDatabaseJournalModes:
assert db.read_bytes() == db_bytes
+class TestConfiguredDeleteNeverApplied:
+ """#111729: a database still in WAL while ``database.journal_mode: delete`` is configured is a
+ WARNING naming the unapplied setting (the runtime never live-downgrades and logs that once per
+ process), not the informational line a healthy WAL database gets; a configured ``wal`` is unchanged."""
+
+ @pytest.mark.parametrize("version, exposed", [((3, 51, 3), False), (VULNERABLE, True)])
+ def test_wal_db_under_configured_delete_warns(self, tmp_path, capsys, monkeypatch, version, exposed):
+ _make_db(tmp_path / "state.db", journal_mode="WAL")
+ monkeypatch.setattr("hermes_state_wal.resolve_journal_mode", lambda: "delete")
+
+ doctor_platform._report_database_journal_modes(tmp_path, version)
+
+ out = capsys.readouterr().out
+ assert "state.db is in WAL mode" in out and "despite database.journal_mode=delete" in out
+ assert "never live-downgraded" in out and "PRAGMA journal_mode=DELETE" in out
+ assert "state.db: WAL journal mode" not in out
+ assert ("To clear the exposure:" in out) is exposed
+
+ def test_configured_wal_keeps_the_informational_line(self, tmp_path, capsys, monkeypatch):
+ _make_db(tmp_path / "state.db", journal_mode="WAL")
+ monkeypatch.setattr("hermes_state_wal.resolve_journal_mode", lambda: "wal")
+
+ doctor_platform._report_database_journal_modes(tmp_path, (3, 51, 3))
+
+ out = capsys.readouterr().out
+ assert "state.db: WAL journal mode" in out
+ assert "despite" not in out
+
+
class TestSizeAndRepairHint:
def test_exposed_databases_report_size_and_repair_hint(self, tmp_path, capsys):
db = tmp_path / "state.db"
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index 3e08cc9154d..44ecb532e36 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -122,6 +122,12 @@ Hermes also warns (once per process per database) when an existing
database's on-disk journal mode is silently flipped to WAL on open — for
example a database an operator had manually converted to `delete` — and
names `database.journal_mode` as the setting that makes the choice stick.
+The reverse never happens automatically: a database that is already in WAL
+mode is not live-downgraded when you set `journal_mode: delete` (a downgrade
+under open connections can corrupt it). `hermes doctor` warns
+`<db> is in WAL mode despite database.journal_mode=delete` until you stop
+every Hermes process for the profile and run a one-time offline
+`PRAGMA journal_mode=DELETE` on the file.
## Environment Variable Substitution