Skip to content

The agent that grows with you

fix: name the allowed retention_days range when skipping auto-maintenance

teknium177737667785d
diff --git a/hermes_state_maintenance.py b/hermes_state_maintenance.py
index bb1815d9e54..7e393c4f958 100644
--- a/hermes_state_maintenance.py
+++ b/hermes_state_maintenance.py
@@ -389,8 +389,10 @@ class SessionMaintenanceMixin:
if retention_days is None or retention_days < 0:
# A negative retention would build a future cutoff and match every ended
# session; auto_prune=false is the disable switch, not a negative bound.
- logger.warning("state.db auto-maintenance skipped: retention_days=%r is invalid",
- retention_days)
+ logger.warning(
+ "state.db auto-maintenance skipped: sessions.retention_days=%r is outside the allowed "
+ "range (a whole number of days >= 0); set sessions.auto_prune: false to disable pruning",
+ retention_days)
result["skipped"] = True
return result
maintenance_lock = _try_acquire_auto_maintenance_lock(self.db_path)
diff --git a/tests/hermes_state/test_hermes_state.py b/tests/hermes_state/test_hermes_state.py
index 3b68e5ab3c9..87ec4b940bb 100644
--- a/tests/hermes_state/test_hermes_state.py
+++ b/tests/hermes_state/test_hermes_state.py
@@ -1382,33 +1382,21 @@ class TestPruneSessions:
older_than_days=90, source="cron", archived=False
)} == {"ended"}
- def test_negative_older_than_days_rejected(self, db):
- """A negative bound builds a FUTURE cutoff, matching every ended session —
- it must raise instead of mass-deleting (config-fed via sessions.retention_days)."""
+ def test_negative_older_than_days_rejected_at_every_prune_boundary(self, db):
+ """A negative bound builds a FUTURE cutoff that matches every ended session (and every
+ never-active keyed row) — the SessionDB API must raise, naming the allowed range, instead
+ of mass-deleting; ``sessions.retention_days: -1`` reaches these paths from config (#116361)."""
db.create_session(session_id="ended", source="cli")
db.end_session("ended", "done")
- with pytest.raises(ValueError, match="older_than_days"):
- db.prune_sessions(older_than_days=-1)
- with pytest.raises(ValueError, match="older_than_days"):
- db.list_prune_candidates(older_than_days=-1)
- with pytest.raises(ValueError, match="older_than_days"):
- db.count_prune_matches(older_than_days=-1)
+ db.create_session(session_id="keyed", source="telegram", session_key="telegram:dm:1")
+ for call in (db.prune_sessions, db.list_prune_candidates, db.count_prune_matches,
+ db.list_never_active_keyed_sessions, db.prune_never_active_keyed_sessions):
+ with pytest.raises(ValueError, match=">= 0"):
+ call(older_than_days=-1)
assert db.get_session("ended") is not None
-
- def test_negative_never_active_keyed_rejected(self, db):
- """list_never_active_keyed_sessions shares the same future-cutoff hazard."""
- db.create_session(session_id="keyed", source="telegram",
- session_key="telegram:dm:1")
- with pytest.raises(ValueError, match="older_than_days"):
- db.list_never_active_keyed_sessions(older_than_days=-1)
- with pytest.raises(ValueError, match="older_than_days"):
- db.prune_never_active_keyed_sessions(older_than_days=-1)
assert db.get_session("keyed") is not None
-
-
-
class TestPruneSessionFilters:
"""Extended filter surface shared by prune/archive/list_prune_candidates."""
@@ -3926,23 +3914,6 @@ class TestAutoMaintenance:
assert second["pruned"] == 0
assert db.get_session("old2") is not None # untouched
- def test_negative_retention_days_skips_maintenance(self, db):
- """sessions.retention_days: -1 in config reaches here via cli.py/gateway:
- a future cutoff would match every ended session, so maintenance must
- warn and skip, not delete."""
- self._make_old_ended(db, "old", days_old=100)
- result = db.maybe_auto_prune_and_vacuum(
- retention_days=-1, min_interval_hours=0
- )
- assert result["skipped"] is True
- assert result["pruned"] == 0
- assert db.get_session("old") is not None
-
-
-
-
-
-
def test_auto_prune_deletes_transcript_files(self, db, tmp_path):
"""Issue #3015: auto-prune must also delete on-disk transcript files."""
sessions_dir = tmp_path / "sessions"
diff --git a/website/docs/user-guide/sessions.md b/website/docs/user-guide/sessions.md
index d199aaf7a2b..d610465b7d4 100644
--- a/website/docs/user-guide/sessions.md
+++ b/website/docs/user-guide/sessions.md
@@ -968,6 +968,7 @@ Key tables in `state.db`:
- Gateway conversations persist across inactivity; use `/new` or `/reset` for an explicit boundary
- Before reset, the agent saves memories and skills from the expiring session
- Auto-pruning (**on by default** since #54189): when `sessions.auto_prune` is `true`, ended sessions inactive for `sessions.retention_days` (default 90) are pruned at CLI/gateway/cron startup
+- `sessions.retention_days` must be a whole number of days `>= 0`. A negative value (or a missing one) is rejected: startup maintenance logs a warning naming the allowed range and skips the sweep instead of treating the future cutoff as "everything" — `sessions.auto_prune: false` is the switch that disables pruning
- After a prune that actually removed rows, `state.db` is `VACUUM`ed to reclaim disk space only when **both** gates pass: at least `sessions.min_vacuum_interval_days` (default 30) have elapsed since the last successful `VACUUM`, **and** more than 25% of the file's pages are reclaimable (`PRAGMA freelist_count / page_count`). A dense database never pays for a full rewrite to reclaim a few MB (SQLite does not shrink the file on plain DELETE)
- Pruning runs at most once per `sessions.min_interval_hours` (default 24); the last-run timestamp is tracked inside `state.db` itself so it's shared across every Hermes process in the same `HERMES_HOME`