The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): resuming a chat never lands inside a subagent or /branch child row
teknium1b80292c9dfe3
diff --git a/hermes_cli/web_server_sessions.py b/hermes_cli/web_server_sessions.pyindex 70bfbc914b0..fc2c0d6e46b 100644--- a/hermes_cli/web_server_sessions.py+++ b/hermes_cli/web_server_sessions.py@@ -9,16 +9,25 @@ import timefrom pathlib import Pathfrom typing import Dict, Optional+from hermes_state_common import _RESET_CHILD_SQL, _sql_json_extract+# Same logger the code used before extraction (record parity)._log = logging.getLogger("hermes_cli.web_server")-_DESCENDANTS_SQL = """+_DESCENDANTS_SQL = f"""WITH RECURSIVE descendants(id, parent_session_id, started_at) AS (SELECT id, parent_session_id, started_at FROM sessions WHERE id = ?UNIONSELECT s.id, s.parent_session_id, s.started_atFROM sessions sJOIN descendants d ON s.parent_session_id = d.id+ -- Continuation edges only (same predicate as the session list's chain CTE): a subagent run,+ -- a /branch fork, a /new reset child or a tool-owned row is its own conversation, and resuming+ -- INTO one parks the user's chat in a row the sidebar never lists (#115092).+ WHERE {_sql_json_extract('s.model_config', '$._delegate_from')} IS NULL+ AND {_sql_json_extract('s.model_config', '$._branched_from')} IS NULL+ AND NOT ({_RESET_CHILD_SQL.format(a='s')})+ AND COALESCE(s.source, '') != 'tool')SELECT id, parent_session_id, started_at FROM descendants"""diff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.pyindex 0607d58d532..0256d3da659 100644--- a/tests/hermes_cli/test_web_server.py+++ b/tests/hermes_cli/test_web_server.py@@ -1246,6 +1246,33 @@ class TestWebServerEndpoints:assert resp.status_code == 200assert resp.json()["session_id"] == "cyc-b"+ def test_latest_descendant_never_resumes_into_a_subagent_or_branch_child(self):+ """#115092: after a ws_orphan_reap the dashboard resumes the predecessor's newest descendant. A+ subagent run (``_delegate_from``) or a /branch fork (``_branched_from``) is its own conversation and+ never listed as a continuation, so following it parks the user's chat in a hidden row; only+ compression continuations are followed."""+ from hermes_state import SessionDB++ db = SessionDB()+ try:+ db.create_session(session_id="primary", source="tui")+ db.create_session(session_id="primary-sub", source="tui", parent_session_id="primary",+ model_config={"_delegate_from": "primary"})+ db.create_session(session_id="primary-fork", source="tui", parent_session_id="primary",+ model_config={"_branched_from": "primary"})+ db.end_session("primary", "ws_orphan_reap")+ assert self.client.get("/api/sessions/primary/latest-descendant").json()["session_id"] == "primary"++ db._conn.execute("UPDATE sessions SET end_reason='compression' WHERE id='primary'")+ db._conn.commit()+ db.create_session(session_id="primary-cont", source="tui", parent_session_id="primary")+ finally:+ db.close()++ resp = self.client.get("/api/sessions/primary/latest-descendant")+ assert resp.status_code == 200+ assert resp.json()["session_id"] == "primary-cont"+