From 999703fd43ab6d75c4a5c7bc8b610dd73ecece76 Mon Sep 17 00:00:00 2001 From: Kshitij Kapoor Date: Sat, 22 Aug 2026 20:34:45 +0530 Subject: [PATCH] refactor(gateway): hoist watchdog constants to the canonical import; drop dead or-fallbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /simplify-code quality reviewer: _start_loop_liveness_guards re-imported the DEFAULT_LOOP_WATCHDOG_* constants locally although the file's canonical shutdown_watchdog import block already exists, and the 'or DEFAULT' guards re-clamped values GatewayConfig.from_dict already validates — unreachable for config-loaded values. getattr defaults keep the config=None test path working. --- gateway/run.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index de35fc3a0c..ba6a87e487 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -2689,6 +2689,9 @@ from gateway.platforms.base import ( ) from gateway.shutdown_watchdog import ( DEFAULT_HEARTBEAT_INTERVAL_S, + DEFAULT_LOOP_WATCHDOG_INTERVAL_S, + DEFAULT_LOOP_WATCHDOG_MAX_STRIKES, + DEFAULT_LOOP_WATCHDOG_TIMEOUT_S, _arm_loop_floor_timer, arm_shutdown_watchdog, loop_heartbeat_forever, @@ -12349,25 +12352,24 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew watchdog = getattr(self, "_loop_liveness_watchdog", None) if watchdog is None or not watchdog.is_alive(): try: - from gateway.shutdown_watchdog import ( - DEFAULT_LOOP_WATCHDOG_INTERVAL_S as _WD_INTERVAL, - DEFAULT_LOOP_WATCHDOG_MAX_STRIKES as _WD_STRIKES, - DEFAULT_LOOP_WATCHDOG_TIMEOUT_S as _WD_TIMEOUT, + # getattr defaults cover the config=None / bare-object test + # path; config-loaded values are already validated+clamped + # by GatewayConfig.from_dict, so no re-clamping here. + interval = getattr( + config, + "loop_watchdog_probe_interval_s", + DEFAULT_LOOP_WATCHDOG_INTERVAL_S, + ) + timeout = getattr( + config, + "loop_watchdog_probe_timeout_s", + DEFAULT_LOOP_WATCHDOG_TIMEOUT_S, + ) + strikes = getattr( + config, + "loop_watchdog_max_strikes", + DEFAULT_LOOP_WATCHDOG_MAX_STRIKES, ) - - interval = _WD_INTERVAL - timeout = _WD_TIMEOUT - strikes = _WD_STRIKES - if config is not None: - interval = getattr( - config, "loop_watchdog_probe_interval_s", _WD_INTERVAL - ) or _WD_INTERVAL - timeout = getattr( - config, "loop_watchdog_probe_timeout_s", _WD_TIMEOUT - ) or _WD_TIMEOUT - strikes = getattr( - config, "loop_watchdog_max_strikes", _WD_STRIKES - ) or _WD_STRIKES self._loop_liveness_watchdog = start_loop_liveness_watchdog( loop, probe_interval=float(interval),