fix(#41662): Windows gateway watchdog for automatic respawn on crash - #41761
fix(#41662): Windows gateway watchdog for automatic respawn on crash#41761iamlukethedev wants to merge 1 commit into
Conversation
|
Thanks for tackling the Windows cron continuity gap. The premise remains valid: current main starts the default cron provider in the gateway as a daemon thread ( Problems
Suggested changes
Automated hermes-sweeper review. |
…atchdog Add a profile-scoped Windows watchdog that preserves cron continuity after a hard gateway crash while honoring intentional stops and uninstalls. - Schedule periodic ticks through Task Scheduler XML + wscript/VBS, never cmd.exe, preserving the existing windowless launcher invariant. - Use IgnoreNew plus a waiting tick launcher to prevent overlapping checks. - Start a hidden long-lived watchdog loop from the Startup-folder fallback, covering machines where Scheduled Task installation is unavailable. - Preserve HERMES_HOME, VIRTUAL_ENV, PYTHONPATH, and detached-launch env parity. - Honor gateway_state=stopped, recheck liveness before spawning, and exit the fallback loop when gateway persistence is uninstalled. - Remove watchdog tasks/scripts during uninstall and report watchdog state in normal/deep status output. - Add behavior tests for crash respawn, healthy/no-op, planned stop, uninstall, VBS/XML launcher behavior, fallback installation, cleanup, and status. The stale execute-code RPC commits from the original branch are intentionally excluded; current main already contains that functionality.
920a35a to
f97b0f3
Compare
|
Reworked against current Security / scope audit
Windows lifecycle rework
TestsReplaced the Local verification:
|
|
Closing as implemented-on-main: since #45610 ( The external-watchdog direction was the right call when this was filed, and thank you for the thorough work on both the Scheduled Task and Startup-fallback paths. As-written it now conflicts with the rewritten |
Summary
Implements a Windows Scheduled Task watchdog that automatically respawns the gateway when it crashes, ensuring cron jobs continue to fire.
Issue: On Windows, the gateway runs the cron scheduler as an internal daemon thread. When the gateway crashes, cron stops firing. There is no systemd Restart=on-failure equivalent on Windows.
Solution: A separate watchdog Scheduled Task that:
get_running_pid()Changes
New Files
hermes_cli/gateway_watchdog.py (181 lines)
pythonw -m hermes_cli.gateway_watchdog [--profile X]tests/hermes_cli/test_gateway_watchdog.py (108 lines)
Modified Files
_get_watchdog_task_name()— per-profile task naming_get_watchdog_script_path()— watchdog .cmd file path_build_watchdog_cmd_script()— generates cmd wrapper_write_watchdog_script()— writes cmd file to disk_install_watchdog_task()— creates Scheduled Task (/SC MINUTE /MO 2)install()integration — auto-installs watchdog after gateway taskHow It Works
Installation
When users run
hermes gateway install --system:Runtime (every 2 minutes)
pythonw gateway-watchdog.cmdgateway_watchdog.main()calls_gateway_is_alive()_gateway_is_alive()usesget_running_pid(cleanup_stale=False)_respawn()callsgateway_windows._spawn_detached()Result
✓ Cron jobs continue firing even after gateway crashes (max 2-minute downtime)
✓ No manual intervention required
✓ No architecture changes needed
Design Decisions
Why every 2 minutes?
Why pythonw.exe?
Why CREATE_BREAKAWAY_FROM_JOB?
Why separate .cmd script?
Why file logging?
Testing
✅ Both modules compile without errors
✅ gateway_watchdog imports and --help works
✅ All 5 new gateway_windows functions exist
✅ Watchdog task naming verified (per-profile isolation)
✅ Script path isolation confirmed
✅ Cmd script structure validated
✅ 7 test cases created and compiling
Integration
✓ Uses existing
get_running_pid()from gateway/status.py✓ Uses existing
_spawn_detached()from gateway_windows✓ Uses existing CREATE_BREAKAWAY_FROM_JOB flag
✓ Follows existing gateway_windows.py patterns and conventions
✓ No breaking changes
✓ No changes to other modules
What's Next
The watchdog is automatically installed during
hermes gateway install --system.Users who have already installed can force re-installation with:
Fixes #41662