The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): busy plaintext approval answers the blocking prompt under the authority
Teknium279dc989b8f6
diff --git a/gateway/run_inbound.py b/gateway/run_inbound.pyindex 7d0b1fb4619..08e91e14707 100644--- a/gateway/run_inbound.py+++ b/gateway/run_inbound.py@@ -1194,7 +1194,11 @@ class GatewayInboundMixin(GatewayInboundHooksMixin, GatewayPluginInjectionMixin)# does to the RUNNING one (steer into it, redirect it, or end it so the FIFO advances).# Without this, ``interrupt`` degrades to ``queue`` behind a turn that may hang for# its whole request timeout.- if self._is_session_running(_quick_key) and await self._hm_busy_preempt(event, source, _quick_key):+ # A bare "yes"/"no" to a blocking dangerous-command approval answers it (#46866):+ # never an interrupt (read as deny) nor a queued turn (auto-deny deadlock).+ if self._is_session_running(_quick_key) and (+ await self._route_plaintext_approval_while_busy(event, _quick_key)+ or await self._hm_busy_preempt(event, source, _quick_key)):return True, None_consumed, _consumer_reply = await self._hm_post_admission_consume(event, source, _quick_key)if _consumed:diff --git a/tests/gateway/test_authority_busy_plaintext_approval.py b/tests/gateway/test_authority_busy_plaintext_approval.pynew file mode 100644index 00000000000..392f3551c85--- /dev/null+++ b/tests/gateway/test_authority_busy_plaintext_approval.py@@ -0,0 +1,64 @@+"""Under the session authority a busy bare "yes" still answers a blocking approval (#46866)."""+import asyncio++import pytest++from gateway.config import GatewayConfig, Platform, PlatformConfig+from gateway.platforms.base import SendResult+from gateway.platforms.event import MessageEvent+from gateway.run import GatewayRunner+from gateway.session_authority import SessionAuthority, initialize_session_authority+from hermes_state_runtime import list_session_admissions++CHAT = '[email protected]'+++class _RunningAgent:+ def __init__(self):+ self.interrupts = []++ def interrupt(self, *args):+ self.interrupts.append(args)++[email protected]('mode', ['interrupt', 'queue'])+async def test_busy_plaintext_yes_resolves_blocking_approval_not_interrupt_or_queue(tmp_path, monkeypatch, mode):+ from plugins.platforms.whatsapp.adapter import WhatsAppAdapter+ from tools.approval import _gateway_queues+ from tools.approval_gateway_wait import _ApprovalEntry+ monkeypatch.setenv('WHATSAPP_ALLOWED_USERS', '15551234567')+ # No drain: an admitted "yes" would then wait on a turn, which is exactly the regression.+ monkeypatch.setattr(SessionAuthority, '_schedule', lambda self, ref: None)+ runner = GatewayRunner(GatewayConfig(sessions_dir=tmp_path / 'sessions'))+ adapter = WhatsAppAdapter(PlatformConfig(enabled=True, extra={'session_path': str(tmp_path / 'wa')}))+ adapter.gateway_runner, runner.adapters = runner, {Platform.WHATSAPP: adapter}+ authority = await initialize_session_authority(runner, profile_id='default', instance_id='approval')+ runner._wire_adapter_handlers(adapter)+ sent = []++ async def send(chat_id, content, **_):+ sent.append(content)+ return SendResult(success=True, message_id='s')++ monkeypatch.setattr(adapter, 'send', send)+ monkeypatch.setattr(runner, '_effective_busy_input_mode', lambda source: mode)+ source = adapter.build_source(chat_id=CHAT, user_id=CHAT, chat_type='dm')+ key = runner._session_key_for_source(source)+ agent = _RunningAgent()+ runner._session_state(key).turn.agent = agent+ entry = _ApprovalEntry({'command': 'rm -rf build'})+ _gateway_queues.setdefault(key, []).append(entry)+ try:+ handled = asyncio.ensure_future(runner._handle_message(MessageEvent(text='yes', source=source, message_id='y1')))+ done, _ = await asyncio.wait({handled}, timeout=10)+ handled.cancel()+ assert done, '"yes" was admitted as a turn behind the blocked approval'+ assert entry.event.is_set() and entry.result == 'once'+ assert agent.interrupts == []+ admitted = [row for sid in authority.sessions+ for row in list_session_admissions(authority.db, session_id=sid, pending_only=False)]+ assert admitted == [], admitted+ finally:+ _gateway_queues.pop(key, None)+ authority.db.close()