The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(state): keep the compression root as a reset lineage row's pin anchor
Teknium32970f3ab311
diff --git a/hermes_state_local.py b/hermes_state_local.pyindex 7b6180d1692..10c993196f7 100644--- a/hermes_state_local.py+++ b/hermes_state_local.py@@ -132,7 +132,8 @@ def local_lineage_index(conn):``acp_adapter.catalog`` does: a canonical reset keeps the creation id as the owner and moves thetranscript to a child, so every segment is one conversation. ``superseded`` holds the listableroots of earlier reset segments (filtered in SQL, before paging); ``heads`` maps the latest- reset segment to ``(owner, lineage)`` for the row that represents the conversation."""+ reset segment to ``(owner, lineage)`` for the row that represents the conversation. A delete+ of that row removes the whole lineage (``hermes_state_mutation_guards.delete_targets``)."""superseded, heads = set(), {}rows = conn.execute("SELECT value FROM state_meta WHERE key GLOB ? AND json_valid(value) ""AND json_array_length(value, '$.lineage') > 1", (POLICY_PREFIX + '*',)).fetchall()@@ -150,14 +151,13 @@ def local_lineage_index(conn):def annotate_local_lineages(sessions, heads):- """Name the whole conversation on its representative row: ``_lineage_root_id`` is the creation- id (the id every surface resolves, deletes and pins by), ``_lineage_ids`` every segment."""+ """Name every segment on the conversation's representative row (``_lineage_ids``, which the+ Desktop matches deletes, tombstones and stored ids against). ``_lineage_root_id`` stays the+ compression root: pins and archive flags live on the listed segment's own chain."""for row in sessions:found = heads.get(row.get('_lineage_root_id') or row['id'])if found is not None:- owner, lineage = found- row['_lineage_ids'] = list(lineage)- row['_lineage_root_id'] = owner if row['id'] != owner else None+ row['_lineage_ids'] = list(dict.fromkeys([*found[1], *(row.get('_lineage_ids') or ())]))return sessionsdiff --git a/tests/gateway/test_local_reset_lineage_one_conversation.py b/tests/gateway/test_local_reset_lineage_one_conversation.pyindex b34e57ca3c9..17634569d17 100644--- a/tests/gateway/test_local_reset_lineage_one_conversation.py+++ b/tests/gateway/test_local_reset_lineage_one_conversation.py@@ -46,7 +46,8 @@ async def test_reset_lineage_lists_once_and_deleting_the_listed_row_deletes_it(rfrom gateway.session_mutations import mutate_sessiont = reset_lineagerows = t.authority.db.list_sessions_rich(order_by_last_active=True, limit=50)- assert [(r['id'], r.get('_lineage_root_id')) for r in rows] == [(t.s1, t.s0)], 'listed as two conversations'+ assert [r['id'] for r in rows] == [t.s1], 'listed as two conversations'+ assert {t.s0, t.s1} <= set(rows[0]['_lineage_ids'])# Pages are filtered before LIMIT/OFFSET: the superseded segment never fills a later page.assert t.authority.db.list_sessions_rich(limit=1, offset=1) == []row = t.authority.db.get_session(t.s1)