The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep loop-watchdog default at 3 strikes; dedupe constants; register knobs in config defaults
Kshitij Kapoor361614572373
diff --git a/gateway/config.py b/gateway/config.pyindex b681c1e10ca..ecf229694a2 100644--- a/gateway/config.py+++ b/gateway/config.py@@ -18,6 +18,11 @@ from enum import Enumfrom hermes_cli.config import get_hermes_homefrom agent.secret_scope import current_secret_scope, get_secret as _get_secret+from gateway.shutdown_watchdog import (+ DEFAULT_LOOP_WATCHDOG_INTERVAL_S,+ DEFAULT_LOOP_WATCHDOG_MAX_STRIKES,+ DEFAULT_LOOP_WATCHDOG_TIMEOUT_S,+)from utils import is_truthy_valuelogger = logging.getLogger(__name__)@@ -993,13 +998,15 @@ class GatewayConfig:# the full tolerance window) still escalates to a supervised restart.loop_watchdog: bool = True# Seconds the watchdog waits between liveness probes.- loop_watchdog_probe_interval_s: float = 30.0+ loop_watchdog_probe_interval_s: float = DEFAULT_LOOP_WATCHDOG_INTERVAL_S# Seconds a single probe may go unprocessed before it counts as a miss.- loop_watchdog_probe_timeout_s: float = 10.0+ loop_watchdog_probe_timeout_s: float = DEFAULT_LOOP_WATCHDOG_TIMEOUT_S# Consecutive missed probes allowed before the watchdog hard-exits.- # Default raised from 3 to 8: a transient reconnect stall (~60-120s) is- # tolerated while a genuine multi-minute wedge still escalates.- loop_watchdog_max_strikes: int = 8+ # Default stays at 3 (~90-120s of sustained loop block): the transient+ # false-positive class (the watchdog's own on-loop heartbeat fsync)+ # is fixed at the root by the off-loop write + two-witness probe, so+ # raising this fleet-wide would only delay genuine-wedge recovery.+ loop_watchdog_max_strikes: int = DEFAULT_LOOP_WATCHDOG_MAX_STRIKES# Unauthorized DM policyunauthorized_dm_behavior: str = "pair" # "pair" or "ignore"@@ -1230,26 +1237,26 @@ class GatewayConfig:data.get("loop_watchdog_probe_interval_s")if "loop_watchdog_probe_interval_s" in dataelse nested_gateway.get("loop_watchdog_probe_interval_s"),- 30.0,+ DEFAULT_LOOP_WATCHDOG_INTERVAL_S,)loop_watchdog_probe_timeout_s = _coerce_float(data.get("loop_watchdog_probe_timeout_s")if "loop_watchdog_probe_timeout_s" in dataelse nested_gateway.get("loop_watchdog_probe_timeout_s"),- 10.0,+ DEFAULT_LOOP_WATCHDOG_TIMEOUT_S,)loop_watchdog_max_strikes = _coerce_int(data.get("loop_watchdog_max_strikes")if "loop_watchdog_max_strikes" in dataelse nested_gateway.get("loop_watchdog_max_strikes"),- 8,+ DEFAULT_LOOP_WATCHDOG_MAX_STRIKES,)if loop_watchdog_probe_interval_s < 1.0:- loop_watchdog_probe_interval_s = 30.0+ loop_watchdog_probe_interval_s = DEFAULT_LOOP_WATCHDOG_INTERVAL_Sif loop_watchdog_probe_timeout_s < 1.0:- loop_watchdog_probe_timeout_s = 10.0+ loop_watchdog_probe_timeout_s = DEFAULT_LOOP_WATCHDOG_TIMEOUT_Sif loop_watchdog_max_strikes < 1:- loop_watchdog_max_strikes = 8+ loop_watchdog_max_strikes = DEFAULT_LOOP_WATCHDOG_MAX_STRIKESif multiplex_profiles is None and isinstance(nested_gateway, dict):# Also honor gateway.multiplex_profiles written by# ``hermes config set gateway.multiplex_profiles true``.diff --git a/gateway/run.py b/gateway/run.pyindex 8591dd39533..de35fc3a0c8 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -12349,19 +12349,25 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatewwatchdog = getattr(self, "_loop_liveness_watchdog", None)if watchdog is None or not watchdog.is_alive():try:- interval = 30.0- timeout = 10.0- strikes = 8+ 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,+ )++ interval = _WD_INTERVAL+ timeout = _WD_TIMEOUT+ strikes = _WD_STRIKESif config is not None:interval = getattr(- config, "loop_watchdog_probe_interval_s", 30.0- ) or 30.0+ config, "loop_watchdog_probe_interval_s", _WD_INTERVAL+ ) or _WD_INTERVALtimeout = getattr(- config, "loop_watchdog_probe_timeout_s", 10.0- ) or 10.0+ config, "loop_watchdog_probe_timeout_s", _WD_TIMEOUT+ ) or _WD_TIMEOUTstrikes = getattr(- config, "loop_watchdog_max_strikes", 8- ) or 8+ config, "loop_watchdog_max_strikes", _WD_STRIKES+ ) or _WD_STRIKESself._loop_liveness_watchdog = start_loop_liveness_watchdog(loop,probe_interval=float(interval),diff --git a/gateway/shutdown_watchdog.py b/gateway/shutdown_watchdog.pyindex 107a181cef2..13d61af4d79 100644--- a/gateway/shutdown_watchdog.py+++ b/gateway/shutdown_watchdog.py@@ -48,12 +48,13 @@ DEFAULT_HEARTBEAT_INTERVAL_S = 30.0DEFAULT_LOOP_FLOOR_TIMER_INTERVAL_S = 5.0DEFAULT_LOOP_WATCHDOG_INTERVAL_S = 30.0DEFAULT_LOOP_WATCHDOG_TIMEOUT_S = 10.0-# Raised from 3 to 8 (kanban t_70483f23): tolerate transient, self-recovering-# event-loop stalls during Telegram/Discord reconnect (sync socket I/O on a-# network blip) so a short block does not force exit code 75. A genuine-# multi-minute wedge still escalates. Tuned via gateway.loop_watchdog_* in-# config.yaml when the default is too loose or too tight for a deployment.-DEFAULT_LOOP_WATCHDOG_MAX_STRIKES = 8+# 3 sustained misses (~90-120s of loop block) escalate. The false-positive+# class that motivated raising this (the watchdog's own on-loop heartbeat+# fsync stalling the loop it monitors) is fixed at the root by the off-loop+# heartbeat write + two-witness probe (#90502), so the default stays tight+# for genuine wedges. Deployments with legitimately slow loops can tune via+# gateway.loop_watchdog_* in config.yaml.+DEFAULT_LOOP_WATCHDOG_MAX_STRIKES = 3_HEARTBEAT_RELATIVE = ("state", "gateway.heartbeat")_WATCHDOG_DUMP_RELATIVE = ("logs", "gateway-shutdown-watchdog.log")diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex 2de95403071..34f502d8404 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -2919,6 +2919,16 @@ DEFAULT_CONFIG = {# of leaving a wedged-but-alive zombie. Set to false to disable."loop_watchdog": True,+ # Loop-liveness watchdog tuning (defaults mirror+ # gateway/shutdown_watchdog.py constants). probe_interval = seconds+ # between liveness probes; probe_timeout = seconds a probe may go+ # unprocessed before counting as a miss; max_strikes = consecutive+ # misses before the watchdog hard-exits 75 for a service respawn+ # (~90-120s of sustained loop block at the defaults).+ "loop_watchdog_probe_interval_s": 30.0,+ "loop_watchdog_probe_timeout_s": 10.0,+ "loop_watchdog_max_strikes": 3,+# Whether the gateway keeps writing the legacy sessions.json mirror of# its routing index. The primary copy lives in state.db (the# gateway_routing table). Default True for backward compatibility withdiff --git a/tests/gateway/test_loop_liveness_watchdog.py b/tests/gateway/test_loop_liveness_watchdog.pyindex 7d56d1be595..6f38454fe30 100644--- a/tests/gateway/test_loop_liveness_watchdog.py+++ b/tests/gateway/test_loop_liveness_watchdog.py@@ -175,7 +175,7 @@ def test_gateway_config_loop_watchdog_tuning_round_trip():assert default.loop_watchdog is Trueassert default.loop_watchdog_probe_interval_s == 30.0assert default.loop_watchdog_probe_timeout_s == 10.0- assert default.loop_watchdog_max_strikes == 8+ assert default.loop_watchdog_max_strikes == 3# Explicit values round-tripcfg = GatewayConfig.from_dict(@@ -217,7 +217,7 @@ def test_gateway_config_loop_watchdog_tuning_round_trip():)assert clamped.loop_watchdog_probe_interval_s == 30.0assert clamped.loop_watchdog_probe_timeout_s == 10.0- assert clamped.loop_watchdog_max_strikes == 8+ assert clamped.loop_watchdog_max_strikes == 3def test_gateway_runner_liveness_guards_start_and_stop():@@ -247,7 +247,7 @@ def test_gateway_runner_liveness_guards_start_and_stop():loop,probe_interval=30.0,probe_timeout=10.0,- max_strikes=8,+ max_strikes=3,)assert runner._loop_floor_timer_handle is floor_timerassert runner._loop_liveness_watchdog is watchdog