fix(sessions): auto-prune state.db by default (90d) and gate VACUUM on freelist ratio (#54189)

Flip the state.db retention defaults per Teknium's decision on #54189:

- sessions.auto_prune: false -> true. A stock install now prunes ENDED
  sessions inactive for retention_days at CLI/gateway/cron startup
  (at most once per min_interval_hours). Open, pinned and mid-turn
  sessions are never deleted; the only open rows touched are stale
  automation sessions (#100903 sweep), which are closed, not deleted,
  and aged a further full window before removal.
- sessions.retention_days stays 90 (already the default; verified).
- Auto-VACUUM is now additionally gated on the reclaimable fraction of
  the file: PRAGMA freelist_count / page_count must exceed 25%
  (AUTO_VACUUM_MIN_FREELIST_RATIO) on top of the existing
  min_vacuum_interval_days throttle. Pruning a few small sessions on a
  dense multi-GB DB no longer rewrites the whole file to reclaim a few MB.
  Unknown ratio (pragma read failure) falls back to the time throttle.

Existing installs that explicitly set any sessions.* key keep their
values (load_config deep-merges DEFAULT_CONFIG under user YAML); only
unset keys pick up the new defaults. No _config_version bump needed.
cli-config.yaml.example documents the section commented-out so
installers that copy it verbatim never pin these as explicit settings.

Tests: ratio gate (below/above/at-threshold/unknown/override), real-DB
freelist ratio, default assertions, fresh-config startup hook reaches
the prune call, explicit opt-out respected, template-does-not-pin-keys.
This commit is contained in:
Teknium
2026-09-02 05:57:47 -07:00
parent 8e4366d358
commit 73f68362b3
6 changed files with 329 additions and 31 deletions

View File

@@ -948,6 +948,32 @@ max_concurrent_sessions: null
# explicitly want one shared "room brain" per group/channel.
group_sessions_per_user: true
# =============================================================================
# Session Storage Retention (state.db)
# =============================================================================
# ~/.hermes/state.db keeps every session, message, and tool call, plus the
# FTS5 search indexes. Since #54189, auto-pruning is ON by default so the file
# stays bounded: at CLI/gateway/cron startup (at most once per
# min_interval_hours) Hermes deletes ENDED sessions whose last activity is
# older than retention_days. Open, pinned, and in-progress sessions are never
# deleted. Stale automation sessions (cron/kanban/subagent/one-shot CLI) whose
# process died without closing them are first *closed*, then aged through a
# further full retention window before removal.
#
# After a prune that removed rows, VACUUM reclaims disk space only when both
# the time throttle (min_vacuum_interval_days) has elapsed AND more than 25%
# of the file's pages are reclaimable — a dense database never pays for a full
# rewrite to reclaim a few MB.
#
# Uncomment to change the defaults shown; set auto_prune: false to keep every
# ended session forever (the pre-#54189 behavior).
# sessions:
# auto_prune: true
# retention_days: 90
# vacuum_after_prune: true
# min_vacuum_interval_days: 30
# min_interval_hours: 24
# Optional direct endpoint for autonomous Bot Mode rooms spanning gateways.
# Leave unset for the safe default: Desktop coordinates cross-gateway rooms and
# same-gateway rooms can still continue on their own. Set this only to the