The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(state): deleting a compressed logical root retires every physical continuation (X19, reported by @Xipong)
teknium1021cbf08341a
diff --git a/hermes_state_mutation_guards.py b/hermes_state_mutation_guards.pyindex 7a463dd3acb..72184404b98 100644--- a/hermes_state_mutation_guards.py+++ b/hermes_state_mutation_guards.py@@ -23,6 +23,7 @@ def require_idle(db, conn, session_ids):def delete_targets(conn, session_id):from hermes_state_sessions import _collect_delegate_child_idsimport json+ from hermes_state_compression import _CHAIN_STEP_SQLfrom hermes_state_local import POLICY_PREFIXfrom hermes_state_local_lineage import validate_local_lineagetargets = {session_id}@@ -32,5 +33,14 @@ def delete_targets(conn, session_id):receipt = json.loads(saved[0])validate_local_lineage(conn, receipt)targets.update(receipt.get('lineage', [session_id]))+ # Canonical admissions bind to the compression root for every producer, not only+ # local receipts: every physical continuation of a target goes with it, or the next+ # message on the route re-admits the "deleted" conversation through the surviving child.+ frontier = list(targets)+ while frontier:+ row = conn.execute(_CHAIN_STEP_SQL, (frontier.pop(),)).fetchone()+ if row is not None and row[0] not in targets:+ targets.add(row[0])+ frontier.append(row[0])targets.update(_collect_delegate_child_ids(conn, targets))return [session_id, *sorted(targets - {session_id})]diff --git a/tests/state/test_runtime_destructive_mutations.py b/tests/state/test_runtime_destructive_mutations.pyindex e011cc35298..ee3ecb85a99 100644--- a/tests/state/test_runtime_destructive_mutations.py+++ b/tests/state/test_runtime_destructive_mutations.py@@ -46,3 +46,25 @@ def test_delete_receipt_survives_removal_and_fences_generation(tmp_path):assert rt.mutate_runtime_session(db, **args) == receiptwith pytest.raises(rt.RuntimeStoreError, match='admission_conflict'):rt.mutate_runtime_session(db, **(args | {'expected_generation': 1}))+++def test_delete_of_compressed_logical_root_retires_every_physical_continuation(tmp_path):+ """Canonical admissions bind to the compression root; deleting it must remove the whole+ chain (transcript, rows, routing) for native sessions too, or the next message on the same+ route resolves to the surviving child and re-admits the 'deleted' conversation with history."""+ import json+ with SessionDB(db_path=tmp_path / 'state.db') as db:+ db.create_session('root', source='telegram', session_key='agent:telegram:dm:1')+ db.append_message('root', 'user', 'before compression')+ assert db.try_acquire_compression_lock('root', 'holder')+ db.publish_compression_child(parent_session_id='root', child_session_id='child', source='telegram',+ messages=[{'role': 'user', 'content': 'summary'}], compression_lock_holder='holder')+ db.append_message('child', 'user', 'after compression')+ db.save_gateway_routing_entry('agent:telegram:dm:1', json.dumps({'session_id': 'child', 'session_key': 'agent:telegram:dm:1'}))+ epoch = rt.begin_runtime_epoch(db, instance_id='owner')+ receipt = rt.mutate_runtime_session(db, epoch=epoch, principal_id='human', session_id='root', request_id='delete',+ expected_revision=0, expected_generation=0, operation='delete', payload={})+ assert set(receipt['deleted_ids']) == {'root', 'child'}+ assert db.get_session('child') is None+ assert db.get_messages_as_conversation('child') == []+ assert db.load_gateway_routing_entries() == {}