Skip to content

The agent that grows with you

fix(web): zero-writer dashboard reports corrupt stores as state_db_corrupt; owner heals schema

Teknium860da54e6c94
diff --git a/hermes_cli/web_routers/_common.py b/hermes_cli/web_routers/_common.py
index a93974894de..b969bf8724a 100644
--- a/hermes_cli/web_routers/_common.py
+++ b/hermes_cli/web_routers/_common.py
@@ -93,6 +93,20 @@ CORRUPT_STORE_DETAIL = {
}
+def corrupt_store_status(db_path, exc) -> HTTPException:
+ """The structured ``state_db_corrupt`` 503 for a malformed store, warning once per store per
+ :data:`_CORRUPT_STORE_WARN_INTERVAL_S` (debug afterwards). Callers ``raise ... from exc``."""
+ key, now = str(db_path), time.monotonic()
+ last = _corrupt_store_warned_at.get(key)
+ if last is None or now - last >= _CORRUPT_STORE_WARN_INTERVAL_S:
+ _corrupt_store_warned_at[key] = now
+ log.warning("state.db at %s is corrupt (%s); dashboard reads return a status payload until it is "
+ "repaired — run `hermes doctor`", db_path, exc)
+ else:
+ log.debug("state.db at %s still corrupt: %s", db_path, exc)
+ return HTTPException(status_code=503, detail={**CORRUPT_STORE_DETAIL, "path": key})
+
+
@contextlib.contextmanager
def corrupt_store_as_status(db_path):
"""Map a corrupt-image ``sqlite3.DatabaseError`` from a state.db read to a 503 status
@@ -105,12 +119,4 @@ def corrupt_store_as_status(db_path):
except sqlite3.DatabaseError as exc:
if not is_malformed_db_error(exc):
raise
- key, now = str(db_path), time.monotonic()
- last = _corrupt_store_warned_at.get(key)
- if last is None or now - last >= _CORRUPT_STORE_WARN_INTERVAL_S:
- _corrupt_store_warned_at[key] = now
- log.warning("state.db at %s is corrupt (%s); dashboard reads return a status payload until it is "
- "repaired — run `hermes doctor`", db_path, exc)
- else:
- log.debug("state.db at %s still corrupt: %s", db_path, exc)
- raise HTTPException(status_code=503, detail={**CORRUPT_STORE_DETAIL, "path": key}) from exc
+ raise corrupt_store_status(db_path, exc) from exc
diff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.py
index 7bdd3dacb3d..6fef440a9bf 100644
--- a/tests/hermes_cli/test_web_server.py
+++ b/tests/hermes_cli/test_web_server.py
@@ -542,14 +542,14 @@ class TestWebServerEndpoints:
assert payload["recents"]["sessions"] == []
def test_startup_eager_reconcile_heals_stale_store(self):
- """The lifespan's eager reconcile brings a stale store current.
+ """The OWNER's startup open brings a stale store current; the dashboard only reads.
#79531/#80037: after `hermes update` an old-schema state.db used to
stay stale until the first NEW session forced a writable open —
every /api/sessions poll 500ed with "no such column" in between.
- The lifespan now schedules one writable open at startup; this
- exercises that worker directly against a store missing
- sessions.last_read_at and asserts the schema is brought current.
+ Under the unified runtime the dashboard is a zero-writer view: its
+ eager probe must NOT heal (#107688 two-writer vector), and the
+ gateway owner's writable acquisition is what reconciles the schema.
"""
import sqlite3
@@ -571,7 +571,21 @@ class TestWebServerEndpoints:
finally:
legacy.close()
+ # Dashboard probe: read-only, never heals (no writable open from a viewer).
_web_server_lifecycle._eager_reconcile_own_session_db()
+ stale = sqlite3.connect(str(db_path))
+ try:
+ assert "last_read_at" not in {row[1] for row in stale.execute("PRAGMA table_info(sessions)")}
+ finally:
+ stale.close()
+
+ # Owner path: the gateway's writable acquisition reconciles the schema at startup.
+ from hermes_state_registry import acquire, release_or_close
+ owner = acquire(db_path)
+ try:
+ pass
+ finally:
+ release_or_close(owner)
healed = sqlite3.connect(str(db_path))
try: