The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(sessions): the pinned-skip note counts only rows that carry the pin
kshitijk4poor1aa83650177d
diff --git a/hermes_cli/sessions_cmd.py b/hermes_cli/sessions_cmd.pyindex f275bc33b00..5a3a1d95a6a 100644--- a/hermes_cli/sessions_cmd.py+++ b/hermes_cli/sessions_cmd.py@@ -652,10 +652,9 @@ def _note_pinned_skipped(db, filters, action):"""Tell the user how many pinned rows bulk prune/archive spared (pin = durable keep; only`prune --include-pinned` opts in, archive always spares them)."""_base = {k: v for k, v in filters.items() if k != "include_pinned"}- # Count matching pinned rows only: whole-lineage selection would also drop the unpinned- # ancestors a pinned tip spares, and report them as pinned.- with_pinned, without = (int(db.count_prune_matches(**_base, include_pinned=flag)) for flag in (True, False))- skipped = max(with_pinned - without, 0)+ # Count matching pinned rows only: neither the unpinned ancestors a pinned tip spares nor the+ # unpinned continuations a pinned segment protects carry the pin.+ skipped = int(db.count_prune_matches(**_base, include_pinned=True, pinned_only=True))if not skipped:returnsuffix = "" if skipped == 1 else "s"diff --git a/hermes_state_maintenance.py b/hermes_state_maintenance.pyindex 740cde5c9fb..2092e3012b5 100644--- a/hermes_state_maintenance.py+++ b/hermes_state_maintenance.py@@ -268,10 +268,13 @@ class SessionMaintenanceMixin:FROM sessions s WHERE {where}ORDER BY last_active ASC, s.started_at ASC""", params)]- def count_prune_matches(self, older_than_days: Optional[float] = None, source: str = None,- **filters) -> int:- """Count-only :meth:`list_prune_candidates` (CLI reports spared pinned sessions)."""+ def count_prune_matches(self, older_than_days: Optional[float] = None, source: str = None, *,+ pinned_only: bool = False, **filters) -> int:+ """Count-only :meth:`list_prune_candidates`; ``pinned_only`` counts rows carrying the pin+ itself, not the continuations it protects (CLI reports spared pinned sessions)."""where, params = self._prune_where(older_than_days, source, filters)+ if pinned_only:+ where += " AND COALESCE(s.pinned, 0) = 1"return int(self._read_one(f"SELECT COUNT(*) FROM sessions s WHERE {where}", params)[0])def count_open_prune_matches(self, older_than_days: Optional[float] = None, source: str = None,diff --git a/tests/hermes_state/test_pinned_lineage.py b/tests/hermes_state/test_pinned_lineage.pyindex a086a492305..078c9c48fae 100644--- a/tests/hermes_state/test_pinned_lineage.py+++ b/tests/hermes_state/test_pinned_lineage.py@@ -2,6 +2,7 @@import timefrom contextlib import closing+from hermes_cli.sessions_cmd import _note_pinned_skippedfrom hermes_state import SessionDB@@ -20,7 +21,7 @@ def _pinned_then_rotated(db):db._conn.commit()-def test_a_pin_follows_the_chat_through_compression_and_bulk_cleanup_spares_it(tmp_path):+def test_a_pin_follows_the_chat_through_compression_and_bulk_cleanup_spares_it(tmp_path, capsys):"""The published segment joins the pin. Stores written before it did hold a pinned segmentwith an unpinned tip, and bulk cleanup spares those too."""with closing(SessionDB(tmp_path / "state.db")) as db:@@ -31,6 +32,8 @@ def test_a_pin_follows_the_chat_through_compression_and_bulk_cleanup_spares_it(tdb._conn.commit()assert db.list_prune_candidates(older_than_days=90, whole_lineages=True) == []+ _note_pinned_skipped(db, {"older_than_days": 90}, "prune")+ assert "Note: 1 pinned session also match" in capsys.readouterr().outassert db.prune_sessions(older_than_days=90) == 0assert db.archive_stale_sessions(3) == db.archive_sessions(older_than_days=90) == 0assert db.get_compression_lineage("keep") == ["keep", "keep-2"]