Skip to content

The agent that grows with you

fix(gateway): delete a compressed cron or subagent history as one chat

unsupportedpastelsfd4db7b0e2fb
diff --git a/hermes_state_mutation_binding.py b/hermes_state_mutation_binding.py
index 07b964d3b7c..7c3fc94a5f3 100644
--- a/hermes_state_mutation_binding.py
+++ b/hermes_state_mutation_binding.py
@@ -80,7 +80,9 @@ def same_history_owner(conn, anchor_id, session_id):
carry the anchor's exact (user_id, session_key, chat_id). A routeless member needs the
anchor's exact import binding; unbound, it must also pass :func:`authorize_history`'s local
rule (local source, no foreign user_id) — e.g. the pre-adoption ancestors of an adopted
- legacy CLI conversation. A bound (imported) anchor therefore never reaches unbound rows.
+ legacy CLI conversation — or share an unbound routeless anchor's source (an old cron run's or
+ subagent's own compression chain, mounted as one chat). A bound (imported) anchor therefore
+ never reaches unbound rows.
"""
columns = 'SELECT source,user_id,session_key,chat_id,origin_json FROM sessions WHERE id=?'
anchor, row = (conn.execute(columns, (sid,)).fetchone() for sid in (anchor_id, session_id))
@@ -91,5 +93,6 @@ def same_history_owner(conn, anchor_id, session_id):
binding = history_binding(conn, session_id)
if binding != history_binding(conn, anchor_id):
return False
+ routeless_peer = row['source'] == anchor['source'] and not any(tuple(anchor)[2:5])
return binding is not None or (
- row['source'] in _history_sources() and _owner_user(row) in (None, '', anchor['user_id']))
+ (row['source'] in _history_sources() or routeless_peer) and _owner_user(row) in (None, '', anchor['user_id']))
diff --git a/tests/gateway/test_stored_history_mount.py b/tests/gateway/test_stored_history_mount.py
index fc54afa565f..fb9b7eae0d7 100644
--- a/tests/gateway/test_stored_history_mount.py
+++ b/tests/gateway/test_stored_history_mount.py
@@ -197,6 +197,21 @@ async def test_session_info_answers_on_a_mount(tmp_path, monkeypatch, sid):
assert reply.get('result', {}).get('source') == ROWS[sid][0], reply
[email protected]('selected', ['tip', 'root'])
+async def test_a_compressed_cron_history_deletes_as_one_chat(tmp_path, monkeypatch, selected):
+ """Deleting one segment of an old cron run's compression chain removed that segment only: the
+ other came back as its own chat, or stayed as a detached one."""
+ conn, ref = await _connect(tmp_path, monkeypatch, 'cron_job1_20261001_120000')
+ db, root = conn.authority.db, ref.session_id
+ db._write_sql("UPDATE sessions SET end_reason='compression', ended_at=1 WHERE id=?", (root,))
+ db.create_session('cron-tip', source='cron', model='m-old', parent_session_id=root)
+ target = SessionRef(ref.profile_id, 'cron-tip' if selected == 'tip' else root)
+ await conn.resume(target, {})
+ await _mutate(conn, target, 'delete', 'delete', {})
+ assert [sid for sid in (root, 'cron-tip') if db.get_session(sid) is not None] == []
+
+
@pytest.mark.asyncio
async def test_push_to_talk_reads_voice_off_on_a_mount(tmp_path, monkeypatch):
"""The TUI's push-to-talk gate on an opened stored chat raised AttributeError on the source-less mount."""