The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: plugin inject_message enters the session FIFO under the session authority
Teknium05305c4efb20
diff --git a/gateway/run_plugin_injection.py b/gateway/run_plugin_injection.pyindex fe5c152ef69..aceede24ba0 100644--- a/gateway/run_plugin_injection.py+++ b/gateway/run_plugin_injection.py@@ -143,6 +143,11 @@ class GatewayPluginInjectionMixin:return Falseasync with self._plugin_injection_scope(source):+ admitted = await self._admit_plugin_injection(+ adapter, source, session_key=session_key, session_id=entry.session_id,+ content=content, plugin_id=plugin_id)+ if admitted is not None:+ return admittedawait adapter.handle_message(MessageEvent(text=content, message_type=MessageType.TEXT, source=source, internal=True,allow_gateway_control=False,@@ -231,6 +236,19 @@ class GatewayPluginInjectionMixin:return Falsesession_key = self._session_key_for_source(source)async with self._plugin_injection_scope(source):+ from gateway.session_authorities import active_authority+ if active_authority(self) is not None:+ # The FIFO admits a producer turn only into a session that already holds a+ # committed human turn (its connector provenance is borrowed, never minted), so+ # an origin with no session yet is refused rather than run outside the FIFO.+ entry = await self.async_session_store.lookup_by_session_key(session_key)+ if entry is None:+ logger.warning("Plugin message injection refused: plugin=%s %s has no session under "+ "the session authority yet", plugin_id, target)+ return False+ return await self._admit_plugin_injection(+ adapter, source, session_key=session_key, session_id=entry.session_id,+ content=content, plugin_id=plugin_id)await adapter.handle_message(MessageEvent(text=content, message_type=MessageType.TEXT, source=source, internal=True,allow_gateway_control=False,@@ -242,3 +260,34 @@ class GatewayPluginInjectionMixin:))logger.info("Plugin message injection dispatched: plugin=%s %s session=%s", plugin_id, target, session_key)return True++ async def _admit_plugin_injection(+ self, adapter, source: SessionSource, *, session_key: str, session_id: str, content: str,+ plugin_id: str,+ ) -> Optional[bool]:+ """Under a session authority, commit the plugin turn into the session's durable FIFO as a+ trusted producer admission (the heartbeat / completion seam) instead of running it on the+ in-process lane beside an admitted turn. ``None`` means no authority serves this scope and+ the caller keeps the standalone adapter path; a refused admission is ``False``, logged."""+ from gateway.session_authorities import active_authority+ authority = active_authority(self)+ if authority is None:+ return None+ import json+ import uuid+ from hermes_state_runtime import RuntimeStoreError+ identity = json.dumps(["plugin", plugin_id, session_key, uuid.uuid4().hex], separators=(",", ":"))+ event = MessageEvent(+ text=content, message_type=MessageType.TEXT, source=source, internal=True,+ allow_gateway_control=False, message_id=identity,+ metadata={"gateway_session_key": session_key, "gateway_session_id": session_id},+ )+ try:+ await authority.admit_automation(adapter, event, identity)+ except RuntimeStoreError as exc:+ logger.warning("Plugin message injection refused by the session authority: plugin=%s session=%s (%s)",+ plugin_id, session_key, exc.reason)+ return False+ logger.info("Plugin message injection admitted: plugin=%s session=%s session_id=%s",+ plugin_id, session_key, session_id)+ return Truediff --git a/tests/gateway/test_plugin_message_injection.py b/tests/gateway/test_plugin_message_injection.pyindex 398fe0ae1ec..e747f41877b 100644--- a/tests/gateway/test_plugin_message_injection.py+++ b/tests/gateway/test_plugin_message_injection.py@@ -455,3 +455,31 @@ def test_install_and_clear_gateway_injector_preserves_newer_owner():assert manager.has_gateway_message_injector is Trueassert manager.inject_gateway_message(value="kept") is Truenewer_injector.assert_called_once_with(value="kept")+++async def test_under_a_session_authority_injection_enters_the_durable_fifo(monkeypatch):+ """With an authority serving the scope, a plugin turn is committed as a trusted producer+ admission into the session's FIFO; it never runs on the in-process adapter lane, and a+ refused admission is reported as not routed instead of falling back to that lane."""+ import gateway.session_authorities as authorities+ from hermes_state_runtime import RuntimeStoreError++ adapter = SimpleNamespace(handle_message=AsyncMock())+ entry = _entry()+ runner = _runner(entry, adapter)+ authority = SimpleNamespace(admit_automation=AsyncMock())+ monkeypatch.setattr(authorities, "active_authority", lambda _runner: authority)++ assert await runner._dispatch_plugin_message_injection(+ session_key=entry.session_key, content="check the deployment", plugin_id="notify-plugin") is True+ adapter.handle_message.assert_not_awaited()+ admitted_adapter, event, identity = authority.admit_automation.await_args.args+ assert admitted_adapter is adapter and event.internal is True and event.message_id == identity+ assert event.metadata == {"gateway_session_key": entry.session_key, "gateway_session_id": entry.session_id}+ assert event.text == "check the deployment" and "notify-plugin" in identity++ authority.admit_automation.side_effect = RuntimeStoreError("not_found")+ assert await runner._dispatch_plugin_message_injection(+ session_key=entry.session_key, content="again", plugin_id="notify-plugin") is False+ adapter.handle_message.assert_not_awaited()