The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(state): never transfer a title off a parent across a branch edge
unsupportedpastels9225098c7fe6
diff --git a/hermes_state_titles.py b/hermes_state_titles.pyindex 883ed7eb5ea..4667533b940 100644--- a/hermes_state_titles.py+++ b/hermes_state_titles.py@@ -8,7 +8,7 @@ import refrom typing import Any, Dict, Optionalfrom agent.message_sanitization import _sanitize_surrogates-from hermes_state_common import _COMPRESSION_CHILD_SQL, escape_like as _escape_like+from hermes_state_common import _COMPRESSION_CHILD_SQL, _non_continuation_child_sql, escape_like as _escape_like# caplog tests pin the "hermes_state" logger name.logger = logging.getLogger("hermes_state")@@ -63,10 +63,10 @@ class SessionTitlesMixin:def _is_compression_ancestor(self, conn, *, ancestor_id: str, descendant_id: str) -> bool:"""True if *ancestor_id* is a compression predecessor of *descendant_id*, via thecanonical continuation edge ``_COMPRESSION_CHILD_SQL`` (excludes delegate/branch- children that also carry ``parent_session_id``)."""+ children that also carry ``parent_session_id``, even under a compressed parent)."""if not ancestor_id or not descendant_id or ancestor_id == descendant_id:return False- edge = _COMPRESSION_CHILD_SQL.format(a="child")+ edge = _COMPRESSION_CHILD_SQL.format(a="child") + _non_continuation_child_sql("child.", "parent.id")return conn.execute(f"""WITH RECURSIVE ancestors(id) AS (SELECT ?diff --git a/tests/gateway/test_legacy_desktop_source.py b/tests/gateway/test_legacy_desktop_source.pyindex 9668492e9e9..cd4b07fe31e 100644--- a/tests/gateway/test_legacy_desktop_source.py+++ b/tests/gateway/test_legacy_desktop_source.py@@ -161,3 +161,36 @@ async def test_editing_ones_own_branch_leaves_another_logins_parent_alone(tmp_pafor sid in ('alice-branch', 'alice-tip'):row = db.get_session(sid)assert (row['pinned'], row['hidden'], row['archived']) == (1, 1, 1), sid++[email protected]('root_owner', ['basic:bob', None])+async def test_renaming_ones_own_branch_leaves_another_logins_parent_title_alone(tmp_path, root_owner):+ """#144596 round-2 review F1: a rename transfers a title off a compression ancestor. alice's branch+ of bob's compressed chat is not his continuation, so taking his title is a conflict, not a transfer."""+ from types import SimpleNamespace+ from gateway.session_authority import SessionAuthority+ from gateway.session_contract import SessionRef+ from gateway.session_mutations import mutate_session+ from hermes_state_runtime import begin_runtime_epoch+ from tui_gateway.methods_session import _persist_branch++ caps = frozenset({'session:read', 'session:control', 'session:create', 'session:operator'})+ alice = Principal(_login('alice'), 'p', caps, 'http')+ with SessionDB(db_path=tmp_path / 'state.db') as db:+ authority = SessionAuthority(SimpleNamespace(_draining=False), profile_id='p', instance_id='owner',+ db=db, epoch=begin_runtime_epoch(db, instance_id='owner'))+ db.create_session('root', source='desktop', user_id=root_owner)+ db.set_session_title('root', 'Bob title')+ db.append_message('root', 'user', 'hello') # a real chat, not an empty ghost that yields its name+ db.end_session('root', 'compression')+ _persist_branch(db, 'alice-branch', 'root', 'Branch', [{'role': 'user', 'content': 'hi'}],+ source='desktop', cwd=None, profile_name=None, model='m', user_id='basic:alice')+ before = db.get_session('root')['runtime_revision']+ params = {'session_id': 'alice-branch', 'request_id': 'rename', 'operation': 'sidebar',+ 'payload': {'title': 'Bob title'},+ 'expected_revision': db.get_session('alice-branch')['runtime_revision']}+ with pytest.raises(Exception, match='already in use'):+ await mutate_session(authority, alice, SessionRef('p', 'alice-branch'), params)+ root = db.get_session('root')+ assert (root['title'], root['runtime_revision']) == ('Bob title', before)