The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(sessions): align prune filter derivation
fangliquanflq0a42bc7113e2
diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.pyindex 16c50dcdc47..f0a039ce5ed 100644--- a/hermes_cli/sessions_cmd.py+++ b/hermes_cli/sessions_cmd.py@@ -942,13 +942,18 @@ def cmd_sessions(args, sessions_parser=None):filters["archived"] = Falsecandidates = db.list_prune_candidates(**filters)- skipped_open = db.count_open_prune_matches(**filters)+ # Archive expands each selected row to its compression lineage, which+ # can include open continuations; a direct-open count would therefore+ # describe the eventual archive effect inaccurately.+ skipped_open = (+ db.count_open_prune_matches(**filters) if action == "prune" else 0+ )if skipped_open:suffix = "" if skipped_open == 1 else "s"print(f"Note: {skipped_open} open session{suffix} also match these "- f"filters but will be skipped because bulk {action} only "- "affects ended sessions. Use `hermes sessions delete <id>` "+ "filters but will be skipped because prune only deletes ended "+ "sessions. Use `hermes sessions delete <id>` ""to remove one explicitly.")verb = "Delete" if action == "prune" else "Archive"diff --git a/hermes_state.py b/hermes_state.pyindex 84a61fe3eee..9bd1ed63dbc 100644--- a/hermes_state.py+++ b/hermes_state.py@@ -11845,14 +11845,7 @@ class SessionDB(SessionSearchMixin, SessionSchemaMixin, SessionPortabilityMixin)``request_dump_*``) for every pruned session, outside the DBtransaction."""- if (- filters.get("last_active_before") is None- and filters.get("started_before") is None- and older_than_days is not None- ):- filters["last_active_before"] = time.time() - (- older_than_days * 86400- )+ self._apply_prune_age_filter(older_than_days, filters)where, where_params = self._prune_filter_where(source=source, **filters)removed_ids: list[str] = []diff --git a/tests/hermes_cli/test_sessions_delete.py b/tests/hermes_cli/test_sessions_delete.pyindex 538f344acd7..7650a9bbeff 100644--- a/tests/hermes_cli/test_sessions_delete.py+++ b/tests/hermes_cli/test_sessions_delete.py@@ -39,10 +39,8 @@ def test_sessions_delete_accepts_unique_id_prefix(monkeypatch, capsys):assert "Deleted session '20260315_092437_c9a6ff'." in output-def _run_prune(- monkeypatch, capsys, argv_tail, candidates=None, skipped_open=0, action="prune"-):- """Run `hermes sessions <action> <argv_tail>` against a FakeDB, capturing+def _run_prune(monkeypatch, capsys, argv_tail, candidates=None, skipped_open=0):+ """Run `hermes sessions prune <argv_tail>` against a FakeDB, capturingthe filter kwargs passed to list_prune_candidates. Auto-confirms."""import hermes_cli.main as main_modimport hermes_state@@ -83,15 +81,12 @@ def _run_prune(def prune_sessions(self, **kwargs):return len(rows)- def archive_sessions(self, **kwargs):- return len(rows)-def close(self):passmonkeypatch.setattr(hermes_state, "SessionDB", lambda: FakeDB())monkeypatch.setattr(- sys, "argv", ["hermes", "sessions", action, *argv_tail]+ sys, "argv", ["hermes", "sessions", "prune", *argv_tail])monkeypatch.setattr("builtins.input", lambda _prompt="": "y")main_mod.main()@@ -129,21 +124,6 @@ def test_sessions_prune_surfaces_matching_open_sessions(monkeypatch, capsys):)assert "2 open sessions also match these filters" in out- assert "bulk prune only affects ended sessions" in out+ assert "prune only deletes ended sessions" in outassert "hermes sessions delete <id>" in outassert "No sessions match" in out---def test_sessions_archive_surfaces_matching_open_sessions(monkeypatch, capsys):- _filters, out = _run_prune(- monkeypatch,- capsys,- ["--source", "cron"],- candidates=[],- skipped_open=1,- action="archive",- )-- assert "1 open session also match these filters" in out- assert "bulk archive only affects ended sessions" in out- assert "No sessions match" in out