feat(autonomous-release): add dormant Candidate worker
This commit is contained in:
+69
@@ -0,0 +1,69 @@
|
||||
"""Dormant Candidate worker supervisor.
|
||||
|
||||
Provider clients are injected by the external management plane. This process
|
||||
never converts a missing projection into a simulated native identity.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import signal
|
||||
import threading
|
||||
|
||||
|
||||
def write_status(directory: Path) -> None:
|
||||
directory.mkdir(parents=True, exist_ok=True, mode=0o750)
|
||||
if directory.is_symlink():
|
||||
raise RuntimeError("worker state directory symlink rejected")
|
||||
payload = {
|
||||
"status": "dormant",
|
||||
"task_plane_execution_enabled": os.environ.get(
|
||||
"AIOS_TASK_PLANE_EXECUTION_ENABLED", "false"
|
||||
).lower()
|
||||
== "true",
|
||||
"gitops_writes_enabled": os.environ.get("AIOS_GITOPS_WRITES_ENABLED", "false").lower()
|
||||
== "true",
|
||||
"production_side_effects": False,
|
||||
"secrets_included": False,
|
||||
}
|
||||
temporary = directory / f"worker-status.{os.getpid()}.new"
|
||||
target = directory / "worker-status.json"
|
||||
if temporary.is_symlink() or target.is_symlink():
|
||||
raise RuntimeError("worker status symlink rejected")
|
||||
descriptor = os.open(
|
||||
temporary,
|
||||
os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_NOFOLLOW", 0),
|
||||
0o640,
|
||||
)
|
||||
try:
|
||||
os.write(descriptor, (json.dumps(payload, sort_keys=True) + "\n").encode("utf-8"))
|
||||
os.fsync(descriptor)
|
||||
finally:
|
||||
os.close(descriptor)
|
||||
os.replace(temporary, target)
|
||||
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--state-directory", required=True, type=Path)
|
||||
return parser
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
args = build_parser().parse_args(argv)
|
||||
if os.environ.get("AIOS_PRODUCTION_DEPLOYMENT_ENABLED", "false").lower() == "true":
|
||||
raise RuntimeError("Candidate worker refuses production deployment mode")
|
||||
write_status(args.state_directory)
|
||||
stopping = threading.Event()
|
||||
signal.signal(signal.SIGTERM, lambda *_: stopping.set())
|
||||
signal.signal(signal.SIGINT, lambda *_: stopping.set())
|
||||
while not stopping.wait(5):
|
||||
write_status(args.state_directory)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user