Skip to content

The agent that grows with you

fix: keep ACP session catalog read-only

Tekniumb117521cbd6f
diff --git a/acp_adapter/session.py b/acp_adapter/session.py
index 293a4417402..a6bd31c6d91 100644
--- a/acp_adapter/session.py
+++ b/acp_adapter/session.py
@@ -193,13 +193,7 @@ class SessionManager:
def list_sessions(self, cwd: str | None = None) -> List[Dict[str, Any]]:
"""Return lightweight info dicts for all sessions (memory + database)."""
normalized_cwd = _normalize_cwd_for_compare(cwd) if cwd else None
- db = self._get_db()
- persisted_rows: dict[str, dict[str, Any]] = {}
- try:
- for row in (db.list_sessions_rich(source="acp", limit=1000) if db is not None else ()):
- persisted_rows[str(row["id"])] = dict(row)
- except Exception:
- logger.debug("Failed to load ACP sessions from DB", exc_info=True)
+ persisted_rows = self._catalog_rows()
def _matches(session_cwd: str) -> bool:
return not normalized_cwd or _normalize_cwd_for_compare(session_cwd) == normalized_cwd
@@ -232,6 +226,18 @@ class SessionManager:
results.sort(key=lambda item: _updated_at_sort_key(item.get("updated_at")), reverse=True)
return results
+ def _catalog_rows(self) -> dict[str, dict[str, Any]]:
+ from hermes_state import SessionDB
+ from pathlib import Path
+
+ path = Path(self._db_instance.db_path) if self._db_instance is not None else get_hermes_home() / "state.db"
+ if not path.exists():
+ return {}
+ # A separate read-only connection must not initialize schemas, switch
+ # journal mode, or start a token writer merely to render the editor picker.
+ with SessionDB(db_path=path, read_only=True) as db:
+ return {str(row["id"]): dict(row) for row in db.list_sessions_rich(source="acp", limit=1000)}
+
def update_cwd(self, session_id: str, cwd: str) -> Optional[SessionState]:
"""Update the working directory for a session and its tool overrides."""
cwd = _translate_acp_cwd(cwd)
diff --git a/tests/acp/test_catalog_read_only.py b/tests/acp/test_catalog_read_only.py
new file mode 100644
index 00000000000..4d4ea41b429
--- /dev/null
+++ b/tests/acp/test_catalog_read_only.py
@@ -0,0 +1,29 @@
+"""Browsing ACP history is not an execution/storage owner."""
+import sqlite3
+
+from acp_adapter.session import SessionManager
+from hermes_state import SessionDB
+
+
+def test_empty_catalog_does_not_initialize_storage(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ manager = SessionManager()
+ assert manager.list_sessions() == []
+ assert not (tmp_path / "state.db").exists()
+ assert manager._db_instance is None
+
+
+def test_catalog_reads_committed_history_without_schema_writes(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ path = tmp_path / "state.db"
+ with SessionDB(path) as db:
+ db.create_session(session_id="catalog", source="acp", model="fixture", model_config={"cwd": str(tmp_path)})
+ db.append_message("catalog", "user", "catalog input")
+ with sqlite3.connect(path) as conn:
+ conn.execute("PRAGMA journal_mode=DELETE")
+ before = path.read_bytes()
+ manager = SessionManager()
+ rows = manager.list_sessions(cwd=str(tmp_path))
+ assert [row["session_id"] for row in rows] == ["catalog"]
+ assert path.read_bytes() == before
+ assert manager._db_instance is None