feat(swarm-mgmt): agent_host + updater opt-in; prevent duplicate forwarder spawn

This commit is contained in:
2026-04-19 05:12:55 -04:00
parent 95ae175e1b
commit e32fdf9cbf
8 changed files with 141 additions and 11 deletions

View File

@@ -86,6 +86,17 @@ def _spawn_detached(argv: list[str], pid_file: Path) -> int:
import os
import subprocess # nosec B404
# If the pid_file points at a live process, don't spawn a duplicate —
# agent/swarmctl auto-spawn is called on every startup, and the first
# run's sibling is still alive across restarts.
if pid_file.exists():
try:
existing = int(pid_file.read_text().strip())
os.kill(existing, 0)
return existing
except (ValueError, ProcessLookupError, PermissionError, OSError):
pass # stale pid_file — fall through and spawn
with open(os.devnull, "rb") as dn_in, open(os.devnull, "ab") as dn_out:
proc = subprocess.Popen( # nosec B603
argv,