The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(sessions): let set-journal-mode --force waive only a failed holder scan
kshitijk4poor9c0e223d964c
diff --git a/hermes_cli/sessions_cmd_journal_mode.py b/hermes_cli/sessions_cmd_journal_mode.pyindex 18db510b664..bb3e59457e5 100644--- a/hermes_cli/sessions_cmd_journal_mode.py+++ b/hermes_cli/sessions_cmd_journal_mode.py@@ -69,6 +69,10 @@ def cmd_set_journal_mode(args) -> int:"(https://sqlite.org/wal.html#walresetbug). Upgrade to 3.51.3+ first.")return 1holders = foreign_state_db_holders(db_path)+ if getattr(args, "force", False):+ # Same override the optimize/prune dispatcher honours, narrowed: --force waives only an incomplete+ # scan (the pid <= 0 sentinel), never a process the scan actually found.+ holders = [holder for holder in holders if holder[0] > 0]if holders:print(f"✗ Refusing to change the journal mode of {db_path}: other processes hold it open ""(a live switch would destroy their uncheckpointed commits). Stop them and re-run:")diff --git a/hermes_cli/subcommands/sessions.py b/hermes_cli/subcommands/sessions.pyindex 5cd9698fc39..d56bf4a4183 100644--- a/hermes_cli/subcommands/sessions.py+++ b/hermes_cli/subcommands/sessions.py@@ -185,7 +185,8 @@ def build_sessions_parser(subparsers, *, cmd_sessions: Callable) -> None:sessions_set_journal_mode.add_argument("--db", default=None, metavar="PATH",help="Convert another Hermes SQLite store (e.g. kanban.db) instead of the profile's state.db")_flag(sessions_set_journal_mode, "--force",- help="Deprecated compatibility flag; holder verification is mandatory on every platform")+ help="Proceed when the holder scan itself fails (cannot prove the store is quiet) after stopping every "+ "Hermes process yourself; a process the scan does find is still refused")sessions_repair_routing = sessions_subparsers.add_parser("repair-routing", help="Re-stamp gateway sessions that lost their routing identity",diff --git a/tests/hermes_cli/test_doctor_journal_modes.py b/tests/hermes_cli/test_doctor_journal_modes.pyindex a2fef61bd67..1268a34222f 100644--- a/tests/hermes_cli/test_doctor_journal_modes.py+++ b/tests/hermes_cli/test_doctor_journal_modes.py@@ -434,12 +434,13 @@ class TestConfiguredDeleteNeverApplied:monkeypatch.setattr("hermes_state_wal.resolve_journal_mode", lambda: "delete")holder = subprocess.Popen([sys.executable, "-c",- "import sqlite3, sys; c = sqlite3.connect(sys.argv[1]); c.execute('SELECT count(*) FROM t'); "- "print('ready', flush=True); sys.stdin.readline()", str(db)],+ "import os, sqlite3, sys; c = sqlite3.connect(sys.argv[1]); c.execute('SELECT count(*) FROM t'); "+ "print(f'held:{os.getpid()}', flush=True); sys.stdin.readline()", str(db)],stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True,)try:- assert holder.stdout.readline().strip() == "ready"+ marker, sqlite_pid = holder.stdout.readline().strip().split(":", 1)+ assert marker == "held" # child-reported: Popen.pid is the venv launcher on Windowsdoctor_platform._report_database_journal_modes(tmp_path, (3, 51, 3))finally:holder.stdin.write("\n")@@ -447,7 +448,7 @@ class TestConfiguredDeleteNeverApplied:holder.wait(timeout=30)out = capsys.readouterr().out- assert f"state.db is held by PID {holder.pid}" in out and "state.db" in out.split("held by PID")[1]+ assert f"state.db is held by PID {sqlite_pid}" in out and "state.db" in out.split("held by PID")[1]assert "no other process holds it" not in out and "cannot prove" not in outdef test_partial_holder_scan_is_never_an_all_clear(self, tmp_path, capsys, monkeypatch):diff --git a/tests/hermes_cli/test_sessions_set_journal_mode.py b/tests/hermes_cli/test_sessions_set_journal_mode.pyindex f21210f51ba..f578a9b1e4f 100644--- a/tests/hermes_cli/test_sessions_set_journal_mode.py+++ b/tests/hermes_cli/test_sessions_set_journal_mode.py@@ -8,7 +8,6 @@ import argparseimport sqlite3import subprocessimport sys-import timeimport pytest@@ -45,7 +44,7 @@ def test_set_journal_mode_converts_wal_store_offline(tmp_path, monkeypatch, capsassert "wal → delete" in capsys.readouterr().out[email protected]("force", [False, True], ids=["normal", "deprecated-force"])[email protected]("force", [False, True], ids=["normal", "force"])def test_set_journal_mode_refuses_while_another_process_holds_the_store(force, tmp_path, monkeypatch, capsys):@@ -69,7 +68,7 @@ def test_set_journal_mode_refuses_while_another_process_holds_the_store(marker, pid_text = holder.stdout.readline().strip().split(":", 1)assert marker == "held"sqlite_pid = int(pid_text)- # --force is compatibility syntax, never a holder-verification bypass.+ # --force never waives a process the scan actually found.assert cmd_sessions(_args("delete", force=force)) == 1finally:holder.kill()@@ -79,6 +78,12 @@ def test_set_journal_mode_refuses_while_another_process_holds_the_store(assert f"pid {sqlite_pid}" in outassert db.read_bytes()[18:20] == b"\x02\x02", "a refused switch must leave the file untouched"+ # A failed scan (pid <= 0 sentinel) is refused too, and is the ONLY thing --force waives.+ monkeypatch.setattr("hermes_state_holders.foreign_state_db_holders", lambda path: [(-1, "scan failed")])+ assert cmd_sessions(_args("delete", force=force)) == (0 if force else 1)+ assert db.read_bytes()[18:20] == (b"\x01\x01" if force else b"\x02\x02")+ assert ("scan: scan failed" in capsys.readouterr().out) is not force+@pytest.mark.parametrize("target,current,cross_vm,expected", [("delete", "wal", False, None),diff --git a/website/docs/user-guide/sessions.md b/website/docs/user-guide/sessions.mdindex 64ef5b6590c..6362ff984a4 100644--- a/website/docs/user-guide/sessions.md+++ b/website/docs/user-guide/sessions.md@@ -725,11 +725,13 @@ waiting out openers (a holder that appears mid-way makes SQLite refuse insteadof racing it), and verifies the file header reports the new mode. It remindsyou to set `database.journal_mode` to the same value when the config disagrees,because the next open re-applies the configured mode. The holder scan is local-and POSIX-only, so it cannot see a process in another container or VM sharing-the volume, and on Windows there is no scan at all — the command refuses there-outright unless you pass `--force` after stopping every Hermes process-yourself. Enabling WAL is also refused when the store sits on a cross-VM-filesystem (virtiofs/9p), where WAL shared memory corrupts silently.+(open-file tables on Linux/macOS, the Restart Manager on Windows), so it+cannot see a process in another container or VM sharing the volume. If the+scan itself fails the command refuses because it cannot prove the store is+quiet; `--force` waives only that case after you have stopped every Hermes+process yourself — a process the scan does find is always refused. Enabling+WAL is also refused when the store sits on a cross-VM filesystem (virtiofs/9p),+where WAL shared memory corrupts silently.## Importing Sessions from Claude Code and Codex CLI