The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): latch one-time state.db repairs on refusal and warn once
teknium1192be92f1cd1
diff --git a/cli.py b/cli.pyindex 19d2c4c29fd..bddb0631516 100644--- a/cli.py+++ b/cli.py@@ -1089,14 +1089,18 @@ def _run_state_db_auto_maintenance(session_db) -> None:"Finalized %d orphaned compression sessions", "Orphan compression finalize skipped: %s",),):+ if session_db.get_meta(meta_key):+ continuetry:- if not session_db.get_meta(meta_key):- count = repair()- session_db.set_meta(meta_key, "1")- if count:- logger.info(done_msg, count)+ count = repair()except Exception as _exc:- logger.debug(skip_msg, _exc)+ # Latched below regardless: a repair this store refuses (live ledger work,+ # locked file) must surface once, not retry silently on every start.+ logger.warning(skip_msg, _exc)+ count = 0+ session_db.set_meta(meta_key, "1")+ if count:+ logger.info(done_msg, count)cfg = (_load_full_config().get("sessions") or {})diff --git a/tests/state/test_ledger_delete_consistency.py b/tests/state/test_ledger_delete_consistency.pyindex b8f795d8624..f1606064378 100644--- a/tests/state/test_ledger_delete_consistency.py+++ b/tests/state/test_ledger_delete_consistency.py@@ -3,9 +3,11 @@ with the ``session_admissions`` / ``worker_executions`` ledger (ON DELETE RESTRIReported by @GodsBoy and @ahrazzle on #106742; fix shape by @dialapus."""+import loggingimport timefrom contextlib import closingfrom dataclasses import asdict+from unittest.mock import MagicMockimport pytest@@ -92,6 +94,29 @@ def test_sweeps_skip_sessions_with_live_work_and_retire_the_rest(tmp_path):assert not c.execute('PRAGMA foreign_key_check').fetchall()+def test_startup_repair_latches_after_a_refusal_and_warns_once(monkeypatch, caplog, tmp_path):+ import cli+ import hermes_cli.config+ import hermes_constants++ monkeypatch.setattr(hermes_cli.config, 'load_config', lambda: {'sessions': {'auto_prune': False}})+ monkeypatch.setattr(hermes_constants, 'get_hermes_home', lambda: tmp_path)+ meta = {}+ session_db = MagicMock()+ session_db.get_meta.side_effect = meta.get+ session_db.set_meta.side_effect = meta.__setitem__+ session_db.prune_empty_ghost_sessions.side_effect = rt.RuntimeStoreError('session_busy')+ session_db.finalize_orphaned_compression_sessions.return_value = 0++ with caplog.at_level(logging.DEBUG, logger='cli'):+ cli._run_state_db_auto_maintenance(session_db)+ cli._run_state_db_auto_maintenance(session_db)+ refusals = [r for r in caplog.records if 'Ghost session prune skipped' in r.getMessage()]+ assert [r.levelno for r in refusals] == [logging.WARNING], 'refusal logged once, at warning'+ assert session_db.prune_empty_ghost_sessions.call_count == 1, 'latched after the refusal'+ assert meta.get('ghost_session_prune_v1')++def test_local_reset_refuses_over_started_admission_then_fences_generation(tmp_path):from hermes_state_local import commit_local_sessionfrom hermes_state_local_lineage import reset_local_target