Expand description
Process-tree containment for a spawned child and everything it starts.
Moved out of hooks/executor.rs (where it was HookProcessTree /
WindowsHookJob) so the hook runner and the extension host share one
implementation. Killing only the immediate child can leave the real work
alive (a hook’s shell runtime, a host plugin’s child_process), so:
- Unix: the child must be spawned as the leader of its own process
group (
process_group(0)); the tree is that group, and it is SIGKILLed as a whole. - Windows: the child is assigned to a Job Object configured with
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, so closing the job kills every process in it. Hooks are created suspended and resumed only after the assignment. Tokio children are assigned after spawning and can start descendants before assignment. This bounds ordinary process lifetimes; it is not a security sandbox.
Dropping the guard kills the tree. That is deliberate: the guard’s lifetime
is the tree’s lifetime, unless ProcessTree::release explicitly lets the
tree outlive it.
Structs§
- Contained
Output - What
contained_output_untilcollected. - Process
Tree - Owns the process tree rooted at one spawned child.
Functions§
- contained_
output Command::output()for a child whose whole process tree dies with the returned future. Dropping it — a caller’stimeoutelapsing, or a cancelled tool call — kills the child and everything it started, where a bareoutput()left them running. Stdin is closed: callers run non-interactive work that must never wait on input.- contained_
output_ until contained_output, plus astopfuture (a deadline, a cancel token). Whenstopfires first the tree is killed and the output written so far is still returned, so a hung command leaves evidence of where it hung.- contained_
output_ with_ input contained_outputfor a command that reads a request on stdin (a plugin tool’s JSON input):inputis written while the output pipes drain, then stdin is closed.- contained_
output_ with_ input_ bounded - Strict capture bounds for the admitted script runner. Overflow refuses the result; it never presents a truncated ToolResult as success. Same containment driver.
- kill_
contained_ trees_ for_ exit - Kill every in-flight contained tree. The process-wide signal path calls
this immediately before
process::exit, where Rust destructors cannot run. - spawn_
contained_ std - Start a synchronous child inside the same process group / Job used by hooks. Windows starts suspended and resumes only after Job assignment. The caller still owns environment policy and bounded waits; this is lifetime containment.