From 205fc37c12fe8fc1ffd7d737c41abf8ddf31118f Mon Sep 17 00:00:00 2001 From: Myron Blair Date: Sat, 13 Jun 2026 14:30:20 +0000 Subject: [PATCH] Fix Windows agent: exit(1) after self-update so SCM restarts the service After writing the updated script, _stop_event.set() caused a clean exit (code 0). SCM failure recovery only fires on non-zero exit, so the service stayed down permanently after every auto-update. Fix: set _update_restart=True before signalling stop; SvcDoRun() checks the flag after main() returns and calls sys.exit(1), which triggers the sc.exe failure recovery chain (restart/5s/10s/30s configured at install). --- public_html/agent/jarvis-agent-windows.py | 11 ++++++++--- public_html/agent/jarvis-agent-windows.py.sha256 | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/public_html/agent/jarvis-agent-windows.py b/public_html/agent/jarvis-agent-windows.py index 48369ce..23d6440 100644 --- a/public_html/agent/jarvis-agent-windows.py +++ b/public_html/agent/jarvis-agent-windows.py @@ -38,8 +38,9 @@ LOG_PATH = INSTALL_DIR / "jarvis-agent.log" AGENT_VERSION = "3.1" # Set by the service wrapper so self_update knows to stop instead of exec -_is_service = False -_stop_event = threading.Event() +_is_service = False +_stop_event = threading.Event() +_update_restart = False # True when stopping for self-update; triggers SCM restart # ── Logging ──────────────────────────────────────────────────────────────────── @@ -420,7 +421,8 @@ def self_update(cfg: dict) -> bool: with open(script_path, "wb") as f: f.write(new_content) if _is_service: - # Signal the main loop to exit; SCM failure-recovery will restart us + global _update_restart + _update_restart = True log("Running as service — stopping for SCM-managed restart after update.") _stop_event.set() else: @@ -590,6 +592,9 @@ if _HAS_WIN32: (self._svc_name_, ""), ) main() + if _update_restart: + # Non-zero exit triggers SCM failure recovery → automatic restart + sys.exit(1) if __name__ == "__main__": diff --git a/public_html/agent/jarvis-agent-windows.py.sha256 b/public_html/agent/jarvis-agent-windows.py.sha256 index e415c83..2750c62 100644 --- a/public_html/agent/jarvis-agent-windows.py.sha256 +++ b/public_html/agent/jarvis-agent-windows.py.sha256 @@ -1 +1 @@ -974c117db29ae2cc417cf70046af32a688037b887bb08b17a18b1a0be37dec6f +224a634375b5d49ccc0a012e0e122ade5f8a1302615450dffbf9a03eac6b7a19