Skip to content

The agent that grows with you

fix: suppress stale "Still working..." heartbeats during gateway restart

nightq0fc3cbac5915
diff --git a/gateway/run_shutdown.py b/gateway/run_shutdown.py
index 78ed9bddd96..845ae0ce219 100644
--- a/gateway/run_shutdown.py
+++ b/gateway/run_shutdown.py
@@ -1077,6 +1077,10 @@ class GatewayShutdownMixin:
"""
if agent is None or (executor_task is not None and executor_task.done()):
return False
+ # Drain/restart already told the chat the task will be interrupted; a "still working"
+ # heartbeat after that notice reads as a contradiction (#10990).
+ if getattr(self, "_draining", False) or getattr(self, "_restart_requested", False):
+ return False
if session_key:
_hb_state = self._peek_session_state(session_key)
if (_hb_state.turn.agent if _hb_state else None) is not agent:
diff --git a/tests/gateway/test_busy_session_ack.py b/tests/gateway/test_busy_session_ack.py
index f28d847a9e4..b4d01fb606d 100644
--- a/tests/gateway/test_busy_session_ack.py
+++ b/tests/gateway/test_busy_session_ack.py
@@ -518,4 +518,17 @@ class TestLongRunningNotificationOwnership:
"sess", original_agent, executor_task=None
) is False
+ @pytest.mark.parametrize("flag", ["_draining", "_restart_requested"])
+ def test_notification_stops_once_shutdown_or_restart_begins(self, flag):
+ """After the restart/shutdown notice a heartbeat would contradict it (#10990)."""
+ from gateway.run import GatewayRunner
+
+ runner = object.__new__(GatewayRunner)
+ runner._running_agents = {}
+ agent = MagicMock()
+ runner._running_agents["sess"] = agent
+ assert runner._should_emit_long_running_notification("sess", agent, executor_task=None) is True
+ setattr(runner, flag, True)
+ assert runner._should_emit_long_running_notification("sess", agent, executor_task=None) is False
+