Skip to content

The agent that grows with you

fix(gateway): tag a drain refusal of a wake as runtime_draining

kshitijk4poorc33731aacb9d
diff --git a/gateway/wake.py b/gateway/wake.py
index bdb6e7ff374..832eb7a00d2 100644
--- a/gateway/wake.py
+++ b/gateway/wake.py
@@ -103,7 +103,7 @@ async def admit_internal_event(adapter: Any, event: Any) -> None:
# A draining gateway answers new work with a drain notice and discards queued follow-ups,
# so a wake admitted now would never run. Refuse it so the caller keeps it for a retry.
if _runner_draining(adapter):
- raise WakeNotAccepted("gateway is draining; retry after restart")
+ raise WakeNotAccepted("gateway is draining; retry after restart", reason="runtime_draining")
await adapter.handle_message(event)
if event._gateway_accepted is not True:
raise WakeNotAccepted()
@@ -112,7 +112,8 @@ async def admit_internal_event(adapter: Any, event: Any) -> None:
# dooms the stored event: the drain gate refuses the claimed turn and the queued follow-up
# is discarded. Refuse it so the producer retries it after the restart.
if _runner_draining(adapter):
- raise WakeNotAccepted("gateway began draining during admission; retry after restart")
+ raise WakeNotAccepted("gateway began draining during admission; retry after restart",
+ reason="runtime_draining")
def _runner_draining(adapter: Any) -> bool:
diff --git a/tests/gateway/test_wake_during_restart_drain.py b/tests/gateway/test_wake_during_restart_drain.py
index a81fcc4820c..d34a12a15bd 100644
--- a/tests/gateway/test_wake_during_restart_drain.py
+++ b/tests/gateway/test_wake_during_restart_drain.py
@@ -106,8 +106,9 @@ async def test_wake_for_a_busy_session_is_refused_while_draining():
asyncio.Event()
) # a turn is still running in this chat
runner._draining = True
- with pytest.raises(WakeNotAccepted):
+ with pytest.raises(WakeNotAccepted) as refused:
await deliver_wake(adapter, text="[kanban] Task t_1 completed.", source=source)
+ assert refused.value.reason == "runtime_draining" and not refused.value.permanent
assert key not in adapter._pending_messages # would be discarded when the turn ends
@@ -129,8 +130,9 @@ async def test_wake_is_refused_when_drain_starts_during_admission():
assert await asyncio.to_thread(entered.wait, 5)
runner._draining = True # /restart begins while admission is parked
release.set()
- with pytest.raises(WakeNotAccepted):
+ with pytest.raises(WakeNotAccepted) as refused:
await admission
+ assert refused.value.reason == "runtime_draining"
await drain(adapter)
assert turns == []