From 8a32baafc5b411a3524f44fc51209e6c7592084e Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 27 Aug 2026 20:06:53 +0530 Subject: [PATCH] fix(gateway): disarm the heartbeat writer in _stop_loop_liveness_guards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ported from #95808 (@rtcopenclawgh, closed as duplicate of this PR): once shutdown starts loading the loop, a heartbeat task that keeps refreshing state/gateway.heartbeat can make a draining gateway look healthy to external probes. Cancel it alongside the watchdog and floor timer. The other additive piece in #95808 — passing a confirm_s confirmation window at the update_cmd.py probe call sites — is not needed here: this PR's probe_gateway_loop_liveness already builds the sustained window in (tick_strikes=3 consecutive socket misses), so every caller gets it without a new parameter. Co-authored-by: rtcopenclawgh --- gateway/run.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gateway/run.py b/gateway/run.py index fe57a98f7a..e85cd3b0e0 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -12692,6 +12692,20 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew except Exception: logger.debug("Failed to cancel gateway loop floor timer", exc_info=True) + # Also disarm the heartbeat writer task itself (ported from #95808): + # once shutdown starts loading the loop, a heartbeat that keeps + # refreshing the file can make a draining gateway look healthy to + # external probes. Cancel is idempotent; the task is also in + # _background_tasks so this is belt-and-braces ordering, not new + # lifecycle. + heartbeat = getattr(self, "_loop_heartbeat_task", None) + self._loop_heartbeat_task = None + if heartbeat is not None: + try: + heartbeat.cancel() + except Exception: + logger.debug("Failed to cancel gateway loop heartbeat task", exc_info=True) + async def _consume_clean_shutdown_marker(self, marker_path) -> int: """Discard orphan turn markers before consuming a clean-exit receipt.