pub fn spawn_tracked(
reap_tx: &Sender<Reaped>,
spawn_fn: impl FnOnce() -> Result<Subagent>,
) -> Result<Subagent>Expand description
Spawn a supervised child and register its pid → reap_tx atomically with
the fork (both under the routes lock), so the reaper can never waitpid a
child before it is registered. spawn_fn does the fork and returns the
Subagent whose pid() is the registry key.
The lock is held across all of spawn_fn — the fork, the first-frame payload
write, and the reader-thread spawn — so concurrent supervisors briefly
serialize on each spawn (bounded by child startup; the child drains its stdin
pipe within a few ms of exec). This is far cheaper than the retired
SUPERVISE_LOCK (held for a whole run, possibly seconds); moving the payload
write outside the lock is a possible follow-on if spawn contention is ever
measured to matter.