The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a rewind by a compression segment's id keeps the owner's busy gate
Tekniumac9b2fd5165c
diff --git a/gateway/session_mutations.py b/gateway/session_mutations.pyindex 3d2cffa89e7..617828b6b99 100644--- a/gateway/session_mutations.py+++ b/gateway/session_mutations.py@@ -17,6 +17,8 @@ logger = logging.getLogger(__name__)_METADATA = frozenset({'rename', 'archive', 'sidebar'})# Prepared off the commit like model, then published as a new frozen policy._POLICY = frozenset({'model', 'reasoning', 'workspace', 'editor_mcp'})+# Controls that leave the transcript alone authorize on the lineage owner (see ``_owner_ref``).+_OWNER_AUTHORIZED = _METADATA | {'delete'}_FIELDS = frozenset({'session_id', 'request_id', 'expected_revision', 'operation', 'payload'})@@ -58,13 +60,19 @@ def _authorize_control(authority, actor, ref, params):def _owner_ref(authority, ref, params):- """A control mutation names the listed row, which may be a later reset or compression segment of- a local conversation; the conversation's creation id owns its policy, FIFO and live session, so- control and the session gate are checked on that owner for every operation. The write itself+ """A metadata control (rename, archive, pin) or a delete names the listed row, which may be a+ later reset or compression segment of a local conversation; the conversation's creation id owns+ its live session, so control and the session gate are checked on that owner. The write itselfstill names the listed row (a title or archive flag belongs to it; delete takes the lineage).- Gating only ``delete`` restored a cold segment as if it were an owner, and rename/archive of a- compressed conversation answered ``storage_unavailable`` (#134889 LC-22, as LC-12 on resume)."""- del params+ Gating only ``delete`` answered rename/archive of a compressed conversation with+ ``storage_unavailable`` (#134889 LC-22, as LC-12 on resume).++ A transcript- or policy-changing operation (rewind, reset, compress, a policy pick) keeps the+ listed id: its busy gate, generation fence and eviction are keyed by the session it writes, so+ authorizing it on the owner while writing the segment would bypass the owner's FIFO. A segment+ of a live owner therefore stays a named refusal for those, as on main."""+ if params.get('operation') not in _OWNER_AUTHORIZED:+ return reffrom gateway.session_contract import SessionReffrom hermes_state_local import local_lineage_ownerwith authority.db._read_ctx() as conn:diff --git a/tests/gateway/test_local_control_compression_child.py b/tests/gateway/test_local_control_compression_child.pyindex 271ba575823..20460f2a423 100644--- a/tests/gateway/test_local_control_compression_child.py+++ b/tests/gateway/test_local_control_compression_child.py@@ -33,6 +33,39 @@ async def test_rename_and_archive_of_a_compression_segment(tmp_path, monkeypatchassert 'result' in renamed, renamedarchived = await _mutate(authority, 'child-2', 'archive-1', 'archive', {'archived': True})assert 'result' in archived, archived- # The write lands on a row of the user's conversation, and the listing reads it back.- titles = {authority.db.get_session(sid).get('title') for sid in (compressed.owner, 'child-1', 'child-2')}- assert 'Renamed' in titles, titles+ # The write lands on the listed row (the sidebar reads the tip's title back), not on the owner.+ assert authority.db.get_session('child-2').get('title') == 'Renamed'++[email protected]('addressed', ['owner', 'segment'])+async def test_a_segment_rewind_keeps_the_owner_busy_gate(tmp_path, monkeypatch, addressed):+ """Owner authorization is for metadata only: a rewind by a compression segment's id must not+ run while the conversation's FIFO holds queued input (the ledger keys admissions by owner id),+ so it is refused exactly like the same rewind by the conversation id (review of #140971)."""+ import hermes_state_runtime as rt+ from gateway.session_controls import AuthorityConnection+ compressed = await _compressed(tmp_path, monkeypatch)+ authority = compressed.warm+ evicted = []+ authority.runner._evict_cached_agent = lambda route, *a, **k: evicted.append(route)+ db = authority.db+ db.append_message('child-2', role='user', content='LIVE_Q')+ db.append_message('child-2', role='assistant', content='LIVE_A')+ target = next(m['id'] for m in db.get_messages('child-2') if m['content'] == 'LIVE_Q')+ rt.admit_session_input(db, epoch=authority.epoch, principal_id='owner', session_id=compressed.owner,+ request_id='queued-1', payload={'text': 'queued after LIVE_A'})+ sid = compressed.owner if addressed == 'owner' else 'child-2'+ row = db.get_session(sid)+ connection = AuthorityConnection(authority, object(), {+ 'provider': 'local', 'user_id': 'owner', 'profile_id': 'fixture', 'instance_id': authority.instance_id,+ 'capabilities': ['session:create', 'session:read', 'session:submit', 'session:control']})+ try:+ reply = await connection.dispatch({'id': 1, 'method': 'session.mutate', 'params': {+ 'session_id': sid, 'request_id': f'rewind-{addressed}', 'expected_revision': row['runtime_revision'],+ 'expected_generation': row['runtime_generation'], 'operation': 'rewind',+ 'payload': {'target_message_id': target}}})+ finally:+ await connection.close()+ assert reply.get('error', {}).get('message') in {'session_busy', 'storage_unavailable'}, reply+ assert [m['content'] for m in db.get_messages('child-2')][-2:] == ['LIVE_Q', 'LIVE_A']