0056. Subprocess v0
- Status: Accepted
- Date: 2026-10-31
- Plan: M6.5, M10.4
- Review: Subprocesses and pipes; extends ADRs 0005/0050/0051
Context
CLI tools need child processes without ambient authority or implicit shell parsing. Capturing one pipe before the other can deadlock on large output.
Decision
Expose only
Process.run(str, vec<str>) -> result<Output, CliError>
and
Process.stream(str, vec<str>) -> result<i64, CliError>
through cli.process. Seed
Output { status: i64, stdout: bytes, stderr: bytes }.
Use posix_spawnp with PATH lookup and locally
declared environ, never a shell. Capture uses
/dev/null stdin and polls both output pipes until
EOF, allocating raw bytes in the caller's region. Internal
descriptors are close-on-exec and above stdio; file capabilities
must also use O_CLOEXEC when implemented. Stream
flushes stdout first, then inherits stdin/stdout/stderr. Wait
retries EINTR; normal status is the exit code, signalled status is
128 plus the signal. The interpreter uses
std::process::Command, wait_with_output
for capture, inherited stdio for stream, and flushes
Host.out before streaming.
Review refinement: children start with default SIGPIPE, even
when the parent inherited SIG_IGN. C uses
posix_spawnattr_setsigdefault with SIGPIPE and
POSIX_SPAWN_SETSIGDEF, matching Rust Command.
Inheriting ignored SIGPIPE would make native and interpreter child
behavior disagree. Capture allocation failures (including
overflow, reservation, commit and budget exhaustion) close the
pipes, kill and reap the owned child before reporting the OOM
trap.
Platform operations return a raw status record; shared lowering
constructs the language result and error text. ENOENT becomes
NotFound("no such program: x"), EACCES becomes
Denied("permission denied: x"), other failures become
Io("spawn x: os error N"). Embedded NUL in
command/arguments is EINVAL; empty arguments are preserved. Child
nonzero status is success, not CliError. Output remains bytes,
including NUL and invalid UTF-8. ProcessRun(layout)
is Fresh; normal arena escape placement applies to captured
output/error messages. E0910 teaches vec
Alternatives considered
- Shell command string — implicit quoting and
expansion obscure argument boundaries. Explicit
/bin/shwith-cremains an ordinary executable call. - Handle-based spawn/wait API — adds child ownership and pipe lifetimes beyond the synchronous v0 scope.
- Sandbox now — M10.4 supplies OS profiles; v0 children are unsandboxed.
Consequences
Only a passed Process capability grants subprocess access. Capture cannot read parent stdin and has no cross-pipe ordering guarantee. Stream inherits actual process descriptors; interpreter memory Hosts only supply the pre-spawn flush. Captured output is bounded by the arena budget, like other fresh allocations. No dependencies, Rust unsafe, or shell fallback are required.