fix(gateway): disarm the heartbeat writer in _stop_loop_liveness_guards

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 <rafael@amora.com.br>
This commit is contained in:
kshitijk4poor
2026-08-27 20:06:53 +05:30
committed by kshitij
parent b48540701c
commit 8a32baafc5
+14
View File
@@ -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.