0267. Process manager: plugins/proc supervisor FFI and a daemon over a Unix socket
- Status: Accepted (maintainer, 2026-11-21); M19 / procman
- Date: 2026-11-21
- Plan: M19.1–M19.18;
plans/procman/PLAN.md - Review: refines ADR-0056 (long-running handles deferred there); follows ADR-0151, ADR-0221, ADR-0222
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
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.New trusted FFI library
plugins/proc. It follows theplugins/ttyshape:[ffi] headers = ["native/<shim>.h"], package capabilities["ffi", "fs"], callers grantffiandfsand pass an explicit platform witness astty.open(fs)does. Children, listeners and connections are opaque generation-checkedi64handles; stale handles return errors. Errors are strings, as inttyandwallclock; no E-codes. Linux and macOS only; other platforms fail at compile time.cli.Processis not extended in v1;run/run_input/streamstay the synchronous v0 API, andplugins/procis the long-running handle API ADR-0056 deferred.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.One native wait per process.
proc.waitusespoll(2)(noFD_SETSIZElimit) 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 isproc.wait. The TUI's only blocking call istty.waitwith the daemon socket as its feed (tty.attach, ADR-0222). No process runs two blockingselectloops. ADR-0165'sNet.waitis not required.Group ownership and cleanup. Exit is observed without reaping (
waitidwithWNOWAIT, 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.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.Config is JSON decoded with
plugins/codecderive. Secrets use a separate procman policy, accepted 2026-11-21: explicit env in config, optional.envfiles, and a redaction mask applied to log bytes before they enter a ring or reach a client. AgentHost.secretis not reused.C backend first. Interpreter support comes later through the ADR-0152 FFI host; AGENTS.md backend parity is still required before M19 completes.
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 inbench/procman/and PTY checks in theexamples/tui/check-live.pystyle.App location and CLI, accepted 2026-11-21. The app lives at
examples/tools/procman. The command istenon procmanwith subcommandsserve,attach,start,stop,statusandrestart.
Alternatives considered
- Extend
cli.Processwith env/cwd/handles — the cleaner language surface, but it edits frozenplugins/cliandinterp*. Revisit after the freeze with a superseding ADR;plugins/proccan then become its implementation. - One TUI process that owns the children — simpler, but quitting or crashing the UI kills every service.
- Copy
hz_agentd.hverbatim — reference only: 64selectslots, SIGKILL only, 100 ms exit polling, no cwd,hrt_names. - TCP control socket via
cli.net.listen— a network bind with weaker local access control; ADR-0222 already chose Unix transport. - Service kinds as FFI or
call_pluginprocesses — native or out-of-process kinds are not needed to build argv and parse logs.
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.