Skip to main content

Module process_tree

Module process_tree 

Source
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§

ContainedOutput
What contained_output_until collected.
ProcessTree
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’s timeout elapsing, or a cancelled tool call — kills the child and everything it started, where a bare output() left them running. Stdin is closed: callers run non-interactive work that must never wait on input.
contained_output_until
contained_output, plus a stop future (a deadline, a cancel token). When stop fires 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_output for a command that reads a request on stdin (a plugin tool’s JSON input): input is 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.