The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): run the last-attempt admission recheck in the owning profile's scope
kshitijk4poor2bc1edbc5ea1
diff --git a/gateway/run_notifications.py b/gateway/run_notifications.pyindex 8248d48153a..94afb520e24 100644--- a/gateway/run_notifications.py+++ b/gateway/run_notifications.py@@ -1752,7 +1752,9 @@ class GatewayNotificationsMixin(GatewayUpdateNotificationsMixin, GatewayNotificaand self._completion_delivery_identity(completion_evt) is not None):from gateway.session_automation import completion_admissiontry:- committed = completion_admission(self, completion_evt) is not None+ # The owning profile's authority, as on the delivery path.+ async with self._completion_event_scope(completion_evt):+ committed = completion_admission(self, completion_evt) is not Noneexcept Exception:# Failing open sends the notice; a dead watcher would send nothing.logger.debug("Process watcher: admission recheck failed for %s", session_id,diff --git a/tests/gateway/test_background_process_notifications.py b/tests/gateway/test_background_process_notifications.pyindex acba3f17090..e4834780e61 100644--- a/tests/gateway/test_background_process_notifications.py+++ b/tests/gateway/test_background_process_notifications.py@@ -8,6 +8,7 @@ Contributed by @PeterFile (PR #593), reimplemented on current main."""import asyncio+import contextlibimport queueimport threadingfrom types import SimpleNamespace@@ -518,7 +519,19 @@ async def test_agent_notify_refused_completion_backs_off_then_sends_plain_noticerunner = _build_runner(monkeypatch, tmp_path, "concise")runner._enqueue_process_completion_notification = AsyncMock(return_value=False)runner.session_authority = object()+ inside = []++ @contextlib.asynccontextmanager+ async def _scope(evt):+ inside.append(evt)+ try:+ yield+ finally:+ inside.pop()+ monkeypatch.setattr(runner, "_completion_event_scope", _scope)+def _admission(_runner, _evt):+ assert inside and inside[-1] is _evt, "recheck ran outside the owning profile scope"if committed == "recheck_fails":raise RuntimeError("store closed")return {"admission_id": "committed"} if committed else None