feat: add read-only session lineage report endpoint - #2012
Conversation
SummaryReading Code referenceThe endpoint dispatcher is appropriately minimal: # api/routes.py:3188-3193
if parsed.path == "/api/session/lineage/report":
sid = parse_qs(parsed.query).get("session_id", [""])[0]
if not sid:
return bad(handler, "session_id required", 400)
report = read_session_lineage_report(_active_state_db_path(), sid)
if not report.get("found"):
return bad(handler, "Session not found", 404)
return j(handler, report)And # api/agent_sessions.py:520-528 (PR head)
for _hop in range(max(0, int(max_hops))):
parent_id = current.get('parent_session_id')
parent = fetch_one(parent_id)
if not parent or parent_id in seen:
manual_review = bool(parent_id and parent_id in seen)
break
if not _is_continuation_session(parent, current):
break
segments.append(parent)
seen.add(parent_id)
current = parent
else:
manual_review = TrueThe DiagnosisMostly small/optional. One contract concern. 1. Empty-then-found mismatch when
|
a42adbe
…ge report endpoint by @dso2ng
…ge report endpoint by @dso2ng
…ge report endpoint by @dso2ng
Thinking Path
/api/sessions.What Changed
read_session_lineage_report(db_path, session_id, max_hops=20)inapi.agent_sessions.GET /api/session/lineage/report?session_id=<sid>.mutation: falsefound,lineage_key,tip_session_idsegmentswithtip/hidden_segmentroleschildrenwithchild_sessionrolesmanual_review: truefor bounded/pathological continuation casesWhy It Matters
This gives WebUI a small backend counterpart to the already-shipped lineage sidebar projection without adding archive/delete actions, background workers, storage migrations, or UI changes. Future UI work can lazily fetch this report only when needed.
Verification
/home/dso2ng/.hermes/hermes-agent/venv/bin/python -m pytest tests/test_session_lineage_report.py tests/test_session_lineage_metadata_api.py tests/test_session_lineage_collapse.py -q->22 passed/home/dso2ng/.hermes/hermes-agent/venv/bin/python -m py_compile api/agent_sessions.py api/routes.py api/models.pygit diff --checknon_ascii_added_lines=0Risks / Follow-ups
archive_candidatesordelete_candidatesand does not mutate WebUI JSON orstate.db.state.db.sessions; missing/old schemas degrade to a safe not-found/empty report.Model Used