The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(sessions): export guard always counts every row; export_all reuses _active_clause
kshitijk4poor41303b379e7a
diff --git a/hermes_cli/console_engine.py b/hermes_cli/console_engine.pyindex 2506ac1080c..83efad1f82f 100644--- a/hermes_cli/console_engine.py+++ b/hermes_cli/console_engine.py@@ -657,7 +657,7 @@ def _guard_exports(db, session_ids: list[str]) -> None:returntry:for session_id in session_ids:- db.assert_export_safe(session_id, max_messages=limit, include_inactive=True)+ db.assert_export_safe(session_id, max_messages=limit)except SessionExportTooLargeError as exc:raise ConsoleCommandError(f"Session '{exc.session_id}' has more than {limit:,} "diff --git a/hermes_state_portability.py b/hermes_state_portability.pyindex db5a193fd1c..e51d1d1d5f1 100644--- a/hermes_state_portability.py+++ b/hermes_state_portability.py@@ -320,7 +320,7 @@ class SessionPortabilityMixin:return [self._with_messages(session, True, include_inactive) for session in sessions]messages_by_session = {session["id"]: [] for session in sessions}session_ids = list(messages_by_session)- active_clause = "" if include_inactive else " AND active = 1"+ active_clause = self._active_clause(include_inactive, False)# Stay below SQLite's legacy 999-variable limit while replacing the per-session N+1 reads.for start in range(0, len(session_ids), 900):chunk = session_ids[start:start + 900]diff --git a/hermes_state_sessions.py b/hermes_state_sessions.pyindex 5763b78f3a2..57b42c4162a 100644--- a/hermes_state_sessions.py+++ b/hermes_state_sessions.py@@ -1401,10 +1401,9 @@ class SessionSessionsMixin:)return statuses- def assert_export_safe(self, session_id: str, max_messages: Optional[int] = None,- include_inactive: bool = False) -> int:- """Row count of this segment — live rows, or every row with ``include_inactive``, matching what- the export materializes — or raise SessionExportTooLargeError (the LIMITed subquery+ def assert_export_safe(self, session_id: str, max_messages: Optional[int] = None) -> int:+ """Row count of this segment — every row, archived included, as the transfer export materializes+ it — or raise SessionExportTooLargeError (the LIMITed subquerystops once the bound is exceeded). ``None`` resolves ``sessions.max_export_messages``; 0 disablesthe guard."""from hermes_state import SessionExportTooLargeError, resolved_max_export_messages@@ -1414,9 +1413,8 @@ class SessionSessionsMixin:raise ValueError("max_messages must be non-negative")if max_messages == 0:return 0- active_clause = "" if include_inactive else " AND active = 1"row = self._read_one(- f"SELECT COUNT(*) FROM (SELECT 1 FROM messages WHERE session_id = ?{active_clause} LIMIT ?)",+ "SELECT COUNT(*) FROM (SELECT 1 FROM messages WHERE session_id = ? LIMIT ?)",(session_id, max_messages + 1),)message_count = int(row[0] if row else 0)