proc

package
v0.1.60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Group(cmd *exec.Cmd)

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.

func Report

func Report(ctx context.Context, pid int)

Report invokes the context's Reporter (if any) with pid. It is a no-op when no reporter is installed — e.g. auth/doctor helpers, or a daemon built without monitoring wired — so every spawn site can call it unconditionally. Safe with any context.

func WithReporter

func WithReporter(ctx context.Context, r Reporter) context.Context

WithReporter returns a context carrying r, retrievable by Report. A nil r is ignored (returns ctx unchanged), so callers can wire it unconditionally.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL