Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-supervisor/blob/main/README.md # spark-supervisor Process supervisor and health monitor for sovereign daemons Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `spark-supervisor / README.md` 199 lines · 13272 bytes Raw Blame History Source # spark-supervisor: aien-supervise AIEN's process supervisor, written in seeded Omega. It runs AIEN services from line-format declaration files: services have no `.service`, `.timer` or `.path` files and no `systemd-run`. One systemd user unit, `tools/aien-supervise.service`, starts the daemon itself at boot (see below). This repository used to hold a Rust daemon. The Rust sources were removed when the Omega supervisor came to Radicle main; they stay in this repository's git history. Nothing in this repository's documents keeps them as an oracle. ## What still depends on systemd on this machine The Spark runs DGX OS (Ubuntu). PID 1 is the distribution's systemd and stays so. aien-supervise calls no systemd program, but two things it relies on come from systemd today: - cgroup delegation. An unprivileged process may only create cgroups and move processes inside a cgroup v2 subtree its user owns. On this machine that subtree is `/sys/fs/cgroup/user.slice/user-UID.slice/user@UID.service`, created and chowned to the user by systemd's user manager at login (controllers `cpu memory pids` delegated). A process started from an ssh login sits in `session-N.scope`, outside that subtree, and cannot move itself in (the common ancestor `user-UID.slice` is root-owned). So the supervisor must be started from a process that already lives inside the delegated subtree; `run-limited` callers from anywhere then reach it over its local socket. - Boot start. One systemd user unit, `tools/aien-supervise.service`, starts the daemon at boot and hands it its delegated cgroup (`Delegate=cpu memory pids`). The route needs no cron line and no other unit: every service is a file in `~/.config/aien-supervise/services`. cgroupfs is rebuilt at every boot, so some boot-time root actor has to create or delegate the subtree; on this machine that actor is systemd. Install: `cp tools/aien-supervise.service ~/.config/systemd/user/ && systemctl --user enable --now aien-supervise`. Moving a service off its own systemd unit: stop the old unit, add `NAME.svc`, `aien-supervise reload`, and once it has run healthy, `systemctl --user disable` the old unit (keep the file for the undo). Until that disable, the old unit still starts at boot as well, and both copies compete for the same port. Once the unit is installed it is the only start route: start and stop the daemon with `systemctl --user start|stop aien-supervise`, not `ensure` or `shutdown` (a daemon started by `ensure` from a login shell sits outside the delegated cgroup, and the unit then refuses to start a second one). Right after a start, requests such as `aien-supervise start NAME` are refused with `daemon not running` until the daemon has written its pid; wait until `aien-supervise status` says `daemon running`. What removes the dependency: a root-owned, one-time setup that creates `/sys/fs/cgroup/aien-supervise.slice` with `cpu memory pids` enabled in its parent and chowns it (and its `cgroup.procs`, `cgroup.subtree_control`) to the operator account; then `AIEN_SUPERVISE_CGROUP` points there and systemd's user manager is no longer involved. Replacing PID 1 itself is a separate, larger change (aienux). ## Parts Program Source Runs as Role `aien-supervise` `om/contract.om`, `om/supervise.om`, `om/limits.om`, `om/limited.om`, `om/services.om` the operator account daemon (`run`), `ensure`, `status`, `start`/`stop`/`restart`, `check`, `reload`, `shutdown`, `run-limited` `aien-supervise-root` `om/root.om` root, via one sudoers rule builds one service's sandbox and execs it; `stop`/`kill` its cgroup; `check` (dry run) `aien-watch` `om/watch.om` the service user, inside the sandbox path trigger for a service's `watch` key `om/lib.om` is shared. `om/syscalls.om` is generated by `tools/gen-syscalls.sh` from `systemd-analyze syscall-filter` and ``; systemd-analyze is used there only as a read-only oracle for group membership, and `tools/gen-syscalls.sh --check` fails on any difference. ## Build ``` OMC=/path/to/omega-mv/seed/out/omc nice -n 19 sh tools/build.sh ``` The script refuses (exit 2) an omc other than the pin: omega-mv `15760b5009f00485ce51669c84d0126ed19fa479`, `seed/out/omc` sha256 `a5613368f427aacd73ebeee16d46f8b3203405711d4de5b860d0cbee11ce4533`. Take that compiler from Radicle storage: `git -C cat-file blob 15760b50:seed/out/omc`. ## Service files Two directories, one line per directive (`key value...`), no quoting: - `~/.config/aien-supervise/services/NAME.svc`: user services, run as the operator account. - `/etc/aien-supervise/services/NAME.svc`: sandboxed services, root-owned, not group/other-writable. `NAME` is 1..32 bytes of `a-z 0-9 -`. The daemon reads the directories when it starts and on `aien-supervise reload` (adds new files, stops services whose file is gone). Key Meaning (systemd equivalent) `exec PATH ARG...` program and arguments; PATH absolute (ExecStart) `type simple\|oneshot` default simple (Type) `restart always\|on-failure\|never` default on-failure; oneshot never; `no` is accepted as `never` (Restart) `backoff MIN MAX` restart delay MIN·2^k seconds, never above MAX, reset after 60 s of uptime (RestartSec) `after NAME...` user services: start only after each named service is running and healthy; stop in reverse order (After, Requires) `health-http PORT PATH` user services: healthy only when `GET PATH` on 127.0.0.1:PORT answers `HTTP/1.x 2..`; without it, healthy = the process is alive `every S` / `delay S` oneshot period and first-run delay (OnCalendar, OnBootSec, Persistent) `timeout S` oneshot run limit: SIGTERM, then SIGKILL after `stoptime` (TimeoutStartSec) `stoptime S` grace between SIGTERM and SIGKILL of the whole process group, default 10 (TimeoutStopSec, KillMode=control-group) `autostart yes\|no` start with the daemon, default yes `log-max BYTES` / `log-keep N` stdout and stderr of the service go to `state/log/NAME.log`, rotated to `NAME.log.1..N` so that no file is ever larger than log-max; default 10 MiB, 3 `env K=V...` user services: the environment is cleared and holds only these (Environment) `dir PATH`, `umask OCTAL`, `nice N` WorkingDirectory, UMask, Nice (0..19, set in Omega) `memory-max BYTES`, `tasks-max N`, `cpu-weight 1..10000` user services: cgroup v2 `memory.max` (with `memory.swap.max` 0 and `memory.oom.group` 1), `pids.max`, `cpu.weight` (MemoryMax, TasksMax, CPUWeight) `watch DIR SUFFIX PERIOD TIMEOUT` run `exec` through `aien-watch` when DIR holds a matching entry Limits fail closed. A user service that declares a limit runs in its own leaf `$AIEN_SUPERVISE_CGROUP/svc-NAME`. The daemon creates the leaf, writes each value and reads it back; the child moves itself into the leaf and reports back before it execs. If any step fails the service is not started, its state is `error` and its status line carries `reason=LIMIT_NOT_APPLIED errno=-N`. A service killed by its memory ceiling shows `LIMIT_OOM_KILLED`. Change trigger: MISSING_IMPLEMENTATION. Restarting a service when its declaration file changes needs inotify, and the pinned compiler has no inotify host words. Every status line says `change-trigger=MISSING_IMPLEMENTATION`. The daemon does not poll the files and runs no timer in its place; `tests/contract.py missing_trigger` checks that an edited file restarts nothing. The compiler change (host words for `inotify_init1`, `inotify_add_watch`, event reads) is a separate omega-mv landing, then a repin here. Sandboxed services (`/etc/aien-supervise/services`) keep the root helper's keys and mechanisms, documented with their per-directive table and probes in docs/MIGRATION.md : `user`, `group`, `groups`, `ro`, `rw`, `hide`, `envfile`, `secret`, `net`, `allow`, `deny`, `net-default`, `listen`, `memory-max`, `memory-swap-max`, `tasks-max`, `cpu-quota`, `nofile`, `namespaces`, `syscalls`, `syscalls-deny`, `syscall-error`, `families`, `mdwe`. Their cgroup is `/sys/fs/cgroup/aien-supervise/NAME`, created by the root helper. ## run-limited ``` aien-supervise run-limited --memory BYTES [--pids N] -- /absolute/CMD ARG... ``` Runs one command under a kernel-enforced memory ceiling (swap 0) and optional process ceiling. The caller connects to the running daemon's socket `state/limited.sock` (mode 0600, peer uid checked with `SO_PEERCRED`). The daemon makes a leaf `job-PID` under its cgroup root, applies and reads back the limits, and runs the command in it with the caller's working directory and the caller's standard input, output and error (opened from the caller's `/proc/PID/fd/0..2`). The command's environment is empty. The leaf is killed and removed afterwards. If the caller goes away, the command's process group is killed. Exit Meaning the command's status the command ran and exited (128+N when it died from signal N) 137 and `LIMIT_OOM_KILLED` on stderr the memory ceiling killed it (`memory.events` `oom_kill` > 0) 125 and `LIMIT_NOT_APPLIED errno=-N` on stderr no daemon, socket refused, or a limit could not be applied: the command did not run 2 usage ## Privilege model The daemon runs as the operator account and holds no privilege. For a sandboxed service it runs `sudo -n /usr/local/libexec/aien-supervise/aien-supervise-root run NAME`. The helper refuses unless real and effective uid are 0 and the arguments are `run|stop|kill|check NAME`; it checks that every path it relies on is root-owned and not group/other-writable; it runs nothing as root except `nft -f` (the service's own table) and `prlimit --pid` (on itself). ``` Defaults!/usr/local/libexec/aien-supervise/aien-supervise-root !use_pty ALL=(root) NOPASSWD: /usr/local/libexec/aien-supervise/aien-supervise-root run *, /usr/local/libexec/aien-supervise/aien-supervise-root stop *, /usr/local/libexec/aien-supervise/aien-supervise-root kill *, /usr/local/libexec/aien-supervise/aien-supervise-root check * ``` ## Install ``` sudo install -d -o root -g root -m 0755 /usr/local/libexec/aien-supervise /etc/aien-supervise /etc/aien-supervise/services sudo install -o root -g root -m 0755 out/aien-supervise-root out/aien-watch /usr/local/libexec/aien-supervise/ install -m 0755 out/aien-supervise ~/.local/bin/aien-supervise ``` Start the daemon from a process inside the delegated subtree (see above), with `AIEN_SUPERVISE_CGROUP` naming a private directory under it, for example `.../user@UID.service/aien-supervise`. State lives in `~/.local/state/aien-supervise/` (`daemon.log`, `log/NAME.log*`, `st/NAME`, `ctl/`, `limited.sock`). `aien-supervise status` prints a daemon line, then one line per service. ## Tests - `sh tests/user.sh`: daemon behaviour without root (restart/backoff, timers, timeout, requests, TERM-to-KILL, environment, rotation, refusals, shutdown). 15 cases. - `python3 tests/contract.py`: cleared environment plus declared variables; always / on-failure / never with bounded backoff; HTTP-health-gated start order, one status line per service and reverse stop; bounded stdout+stderr rotation, grace then process-group kill with no surviving child; the honest missing change trigger; a fake cgroup root that refuses writes (service and `run-limited` both refused, command never run). 6 cases. The test waits on inotify events. - `OMC=... sh tests/limits.sh`: real cgroup v2 under the user's delegated subtree: a child at half the ceiling succeeds, one past it is killed and reported, a fork bomb is held by `pids.max`, pipes and exit status pass through, service limits read back, a service OOM is reported, restart and rotation under a running daemon. Exits 3 (NOT_RUN) when no delegated subtree or delegated tmux server is available. - `OMC=... python3 tests/mutants.py`: 20 source mutants (environment, each restart policy, backoff bound, start order, HTTP health, reverse stop, status line, rotation bound, grace, group kill, missing-trigger marker, explicit reload, fail-closed, memory, pids and cpu writes, OOM marker, exit status); each must make its test fail. - `sudo -n sh tests/sandbox.sh` (root; qualifies the installed helper) and `sh tools/gen-syscalls.sh --check`. ## Host helpers (recorded dependencies) The user-service path uses only Omega host words (`execenv`, `setprio`, cgroup files). The root helper still uses these host programs: Helper Used for Omega successor `/usr/bin/setpriv` uid/gid/groups, no_new_privs, capability drop `setids`, `nonewpriv`, `capdrop` host words `/usr/bin/prlimit` RLIMIT_NOFILE, RLIMIT_RTPRIO on the helper `prlimit` host word (exists at the pin; not yet used by `om/root.om`) `/usr/bin/bwrap` namespaces, binds, seccomp load `unshare`, `mount`, `pivotroot`, `seccomp` host words `/usr/sbin/nft` per-uid network table nfnetlink in Omega `/usr/bin/sudo` the single privilege crossing none planned: the narrow rule is the design ## License Apache-2.0 WITH LLVM-exception. See LICENSE and NOTICE .