The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: mutation idleness comes from the ledger, not drain task liveness
Tekniumb50f3df477eb
diff --git a/gateway/session_mutations.py b/gateway/session_mutations.pyindex 9d4111a940b..436b8d3fba9 100644--- a/gateway/session_mutations.py+++ b/gateway/session_mutations.py@@ -56,10 +56,9 @@ async def mutate_session(authority, actor, ref, params):applied = Trueif operation in _METADATA or operation == 'import':return- for sid in targets:- candidate = authority.sessions.get(sid)- if candidate is not None and candidate.task is not None and not candidate.task.done():- raise RuntimeStoreError('session_busy')+ # Idleness is the ledger's call (require_idle, same transaction). The drain+ # task outlives the final settlement by one loop iteration, so its liveness+ # would refuse a session whose receipt the client already saw as terminal.if operation == 'delete':store = getattr(authority.runner, 'session_store', None)if store is not None and (store._routing_db is Nonediff --git a/tests/gateway/test_session_mutation_delete_fences.py b/tests/gateway/test_session_mutation_delete_fences.pyindex 7cb1778971f..6a365f64f86 100644--- a/tests/gateway/test_session_mutation_delete_fences.py+++ b/tests/gateway/test_session_mutation_delete_fences.py@@ -1,5 +1,4 @@"""Deletion covers live descendants before their durable claim."""-import asynciofrom types import SimpleNamespaceimport pytestfrom gateway.session_authority import LiveSession, SessionAuthority@@ -16,8 +15,12 @@ async def test_delete_cannot_remove_a_live_delegate_without_a_claim(tmp_path):epoch = rt.begin_runtime_epoch(db, instance_id='owner')authority = SessionAuthority(SimpleNamespace(_draining=False), profile_id='owned', instance_id='owner', db=db, epoch=epoch)authority.sessions['s'] = LiveSession(None, 'route')- child = authority.sessions['child'] = LiveSession(None, 'child-route')- child.task = asyncio.create_task(asyncio.Event().wait())+ authority.sessions['child'] = LiveSession(None, 'child-route')+ # The descendant's execution is a ledger row, not an in-memory task: it must+ # fence the parent's deletion in the same transaction that would delete it.+ db._execute_write(lambda conn: conn.execute(+ "INSERT INTO worker_executions(execution_id,session_id,kind,owner_epoch,generation,status,adoption_digest) "+ "VALUES('child-exec','child','child',?,0,'running','digest')", (epoch,)))owner = AuthorityConnection(authority, object(), {'user_id': 'human'})try:response = await owner.dispatch({'id': 1, 'method': 'session.mutate', 'params': {'session_id': 's',@@ -26,6 +29,4 @@ async def test_delete_cannot_remove_a_live_delegate_without_a_claim(tmp_path):assert response['error']['message'] == 'session_busy'assert db.get_session('child') is not Nonefinally:- child.task.cancel()- await asyncio.gather(child.task, return_exceptions=True)await owner.close()