From 44eeef9a83705b60ac28704a3ce0f4ab35113f6f Mon Sep 17 00:00:00 2001 From: Kshitij Kapoor Date: Sat, 22 Aug 2026 20:29:57 +0530 Subject: [PATCH] fix(gateway): apply startup-watchdog config to the already-armed handle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /simplify-code quality+efficiency reviewers (converged, verified): on the standard 'hermes gateway run' path the argv fast-path arms BEFORE run_gateway's config bridge executes, and arm_startup_watchdog() is idempotent — so gateway.startup_watchdog: false and startup_watchdog_timeout_seconds were dead knobs (env bridged, live handle untouched). run_gateway now applies the config to the live handle: disarm on disable; disarm+re-arm on a bridged config timeout so the fresh handle covers the remaining pre-loop startup with the configured deadline. config_defaults comment updated to match reality. E2E (real module, fast-path armed first): disable path disarms the live handle; timeout path re-arms a fresh handle at 123s. --- hermes_cli/config_defaults.py | 10 ++++++---- hermes_cli/gateway.py | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.py index 8ee4e5c931..be5b02fdcd 100644 --- a/hermes_cli/config_defaults.py +++ b/hermes_cli/config_defaults.py @@ -3226,10 +3226,12 @@ DEFAULT_CONFIG = { # Startup-liveness watchdog (OOF-298): plain daemon thread armed at # process entry for gateway runs, hard-exits 75 if the event loop is # not confirmed live within the deadline. The watchdog module itself - # is stdlib-only and armed before config can load, so these keys are - # BRIDGED to the internal HERMES_STARTUP_WATCHDOG / - # HERMES_STARTUP_WATCHDOG_TIMEOUT_S env vars by the gateway - # launchers — config.yaml is the user-facing surface. + # is stdlib-only and armed before config can load, so run_gateway() + # bridges these keys to the internal HERMES_STARTUP_WATCHDOG / + # HERMES_STARTUP_WATCHDOG_TIMEOUT_S env vars AND applies them to the + # already-armed handle (disarm on disable, disarm+re-arm on a config + # timeout) — config.yaml is the user-facing surface; explicit env + # values win as operator override. "startup_watchdog": True, "startup_watchdog_timeout_seconds": 300, diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py index d81ff4bfe0..2d10dc4d13 100644 --- a/hermes_cli/gateway.py +++ b/hermes_cli/gateway.py @@ -6453,12 +6453,24 @@ def run_gateway(verbose: int = 0, quiet: bool = False, replace: bool = False, fo # gateway.startup_watchdog_timeout_seconds); the env vars are the # internal bridge, needed because the argv fast-path arms before config # can load. Explicit env values (operator override) are respected. + # + # The argv fast-path has ALREADY armed on the standard `hermes gateway + # run` path by the time this runs, and arm_startup_watchdog() is + # idempotent (returns the live handle without re-reading env). So the + # bridge alone is not enough: apply the config to the live handle — + # disarm when disabled, disarm+re-arm when a config timeout should + # replace the fast-path default. Re-arming is safe here: the heavy + # import graph the fast-path guards is behind us, and the fresh handle + # covers the remaining pre-loop startup with the configured deadline. try: from hermes_startup_watchdog import ( ENV_STARTUP_WATCHDOG, ENV_STARTUP_WATCHDOG_TIMEOUT_S, arm_startup_watchdog, + disarm_startup_watchdog, + startup_watchdog_disabled, ) + _sw_timeout_bridged = False try: from hermes_cli.config import load_config as _sw_load_config _gw_cfg = (_sw_load_config() or {}).get("gateway", {}) or {} @@ -6472,9 +6484,17 @@ def run_gateway(verbose: int = 0, quiet: bool = False, replace: bool = False, fo and _sw_timeout is not None ): os.environ[ENV_STARTUP_WATCHDOG_TIMEOUT_S] = str(_sw_timeout) + _sw_timeout_bridged = True except Exception: pass - arm_startup_watchdog() + if startup_watchdog_disabled(): + disarm_startup_watchdog() + else: + if _sw_timeout_bridged: + # A config timeout must beat the fast-path default that an + # already-armed handle resolved before config was readable. + disarm_startup_watchdog() + arm_startup_watchdog() except Exception: pass