0012: A process supervisor that owns process trees
- Status: Proposed (implemented in Phase 2, task 003)
- Date: 2026-12-05
Context
Language servers were started with std::process::Command and stopped with Child::kill, which kills only the direct child. Servers such as rust-analyzer start their own children (proc-macro servers, cargo), which could outlive the IDE. Drop waited on the child on the UI thread, and every inherited environment variable, including tokens, reached the server. Tasks, terminals and debug adapters will need the same lifecycle.
Decision
- Add a UI-independent crate,
ide-process, with no dependency on other IDE crates.ide-languages(and later task and debug code) depends on it; trust stays inide-core. - A typed
ProcessSpec(program, argv, cwd, explicit env, env policy, stdio modes, output bounds, deadline, owner) replaces ad hocCommanduse. No shell. - Own the tree: Unix process groups with
waitid(WNOWAIT)before reaping; Windows job objects through thewin32jobcrate. Platforms without a safe mechanism fail closed. - Monitor and watchdog threads own waiting, reaping and deadlines; callers only signal.
- The LSP manager enforces a hard service limit, treats outstanding requests as leases against idle eviction, and stops services without blocking on workspace switches.
Alternatives considered
- Keep
Child::kill: leaves grandchildren running. - An async runtime (tokio::process): adds a runtime the project deliberately avoids (ADR 0004) and still needs process groups and job objects.
- Write the Windows job-object calls ourselves: requires
unsafe, which the workspace forbids. - Put the supervisor in
ide-core:ide-languagescould not use it without a dependency cycle.
Consequences
- Each supervised process costs two extra lightweight threads (monitor, watchdog) besides the stderr drain.
- Tools that relied on arbitrary environment variables need them added explicitly or through the allowlist.
- Escaping daemons and the Windows assignment race remain documented limits.
Validation
crates/ide-process/tests/supervisor.rs (child and grandchild termination, unrelated process untouched, graceful and forced stop, deadline, noisy output, blocked stdin, environment, shutdown) and crates/ide-languages/tests/lsp_lifecycle.rs; evidence in Phase 2 validation.