Skip to content

The agent that grows with you

refactor(sessions): carry the export refusal text on SessionExportTooLargeError

kshitijk4poorf64c68a60ddd
diff --git a/hermes_cli/console_engine.py b/hermes_cli/console_engine.py
index fe5431b43b0..86aac1bb50b 100644
--- a/hermes_cli/console_engine.py
+++ b/hermes_cli/console_engine.py
@@ -651,11 +651,11 @@ def _config_migrate(_engine: HermesConsoleEngine, args: list[str]) -> None:
def _guard_exports(db, session_ids: list[str]) -> None:
"""Per-session export budget: only an individual runaway transcript trips it; 0 disables."""
- from hermes_state import SessionExportTooLargeError, export_too_large_message
+ from hermes_state import SessionExportTooLargeError
try:
db.assert_exports_safe(session_ids)
except SessionExportTooLargeError as exc:
- raise ConsoleCommandError(export_too_large_message(exc)) from exc
+ raise ConsoleCommandError(str(exc)) from exc
@_captured
diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.py
index d5efc4160f7..8c11ddd68f3 100644
--- a/hermes_cli/sessions_cmd.py
+++ b/hermes_cli/sessions_cmd.py
@@ -349,7 +349,7 @@ def _cmd_export(db, args):
"""The transfer projection holds every stored row in memory: the console export's per-session
``sessions.max_export_messages`` guard (0 disables) runs before any is loaded. ``None`` = the
sessions a bare export loads."""
- from hermes_state import SessionExportTooLargeError, export_too_large_message, resolved_max_export_messages
+ from hermes_state import SessionExportTooLargeError, resolved_max_export_messages
if shown:
return False
limit = resolved_max_export_messages()
@@ -360,7 +360,7 @@ def _cmd_export(db, args):
try:
db.assert_exports_safe(session_ids, max_messages=limit)
except SessionExportTooLargeError as exc:
- print(f"Error: {export_too_large_message(exc)}")
+ print(f"Error: {exc}")
return True
return False
diff --git a/hermes_state.py b/hermes_state.py
index affa023a8ac..858e6675007 100644
--- a/hermes_state.py
+++ b/hermes_state.py
@@ -116,7 +116,7 @@ class SessionResumeTooLargeError(ValueError):
super().__init__(
f"This session is too long to reload safely ({message_count} messages; limit {limit}). "
"Start a fresh chat and keep a copy with the dashboard Sessions page's Export action or "
- "`hermes sessions export --format md` (neither is capped), or raise the limit "
+ "`hermes sessions export --format md --session-id <id>` (neither is capped), or raise the limit "
"with `hermes config set sessions.max_resume_messages 0`."
)
@@ -124,21 +124,14 @@ class SessionResumeTooLargeError(ValueError):
class SessionExportTooLargeError(ValueError):
def __init__(self, session_id: str, message_count: int, limit: int = _MAX_SAFE_MESSAGES):
self.session_id, self.message_count, self.limit = session_id, message_count, limit
+ # User-facing refusal shared by every in-memory JSON/JSONL export (CLI and console).
super().__init__(
- f"session '{session_id}' has at least {message_count} active messages; "
- f"safe in-memory export limit is {limit}"
+ f"Session '{session_id}' has more than {limit:,} exportable messages; the JSON/JSONL "
+ "backup is built in memory and capped per session. Use the dashboard Sessions page's streaming "
+ "Export action, or set sessions.max_export_messages: 0 in config.yaml to disable the guard."
)
-def export_too_large_message(exc: SessionExportTooLargeError) -> str:
- """User-facing refusal shared by every in-memory JSON/JSONL export (CLI and console)."""
- return (
- f"Session '{exc.session_id}' has more than {exc.limit:,} exportable messages; the JSON/JSONL "
- "backup is built in memory and capped per session. Use the dashboard Sessions page's streaming "
- "Export action, or set sessions.max_export_messages: 0 in config.yaml to disable the guard."
- )
-
-
def _compression_lock_holder_process_is_dead(holder: str) -> bool:
"""True only when a ``pid=<n>`` lock holder's local PID is provably gone.
Reclaim on kernel proof only: unstructured/same-process holders (another