The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): startup schema reconcile opens state.db read-only first
Tekniumc9b71ebaf75f
diff --git a/hermes_cli/web_server_lifecycle.py b/hermes_cli/web_server_lifecycle.pyindex dc7bcc0f7d1..456b005a21b 100644--- a/hermes_cli/web_server_lifecycle.py+++ b/hermes_cli/web_server_lifecycle.py@@ -171,18 +171,23 @@ def _resolve_restart_drain_timeout() -> float:def _eager_reconcile_own_session_db() -> None:- """One writable open of this process's own state.db at startup.-- ``SessionDB.__init__`` runs ``_init_schema`` → ``_reconcile_columns`` with- open-time lock patience. Never raises: an unfixable store still gets the- per-poll read-probe heal in :func:`_open_session_db_at_path`.+ """Bring this process's own state.db schema current at startup — read-only first.++ The dashboard is a view layer; the gateway owns the writer. A healthy store+ must never see a second writable ``SessionDB`` from this process (its+ close-time checkpoint and a possible FTS rebuild in ``_init_fts`` are the+ two-writer corruption vector, #107688 / #100896). The read-only path still+ bootstraps a missing store and heals a stale/malformed schema through ONE+ writable open, so the #79531 contract holds. Never raises: an unfixable+ store still gets the per-poll read-probe heal."""try:from hermes_state import _default_db_path- from hermes_state_registry import acquire, release_or_close- db = acquire(Path(_default_db_path()))- release_or_close(db)+ from hermes_cli.web_server_sessions import _open_session_db_at_path++ db = _open_session_db_at_path(Path(_default_db_path()), read_only=True)+ db.close()except Exception as exc:_log.warning("startup schema reconcile of state.db failed (%s); session "diff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.pyindex 72242e27b15..cabcd6aeb4c 100644--- a/tests/hermes_cli/test_web_server.py+++ b/tests/hermes_cli/test_web_server.py@@ -566,6 +566,32 @@ class TestWebServerEndpoints:db.close()assert [r["id"] for r in rows] == ["eager-stale"]+ def test_startup_eager_reconcile_is_read_only_on_a_healthy_store(self, monkeypatch):+ """A current-schema store gets NO writable open from the dashboard (#107688).++ The gateway owns the writer; a second writable SessionDB from the+ dashboard (close-time checkpoint, possible FTS rebuild) is the+ two-writer corruption vector. Only the stale-schema heal may write.+ """+ import hermes_state+ from hermes_constants import get_hermes_home+ from hermes_state import SessionDB++ SessionDB(db_path=get_hermes_home() / "state.db").close()++ writable_opens = []+ real_init = SessionDB.__init__++ def spy(self, *args, **kwargs):+ if not kwargs.get("read_only"):+ writable_opens.append(kwargs)+ return real_init(self, *args, **kwargs)++ monkeypatch.setattr(hermes_state.SessionDB, "__init__", spy)+ _web_server_lifecycle._eager_reconcile_own_session_db()++ assert writable_opens == []+def test_startup_eager_reconcile_never_raises(self, monkeypatch):"""A store the eager reconcile cannot open must not break startup."""import sqlite3 as sqlite3_module