The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): word the parked-profile refusal as an outage notice
unsupportedpastelsab3507a83da5
diff --git a/gateway/parked_route_refusal.py b/gateway/parked_route_refusal.pyindex cff36fed4de..76197899e51 100644--- a/gateway/parked_route_refusal.py+++ b/gateway/parked_route_refusal.py@@ -3,7 +3,8 @@A parked profile comes back on a rescan, so its traffic is temporarily unavailable. Relay frames andwebhooks are left unacknowledged for the platform to redeliver (``webhook_ingress``). A direct bot(Telegram's PTB ``Updater``, Slack Socket Mode, Discord's gateway, Google Chat Pub/Sub) has already-confirmed the update to its platform before the gateway sees it, so nothing redelivers it. Holding it+confirmed the update to its platform before the gateway sees it, so the platform never redelivers it+(Discord's own missed-message backfill, when enabled, can still pick it up after recovery). Holding ithere would be a second inbound queue outside the one durable queue, kept for a profile whose store isthe one that cannot be trusted. So the sender is told, in-channel, to resend, and nothing is admitted."""@@ -13,7 +14,9 @@ import logginglogger = logging.getLogger(__name__)# Generic on purpose: the chat is not told which profile the route targets or why it is parked.-PARKED_ROUTE_NOTICE = 'This assistant is temporarily unavailable; please resend your message in a moment.'+# Worded as an outage notice Discord's backfill recognises (``_is_down_notice_content``): the reply+# must not mark the never-admitted message answered, so backfill picks it up once it is served again.+PARKED_ROUTE_NOTICE = 'The agent is currently unavailable; please resend your message in a moment.'def drop_rejected_route(adapter, source):diff --git a/tests/gateway/test_parked_profile_platform_refusal.py b/tests/gateway/test_parked_profile_platform_refusal.pyindex 54ef9372ace..cfa0a9923d0 100644--- a/tests/gateway/test_parked_profile_platform_refusal.py+++ b/tests/gateway/test_parked_profile_platform_refusal.py@@ -58,7 +58,7 @@ async def _settle(bot):def _assert_refused(bot, homes, event, caplog):assert [(chat, reply_to) for chat, _text, reply_to in bot.sent] == [('C', 'm1')], (f'the sender of a message routed to a parked profile was not told: {bot.sent}')- assert 'temporarily unavailable' in bot.sent[0][1] and 'resend' in bot.sent[0][1], bot.sent+ assert 'currently unavailable' in bot.sent[0][1] and 'resend' in bot.sent[0][1], bot.sentassert 'beta' not in bot.sent[0][1], 'the refusal names the routed profile to the chat'assert event._gateway_accepted is Falseassert _admissions(homes[0][1]) == 0 and _admissions(homes[1][1]) == 0diff --git a/tests/gateway/test_parked_route_refusal_discord.py b/tests/gateway/test_parked_route_refusal_discord.pynew file mode 100644index 00000000000..b0d75247acd--- /dev/null+++ b/tests/gateway/test_parked_route_refusal_discord.py@@ -0,0 +1,60 @@+"""A parked-profile refusal on Discord is an outage notice: it never hides the message from backfill.++Discord's missed-message backfill re-dispatches an input that has no substantive bot reply, and skips+the replies it recognises as outage notices (``_is_down_notice_content``). The refusal replies to the+input it refuses, so unless it reads as an outage notice, the never-admitted message counts as+answered and is not picked up after the profile is served again.+"""+import asyncio+from types import SimpleNamespace+from unittest.mock import AsyncMock++import pytest++from gateway.parked_route_refusal import drop_rejected_route+from tests.gateway import test_discord_missed_message_backfill as discord_tests++adapter = discord_tests.adapter+++def _replying_channel(adapter, monkeypatch):+ """``(channel, message)``: the real ``adapter.send`` puts its reply to *message* in the history."""+ channel = discord_tests.FakeChannel()+ message = discord_tests.make_message(channel=channel)++ async def send(*, content, reference, **_kwargs):+ reply = SimpleNamespace(id=100 + len(channel._history_messages), content=content,+ author=adapter._client.user, reference=SimpleNamespace(message_id=message.id))+ channel._history_messages.append(reply)+ return reply++ channel.send = send+ monkeypatch.setattr(adapter, '_resolve_channel', AsyncMock(return_value=channel))+ monkeypatch.setattr(adapter, '_reply_reference_for_send', lambda *a: SimpleNamespace(message_id=message.id))+ return channel, message+++async def test_a_parked_profile_refusal_leaves_the_message_to_backfill(adapter, monkeypatch):+ channel, message = _replying_channel(adapter, monkeypatch)+ assert await adapter._should_backfill_discord_message(message)+ adapter.gateway_runner = SimpleNamespace(+ session_runtime_descriptor={'parked_profiles': {'beta': 'test park'}},+ _thread_metadata_for_source=lambda source: None)+ source = adapter.build_source('123', chat_type='group', user_id='42', message_id='1')+ source._rejected_route_profile = 'beta'+ drop_rejected_route(adapter, source)+ await asyncio.gather(*list(adapter._background_tasks))+ assert len(channel._history_messages) == 1, 'the refusal was not sent'+ assert not adapter._discord_message_is_persistently_complete('1')+ assert await adapter._should_backfill_discord_message(message), (+ f'the refusal reads as an answer, so the never-admitted message is not backfilled: '+ f'{channel._history_messages[0].content!r}')+++async def test_a_real_final_answer_still_completes_the_message(adapter, monkeypatch):+ channel, message = _replying_channel(adapter, monkeypatch)+ result = await adapter.send('123', 'Here is the summary you asked for.', reply_to='1', metadata={'notify': True})+ assert result.success and len(channel._history_messages) == 1+ assert not await adapter._should_backfill_discord_message(message)