fix(gateway): answer a message refused by a restart drain with the restarting notice
During a restart's after-turn wait the session authority refuses every new messaging input with runtime_draining. admit_message re-raised it, so the sender got the generic "Something went wrong ... /retry" turn error (the traceback in #152410). It now returns the same drain notice the in-process path gives; nothing is committed either way. The wedged-restart half of #152410 is the configured agent.restart_after_turn_timeout cap (default 1800s): live, the wait times out, stop() interrupts the hung provider wait and the process exits 75 without a manual kill. Fixes #152410
This commit is contained in:
@@ -57,6 +57,12 @@ async def admit_message(authority, event):
|
||||
named = f'{exc.reason}: {exc.field}' if exc.field in _CONTENT_CLAUSES else exc.reason
|
||||
return (f'⚠️ Hermes refused this message ({named}), so it was not saved '
|
||||
'or answered. Ask the operator to check gateway.log.')
|
||||
runner = authority.runner
|
||||
if exc.reason == 'runtime_draining' and runner._draining:
|
||||
# A restart's after-turn wait or a stop refused it before commit: the same notice the
|
||||
# in-process path gives, not a turn error that offers a /retry into the drain (#152410).
|
||||
from agent.i18n import t
|
||||
return t('gateway.busy.drain_rejected_new_work', action=runner._status_action_gerund())
|
||||
if exc.reason != 'queue_full':
|
||||
raise
|
||||
# Nothing was committed (main's busy-queue cap): say so instead of a generic turn error.
|
||||
|
||||
29
tests/gateway/test_restart_wait_messaging_drain_notice.py
Normal file
29
tests/gateway/test_restart_wait_messaging_drain_notice.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""A chat message refused by a restart's after-turn wait is answered with the drain notice.
|
||||
|
||||
While ``request_restart`` holds the gateway in ``draining`` for an in-flight turn (up to
|
||||
``agent.restart_after_turn_timeout``), the session authority's admission gate refuses every new
|
||||
messaging input with ``runtime_draining`` (#152410). That refusal must reach the sender as the same
|
||||
"Gateway is restarting" notice the in-process path gives, not escape ``_handle_message`` as an
|
||||
exception the adapter turns into the generic "Something went wrong… /retry" turn error. Real
|
||||
GatewayRunner, DiscordAdapter and SessionAuthority over SQLite.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.gateway.test_wake_during_restart_drain_authority import admissions, authority_route
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_message_during_restart_wait_gets_the_drain_notice_not_a_turn_error(monkeypatch):
|
||||
from agent.i18n import t
|
||||
from gateway.platforms.event import MessageEvent
|
||||
|
||||
executed = []
|
||||
runner, _adapter, authority, source = await authority_route(monkeypatch, executed)
|
||||
runner._restart_requested = True
|
||||
runner._draining = True # request_restart: refusing new turns while the in-flight one finishes
|
||||
|
||||
reply = await runner._handle_message(MessageEvent(text="are you there?", source=source, message_id="B"))
|
||||
|
||||
assert reply == t("gateway.busy.drain_rejected_new_work", action=runner._status_action_gerund())
|
||||
assert executed == [] and admissions(runner, authority, source) == [] # nothing half-admitted
|
||||
Reference in New Issue
Block a user