Skip to content

Kill full process groups and report resource usage on macOS workers - #2634

Open
erneestoc wants to merge 1 commit into
TraceMachina:mainfrom
erneestoc:ec/macos-process-group-rusage
Open

Kill full process groups and report resource usage on macOS workers#2634
erneestoc wants to merge 1 commit into
TraceMachina:mainfrom
erneestoc:ec/macos-process-group-rusage

Conversation

@erneestoc

@erneestoc erneestoc commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Problem

On macOS, NativeLink kills only the direct child of an action on timeout or
scheduler kill. Anything the action spawned below that — compiler daemons,
simulator processes, test runners — survives as an orphan, retains CPU/RAM,
and accumulates until the worker degrades. macOS workers also report no
per-action resource usage, while Linux samples peak memory (#2409).

Mechanism

  • The action is now its own process-group leader on all unix platforms. On
    macOS this maps to posix_spawn's POSIX_SPAWN_SETPGROUP attribute — the
    standard library only falls back to fork/exec for uid/gid/pre_exec/
    groups/chroot, so the fast spawn path is preserved (pre_exec is only
    used under Linux namespaces).
  • Every kill path (timeout, scheduler kill, drop-guard) additionally
    signals the entire group via kill(-pgid, SIGKILL) on macOS. Linux
    behavior is unchanged (namespaces already contain descendants there;
    non-namespaced Linux remains issue Workers that spawn child processeses may cause zombies #225).
  • The resource-usage sampler gains a macOS implementation with parity to
    the Linux /proc sampler: proc_listpids(PROC_PGRP_ONLY) +
    proc_pid_rusage sum resident memory per tick and keep each pid's
    latest cumulative CPU (converted from mach absolute time units via
    mach_timebase_info), so members that exit between ticks retain their
    CPU in the totals. ActionResourceUsage gains additive cpu_user_ns/
    cpu_system_ns fields (populated on macOS; zero elsewhere).

Verification

The group-kill regression test backgrounds a grandchild with a pgrep-able
marker, kills the action, and asserts the grandchild dies — it fails when
the group signal is disabled and passes with it. The rusage test runs a
CPU-burning helper through the full action pipeline and asserts sampled
peak memory and plausible CPU time. Suites: worker integration 37/37;
cargo check --tests --workspace clean; bazel worker+util+proto+scheduler
41/41 with clippy pedantic + nightly rustfmt aspects.


This change is Reviewable

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nativelink Ready Ready Preview, Comment Jul 27, 2026 6:34am
nativelink-aidm Ready Ready Preview, Comment Jul 27, 2026 6:34am

Request Review

macOS workers previously killed only the direct child on timeout or
scheduler kill, so helper processes spawned by the action (compiler
daemons, simulators, test runners) survived as orphans and slowly
degraded the worker. The action is now its own process-group leader on
all unix platforms (on macOS this maps to posix_spawn's
POSIX_SPAWN_SETPGROUP attribute, so the fast spawn path is preserved;
the standard library only falls back to fork/exec for
uid/gid/pre_exec/groups/chroot), and every kill path additionally
signals the whole group via kill(-pgid).

The resource-usage sampler gains a macOS implementation with parity to
the Linux /proc sampler: proc_listpids(PROC_PGRP_ONLY) enumerates the
group and proc_pid_rusage sums resident memory per tick, keeping the
per-pid latest cumulative CPU observation (converted from mach absolute
time units to nanoseconds via mach_timebase_info) so already-exited
members retain their CPU in the totals. ActionResourceUsage gains
additive cpu_user_ns/cpu_system_ns fields, populated on macOS.

Verified fails-without-fix: the new group-kill regression test leaves a
backgrounded grandchild alive when the group signal is disabled and
passes with it; the rusage test asserts sampled peak memory and
plausible CPU time for a CPU-burning helper.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UXVtatcR9YMecBiu9RjwpC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant