The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): fence the hosted preclaim await against FIFO advance (X4, reported by @Xipong)
teknium18d6d486f4ad9
diff --git a/gateway/session_authority.py b/gateway/session_authority.pyindex 2ce61e1e180..6e421f717ac 100644--- a/gateway/session_authority.py+++ b/gateway/session_authority.py@@ -392,6 +392,11 @@ class SessionAuthority:if service is None:raise RuntimeStoreError('permission_denied')await asyncio.to_thread(service.check_admission, ref, first)+ # Cancellation may advance the FIFO while the source owner is awaited;+ # the successor must earn its own reauthorization, not inherit this one.+ current = get_session_admission(self.db, admission_id=first['admission_id'])+ if current is None or current['status'] != 'queued':+ continueif 'local_automation_v1' in first['payload']:from gateway.session_automation import check_local_automationcheck_local_automation(self, ref, first)diff --git a/tests/gateway/test_session_authority_cancel_settlement.py b/tests/gateway/test_session_authority_cancel_settlement.pyindex eee8f946d06..c28d5226372 100644--- a/tests/gateway/test_session_authority_cancel_settlement.py+++ b/tests/gateway/test_session_authority_cancel_settlement.py@@ -92,3 +92,43 @@ async def test_cancelling_the_head_of_a_paused_fifo_resumes_its_successor(tmp_pastatuses = {r['request_id']: (r['status'], r['outcome'])for r in list_session_admissions(db, session_id='s', pending_only=False)}assert statuses == {'blocked': ('terminal', 'cancelled'), 'follower': ('terminal', 'completed')}+++async def test_hosted_head_cancelled_during_preclaim_does_not_let_successor_skip_its_check(tmp_path, monkeypatch):+ import threading+ from gateway import session_finite, session_hosted_transport, session_local_recovery+ from gateway.config import Platform++ db, authority = _authority(tmp_path, monkeypatch, platform=Platform.LOCAL)+ monkeypatch.setattr(session_local_recovery, 'restore_local_session', lambda authority, sid: None)+ validated, executed = [], []+ head_checking, release_head = threading.Event(), threading.Event()++ def check_remote_hosted_admission(authority, ref, row):+ validated.append(row['request_id'])+ if row['request_id'] == 'hosted:A':+ head_checking.set()+ release_head.wait(5)+ return True+ # B's own reauthorization is revoked; it must be asked, never inherit A's verdict.+ raise RuntimeStoreError('permission_denied')+ monkeypatch.setattr(session_hosted_transport, 'check_remote_hosted_admission', check_remote_hosted_admission)++ async def execute(authority, ref, row):+ executed.append(row['request_id'])+ return 'done'+ monkeypatch.setattr(session_finite, 'execute_finite_admission', execute)++ with db:+ head = await _submit(authority, 'hosted:A')+ await _submit(authority, 'hosted:B')+ await asyncio.get_running_loop().run_in_executor(None, head_checking.wait, 5)+ await authority.cancel_queued(ACTOR, REF, head.admission_id)+ release_head.set()+ await asyncio.wait_for(authority.sessions['s'].task, 5)++ assert executed == [], 'the successor reached execution without its own hosted validation'+ assert validated == ['hosted:A', 'hosted:B']+ statuses = {r['request_id']: r['status'] for r in list_session_admissions(db, session_id='s', pending_only=False)}+ assert statuses == {'hosted:A': 'terminal', 'hosted:B': 'queued'}