Documentation
¶
Overview ¶
Package proc configures spawned commands so that cancelling their context tears down the WHOLE process tree, not just the shell that Go directly forked.
Every agent (and every auth/doctor helper) runs as `bash -lc <cmd>`. On ctx cancel or timeout the os/exec default kills only that bash parent, orphaning the real grandchild it spawned — node/claude/codex — which then keeps running: burning API budget, holding locks, and mutating the workspace long after the turn was "cancelled". Worse, the orphan inherits the stdout pipe's write end, so the parser may never see EOF and cmd.Wait() can block past cancellation.
Group() addresses both: it puts the child in its own process group and overrides the command's Cancel to signal the entire group, and it sets WaitDelay so a lingering grandchild that kept the pipe open can't wedge Wait() forever. Call it immediately after exec.CommandContext, before Start.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Group ¶
Group runs the command in its own process group (Setpgid) and, on ctx cancel, SIGKILLs the whole group by signalling the negative pid — so bash AND every descendant it spawned (node/claude/codex) die together, not just the shell. WaitDelay guarantees Wait() returns even if an orphan still holds an inherited pipe. Call immediately after exec.CommandContext, before Start.
Types ¶
type Reporter ¶
type Reporter func(pid int)
Reporter is called with the group-leader pid of a spawned process, right after Start. It is how a turn's process group becomes visible to resource monitoring WITHOUT coupling the driver/adapter to the monitor: the orchestrator installs one on a turn's context via WithReporter, and each spawn site calls Report(ctx, cmd.Process.Pid) after cmd.Start(). Because the child is its own group leader (Group set Setpgid), that pid IS the whole process tree's group id.