The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(state): reset forks leave the Python lineage walk too; /resume ranks lineages by activity
teknium109cf1b926f31
diff --git a/gateway/slash_commands_session.py b/gateway/slash_commands_session.pyindex ddbe7b2fba8..664e9af231b 100644--- a/gateway/slash_commands_session.py+++ b/gateway/slash_commands_session.py@@ -801,9 +801,11 @@ class GatewaySessionCommandsMixin:async def _list_titled_sessions(self, source, session_key: str, allow_all: bool) -> list[dict]:"""Titled sessions visible to the caller (origin-scoped unless admin ``--all``)."""widen = allow_all and self._resume_caller_is_admin(source)+ # Rank by lineage activity, not root started_at: a lineage compressed for days is projected+ # onto its live tip and must sit where the user last touched it (#114271).sessions = await self._session_db.list_sessions_rich(source=source.platform.value if source.platform else None,- session_key=None if widen else session_key, limit=10)+ session_key=None if widen else session_key, limit=10, order_by_last_active=True)titled = [s for s in sessions if s.get("title")][:10]return [s for s in titled if await self._resume_row_visible(source, s, allow_all)]diff --git a/hermes_state_compression.py b/hermes_state_compression.pyindex 4e1039ec0ff..41dae78f9c3 100644--- a/hermes_state_compression.py+++ b/hermes_state_compression.py@@ -503,7 +503,7 @@ class SessionCompressionMixin:seen = {session_id}while current:parent_id = current.get("parent_session_id")- if not parent_id or parent_id in seen or self._is_explicit_fork_child_row(current):+ if not parent_id or parent_id in seen or self._is_explicit_fork_child_row(current, include_reset=True):breakparent = _row(parent_id)if not parent or parent.get("end_reason") != "compression":@@ -678,7 +678,8 @@ class SessionCompressionMixin:def _is_compression_child_row(self, child: Dict[str, Any]) -> bool:parent_id = child.get("parent_session_id")- if not parent_id or self._is_explicit_fork_child_row(child):+ # A reset fork of a compression-ended parent is its own conversation, not the continuation (#114271).+ if not parent_id or self._is_explicit_fork_child_row(child, include_reset=True):return Falseparent = self.get_session(parent_id)return bool(parent and parent.get("end_reason") == "compression")diff --git a/hermes_state_messages.py b/hermes_state_messages.pyindex d19b819a6fb..38d9a6bcbbe 100644--- a/hermes_state_messages.py+++ b/hermes_state_messages.py@@ -1294,10 +1294,11 @@ class SessionMessagesMixin:"SELECT 1 FROM messages WHERE session_id = ? AND platform_message_id = ? LIMIT 1",(session_id, platform_message_id)) is not None- def _is_explicit_fork_child_row(self, session: Dict[str, Any]) -> bool:- """True when *session* is a branch, delegate, or tool child of its parent. Markers only count when they- point at ``parent_session_id``: compression copies ``model_config`` onto the continuation, so- presence-only matching would misclassify it (same binding as ``_NON_CONTINUATION_CHILD_FILTER_SQL``)."""+ def _is_explicit_fork_child_row(self, session: Dict[str, Any], *, include_reset: bool = False) -> bool:+ """True when *session* is a branch, delegate, or tool child of its parent (``include_reset``: also a+ reset fork). Markers only count when they point at ``parent_session_id``: compression copies+ ``model_config`` onto the continuation, so presence-only matching would misclassify it (same binding+ as ``_NON_CONTINUATION_CHILD_FILTER_SQL``)."""if session.get("source") == "tool":return Truecfg = session.get("model_config")@@ -1309,6 +1310,8 @@ class SessionMessagesMixin:if not isinstance(cfg, dict):return Falsemarkers = (cfg.get("_branched_from"), cfg.get("_delegate_from"))+ if include_reset:+ markers += (cfg.get("_reset_from"),)parent_id = session.get("parent_session_id")return parent_id in markers if parent_id else any(m is not None for m in markers)diff --git a/tests/gateway/test_resume_command.py b/tests/gateway/test_resume_command.pyindex e1bf10ebb2a..a627e9525ac 100644--- a/tests/gateway/test_resume_command.py+++ b/tests/gateway/test_resume_command.py@@ -4,6 +4,7 @@ Tests the _handle_resume_command handler (switch to a previously-named session)across gateway messenger platforms."""+import timefrom types import SimpleNamespacefrom unittest.mock import AsyncMock, MagicMock@@ -305,6 +306,31 @@ class TestHandleResumeCommand:assert "Foreign Work" not in resultdb.close()+ @pytest.mark.asyncio+ async def test_bare_resume_ranks_lineages_by_last_activity(self, tmp_path):+ """A lineage whose root started days ago but was touched last must lead the list: the+ picker ranks by lineage activity, not root ``started_at`` (#114271)."""+ from hermes_state import SessionDB++ db = SessionDB(db_path=tmp_path / "state.db")+ event = _make_event(text="/resume")+ lane_key = _session_key_for_event(event)+ t0 = time.time() - 5 * 86400+ for sid, started, active in (("old_root", t0, t0 + 4 * 86400), ("new_root", t0 + 86400, t0 + 86400 + 60)):+ db.create_session(sid, "telegram", session_key=lane_key, user_id="12345", chat_id="67890")+ db.append_message(sid, "user", "hi")+ db._conn.execute("UPDATE sessions SET started_at=?, last_activity_at=? WHERE id=?", (started, active, sid))+ db._conn.execute("UPDATE messages SET timestamp=? WHERE session_id=?", (active, sid))+ db._conn.commit()+ db.set_session_title("old_root", "Old But Active")+ db.set_session_title("new_root", "Newer But Idle")++ runner = _make_runner(session_db=db, event=event)+ result = await runner._handle_resume_command(event)++ assert result.index("Old But Active") < result.index("Newer But Idle")+ db.close()+@pytest.mark.asyncioasync def test_bare_resume_admin_all_preserves_same_platform_widening(self, tmp_path):from hermes_state import SessionDBdiff --git a/tests/hermes_state/test_hermes_state.py b/tests/hermes_state/test_hermes_state.pyindex 2a370e4faa8..f7c9026ff51 100644--- a/tests/hermes_state/test_hermes_state.py+++ b/tests/hermes_state/test_hermes_state.py@@ -3254,6 +3254,26 @@ class TestCompressionChainProjection:assert ordered_ids.count("reset1") == 1assert ordered_ids.index("solo") < ordered_ids.index("tip1")+ def test_reset_fork_of_compressed_parent_is_not_a_lineage_member(self, db):+ """The Python lineage walk (``get_compression_lineage`` / ``_is_compression_child_row``)+ must agree with the SQL chain step: a reset fork hanging off a compression-ended parent is+ its own conversation, so the true tip keeps its ancestors and the fork never enters the+ lineage even when it started first."""+ import time as _time+ t0 = _time.time() - 3600+ db.create_session("root1", "cli")+ db._conn.execute("UPDATE sessions SET ended_at=?, end_reason='compression' WHERE id=?", (t0 + 10, "root1"))+ db.create_session("reset1", "cli", parent_session_id="root1", model_config={"_reset_from": "root1"})+ db._conn.execute("UPDATE sessions SET started_at=? WHERE id=?", (t0 + 11, "reset1"))+ db.create_session("tip1", "cli", parent_session_id="root1")+ db._conn.execute("UPDATE sessions SET started_at=? WHERE id=?", (t0 + 20, "tip1"))+ db._conn.commit()++ assert db._is_compression_child_row(db.get_session("reset1")) is False+ assert db.get_compression_lineage("root1") == ["root1", "tip1"]+ assert db.get_compression_lineage("tip1") == ["root1", "tip1"]+ assert db.get_compression_lineage("reset1") == ["reset1"]+def test_list_serves_full_lineage_ids_for_projected_rows(self, db):"""The projected tip row must carry every chain id. Root and tipalone are not enough client-side: a persisted tile or route can holddiff --git a/website/docs/reference/slash-commands.md b/website/docs/reference/slash-commands.mdindex c6803adacf7..eb10b324834 100644--- a/website/docs/reference/slash-commands.md+++ b/website/docs/reference/slash-commands.md@@ -58,7 +58,7 @@ Type `/` in the CLI to open the autocomplete menu. Built-in commands are case-in| `/refine [focus]` | Run the background memory/skill self-improvement review **now** instead of waiting for the automatic post-turn trigger. Optional focus text steers the review (e.g. `/refine save the deploy workflow as a skill`). Runs in a background fork against a conversation snapshot — the live session and prompt cache are untouched; results are reported when done. || `/review [instructions]` | Spawn an independent, full-privilege reviewer subagent to review the work just discussed — a PR, code, docs, any artifact referenced in the last 10 chat messages. It investigates in the background (opens the PR, reads the diff, runs code) and its full review re-enters this session as a background-subagent completion the primary agent can act on. Pin a dedicated review model via `auxiliary.review` in config.yaml (defaults to your main model). See [Subagent Delegation](/user-guide/features/delegation#the-review-command). || `/moa <prompt>` | Run a single prompt through the default [Mixture of Agents](/user-guide/features/mixture-of-agents) preset, then restore your current model. One-shot — does not change your session model. |-| `/resume [name]` | Resume a previously-named session. In the classic CLI this (and `/sessions <id>`) is refused while a turn is running — the CLI shares one agent across sessions, so switching mid-turn would file the rest of the running turn under the other session. |+| `/resume [name]` | Resume a previously-named session. Bare `/resume` lists this chat's named sessions ranked by most recent activity (a long-running conversation that compression has rotated several times counts as one entry, shown at its live tip). In the classic CLI this (and `/sessions <id>`) is refused while a turn is running — the CLI shares one agent across sessions, so switching mid-turn would file the rest of the running turn under the other session. || `/sessions` (TUI alias: `/switch`) | Classic CLI: browse and resume previous sessions in an interactive picker. TUI: open the live session switcher for currently open TUI sessions. Use `/sessions new` in the TUI to start another live session immediately. || `/egress [status]` | Show Docker egress proxy status — enabled/configured/running state, credential source, token mappings, uncovered providers, and next remediation step. Works in CLI, TUI, Desktop chat, and messaging gateway. || `/redraw` | Force a full UI repaint (recovers from terminal drift after tmux resize, mouse selection artifacts, etc.) |