Description
When delegate_task spawns subagent sessions, they appear in hermes sessions list and /resume as untitled orphan entries indistinguishable from real user sessions.
Root Cause
delegate_tool.py passes session_db to child agents (line 229) but not parent_session_id. The child agent calls create_session() (run_agent.py:968) with parent_session_id=None, creating a top-level session with source=cli.
The DB schema already has parent_session_id as a FK column on the sessions table, and session_search already handles it correctly (filters children in recent list, resolves to parent in FTS). But delegate_tool never wires it up.
Reproduction
hermes chat
> delegate a task to check the date
> /resume
The subagent session appears as an untitled entry alongside real sessions.
Impact
hermes sessions list shows orphan subagent sessions
/resume picker shows them
session_search recent sessions list shows them
- Each
delegate_task call (especially batch with 3 tasks) creates 1-3 extra visible sessions
Additional: FK cascade bug in delete_session/prune_sessions
The sessions.parent_session_id FK has no ON DELETE CASCADE. When sessions DO have parent_session_id set (compression chains today, subagents after fix), deleting a parent raises IntegrityError because children reference it.
delete_session() and prune_sessions() need to delete children before parents.
Suggested Fix
- Pass
parent_session_id=parent_agent.session_id in delegate_tool._build_child_agent()
- Add
parent_session_id param to run_agent.py __init__, pass to create_session()
- Filter
parent_session_id IS NULL in list_sessions_rich()
- Delete children first in
delete_session()/prune_sessions()
Description
When
delegate_taskspawns subagent sessions, they appear inhermes sessions listand/resumeas untitled orphan entries indistinguishable from real user sessions.Root Cause
delegate_tool.pypassessession_dbto child agents (line 229) but notparent_session_id. The child agent callscreate_session()(run_agent.py:968) withparent_session_id=None, creating a top-level session withsource=cli.The DB schema already has
parent_session_idas a FK column on the sessions table, andsession_searchalready handles it correctly (filters children in recent list, resolves to parent in FTS). Butdelegate_toolnever wires it up.Reproduction
The subagent session appears as an untitled entry alongside real sessions.
Impact
hermes sessions listshows orphan subagent sessions/resumepicker shows themsession_searchrecent sessions list shows themdelegate_taskcall (especially batch with 3 tasks) creates 1-3 extra visible sessionsAdditional: FK cascade bug in delete_session/prune_sessions
The
sessions.parent_session_idFK has noON DELETE CASCADE. When sessions DO haveparent_session_idset (compression chains today, subagents after fix), deleting a parent raisesIntegrityErrorbecause children reference it.delete_session()andprune_sessions()need to delete children before parents.Suggested Fix
parent_session_id=parent_agent.session_idindelegate_tool._build_child_agent()parent_session_idparam torun_agent.py__init__, pass tocreate_session()parent_session_id IS NULLinlist_sessions_rich()delete_session()/prune_sessions()