The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): the session store's read-only reader opens once the gateway made state.db
Teknium705e6b26bb2f
diff --git a/hermes_cli/gateway_session_store.py b/hermes_cli/gateway_session_store.pyindex 15ef74155e8..085afd450dd 100644--- a/hermes_cli/gateway_session_store.py+++ b/hermes_cli/gateway_session_store.py@@ -61,21 +61,24 @@ class GatewaySessionStore:self.snapshots: dict[str, dict] = {}self.current: dict | None = Noneself._reader = None- self._reader_failed = Falsedef __bool__(self):return not self.connection.closed# -- reads -----------------------------------------------------------------------------def _db(self):- if self._reader is None and not self._reader_failed:+ """The read-only reader, opened on first use. No state.db yet (the gateway creates it on its+ first start, after the CLI's startup maintenance probe) is retried on the next read."""+ if self._reader is None:+ from hermes_constants import get_hermes_home+ path = get_hermes_home() / "state.db"+ if not path.exists():+ return Nonetry:- from hermes_constants import get_hermes_homefrom hermes_state import SessionDB- self._reader = SessionDB(db_path=get_hermes_home() / "state.db", read_only=True)- except Exception as exc: # no state.db yet (the gateway creates it): reads find nothing+ self._reader = SessionDB(db_path=path, read_only=True)+ except Exception as exc: # reads find nothing; retried on the next readlogger.debug("read-only state.db unavailable: %s", exc)- self._reader_failed = Truereturn self._readerdef __getattr__(self, name):diff --git a/tests/hermes_cli/test_gateway_session_store.py b/tests/hermes_cli/test_gateway_session_store.pyindex d906dcaba8d..49c1f991404 100644--- a/tests/hermes_cli/test_gateway_session_store.py+++ b/tests/hermes_cli/test_gateway_session_store.py@@ -116,3 +116,13 @@ def test_store_is_falsy_once_the_gateway_connection_closed(store):assert dbdb.connection.close()assert not db+++def test_reader_opens_once_the_gateway_created_state_db(store, tmp_path, monkeypatch):+ """The startup maintenance probe runs before the gateway exists; that miss is not latched."""+ db, _ = store+ monkeypatch.setattr("hermes_constants.get_hermes_home", lambda: tmp_path)+ assert db.get_session("x") is None and db._reader is None+ from hermes_state import SessionDB+ SessionDB(db_path=tmp_path / "state.db").close()+ assert db.get_session("x") is None and db._reader is not None