On this page

0267. Process manager: plugins/proc supervisor FFI and a daemon over a Unix socket

Context

A TUI process manager needs long-running children: spawn with argv, env and cwd, stream stdout/stderr, signal process groups, restart, and keep running after the UI exits. Tenon programs cannot do this today. cli.Process.run, run_input and stream (ADR-0056, LANGUAGE.md "process") block until the child exits, inherit environ and the parent cwd, and return no handle. Native cwd/env for Process is parked (PLAN.md parking lot, 2026-11-03). plugins/cli and interp* are frozen, so cli.Process cannot grow a handle API now.

The FFI tier already ships trusted shims with generation-checked handles (ADR-0151 pattern; plugins/tty, plugins/sqlite, plugins/wallclock). tty.wait uses select over the terminal, a resize pipe and one Unix feed (plugins/tty/native/tz_tty.h, ADR-0222). Process ownership work exists only compiler-internally (crates/tenon/src/app_test_supervise.rs, ADR-0171, ADR-0172, ADR-0228). The sibling prototype coding-harness/native/hz_agentd.h uses 64 select slots, SIGKILL only, a 100 ms exit poll, no cwd and old hrt_ names.

Decision

  1. Daemon owns services; clients attach. A daemon process owns all children, restart policy, log buffers and one Unix-domain listening socket. The TUI and a headless CLI are clients over that socket. Quitting or crashing the TUI never signals services. The socket is a filesystem path (never a network bind), given explicitly or derived from config, in a directory with mode 0700, socket mode 0600; the daemon checks the peer uid (SO_PEERCRED / getpeereid) and refuses an existing non-socket path. The daemon never opens /dev/tty.

  2. New trusted FFI library plugins/proc. It follows the plugins/tty shape: [ffi] headers = ["native/<shim>.h"], package capabilities ["ffi", "fs"], callers grant ffi and fs and pass an explicit platform witness as tty.open(fs) does. Children, listeners and connections are opaque generation-checked i64 handles; stale handles return errors. Errors are strings, as in tty and wallclock; no E-codes. Linux and macOS only; other platforms fail at compile time. cli.Process is not extended in v1; run/run_input/stream stay the synchronous v0 API, and plugins/proc is the long-running handle API ADR-0056 deferred.

  3. Spawn contract. argv (no shell), an explicit env vector (no implicit inheritance; the app copies named variables with Env.get) and cwd. Each child gets its own process group, non-blocking close-on-exec pipes, default SIGPIPE and an empty signal mask (ADR-0056 refinement). Spawn failures (ENOENT, EACCES, bad cwd) are reported synchronously. There is no implicit shell fallback on ENOEXEC (ADR-0087). PTY spawn is a later addition to the same plugin, not part of the first spawn step.

  4. One native wait per process. proc.wait uses poll(2) (no FD_SETSIZE limit) over child pipes, the listener, accepted connections and a SIGCHLD self-pipe, and returns a readiness list. No timer polling for exits. The daemon's only blocking call is proc.wait. The TUI's only blocking call is tty.wait with the daemon socket as its feed (tty.attach, ADR-0222). No process runs two blocking select loops. ADR-0165's Net.wait is not required.

  5. Group ownership and cleanup. Exit is observed without reaping (waitid with WNOWAIT, the ADR-0171 idea) so the group id stays reserved until group cleanup; then the leader is reaped. Stop is TERM to the group, then KILL after a grace period scheduled by the caller (the shim does not sleep). On daemon exit or handled INT/TERM/HUP, owned groups get TERM, a bounded wait, then KILL; SIGKILL of the daemon cannot clean up. On macOS a group KILL that returns EPERM is accepted only when a group snapshot shows no live member, reusing the ADR-0228 idea in new code.

  6. Service kinds are pure Tenon packages (capabilities = []). A kind maps a spec to argv/env/cwd, a health-probe description and a log-line parser. Kinds do no I/O and have no native code; the daemon executes probes.

  7. Config is JSON decoded with plugins/codec derive. Secrets use a separate procman policy, accepted 2026-11-21: explicit env in config, optional .env files, and a redaction mask applied to log bytes before they enter a ring or reach a client. Agent Host.secret is not reused.

  8. C backend first. Interpreter support comes later through the ADR-0152 FFI host; AGENTS.md backend parity is still required before M19 completes.

  9. Tests. Pure logic (state machine, backoff on a supplied clock, protocol, config, ring buffers) is unit-tested in the 2-minute gate. M19.4 adds a small Rust module (not under interp*) that embeds the pure Tenon core and runs scenarios through the in-process interpreter (interp::run_output): no files, children or real clock. Anything that spawns children, opens sockets or PTYs, or reads the real clock lives in bench/procman/ and PTY checks in the examples/tui/check-live.py style.

  10. App location and CLI, accepted 2026-11-21. The app lives at examples/tools/procman. The command is tenon procman with subcommands serve, attach, start, stop, status and restart.

Alternatives considered

Consequences

The app needs ffi and fs in its capability ceiling; FFI stays trusted and handles are not secrets. The supervisor's C code cannot be exercised by the gate and needs bench and PTY evidence on Linux and macOS (the live TUI was last qualified on macOS C only, plans/tui/VALIDATION.md). tenon interp cannot run the daemon until the FFI-host step lands. Secrets policy, app location, CLI command shape and the in-process gate harness are decided above. Socket path, daemon start, stale groups, HTTP probe transport and first coding agents remain open as Q2–Q6 in plans/procman/PLAN.md.