fix(gateway): apply startup-watchdog config to the already-armed handle

/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.
This commit is contained in:
Kshitij Kapoor
2026-08-22 20:29:57 +05:30
committed by Teknium
parent d2c3c38e98
commit 44eeef9a83
2 changed files with 27 additions and 5 deletions
+6 -4
View File
@@ -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,
+21 -1
View File
@@ -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