Repository navigation
Conversation
Job steps shared an orphaned process group with Runner.Listener and its supervisor. A step that leaves a stopped process behind when a group member exits (for example .NET's Process.Kill(entireProcessTree: true)) makes the kernel send SIGHUP and SIGCONT to the whole group, killing the runner. Fixes actions/runner-images#14833
There was a problem hiding this comment.
🟡 Changes recommended
Terminal-probe failures are handled too broadly, and the process-wide behavior lacks a rollout feature flag.
2 open findings
What changed in this PR
Separates noninteractive Unix workers and job steps from the listener’s process group to prevent group signals from terminating the runner stack.
Changes:
- Detects controlling terminals and manual signal trapping.
- Moves eligible workers into a dedicated process group.
- Logs process-group transition failures as best effort.
| File | Description |
|---|---|
src/Runner.Worker/Program.cs |
Adds Unix process-group isolation during worker startup. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| #if !OS_WINDOWS | ||
| MoveToOwnProcessGroup(trace); | ||
| #endif |
There was a problem hiding this comment.
Done in 8b8c855. The process group move now happens in Worker.RunAsync, after the job message arrives and before any step launches, and only when the actions_runner_worker_own_process_group feature flag is true. It is off by default, so it can be rolled out and turned off from the service side.
| return; | ||
| } | ||
| } | ||
| catch (IOException) |
There was a problem hiding this comment.
Done in 8b8c855. /dev/tty is now probed with open(2) directly. Only ENXIO (no controlling terminal) and ENOENT (no /dev/tty) count as "no terminal". Any other errno keeps the current process group and logs the errno. I checked this in a Linux container: without a terminal, open returns ENXIO and setpgid moves the process; under a pty, the terminal is found and the group stays.
…robe Move the process group change from Program.MainAsync into Worker.RunAsync, after the job message arrives and before any step launches, so it can be gated by the actions_runner_worker_own_process_group feature flag. Probe /dev/tty with open(2) and treat only ENXIO and ENOENT as "no terminal". Any other error keeps the current process group, instead of treating every IOException as a missing terminal.
| private void MoveToOwnProcessGroup() | ||
| { | ||
| if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("RUNNER_MANUALLY_TRAP_SIG"))) |
There was a problem hiding this comment.
Done in 94e92b8. The libc calls are now behind IProcessGroupNative, so Worker can be tested with a mock. New tests in WorkerL0 cover:
- the feature flag gate (unset,
false,true), including that the move happens before the job starts. On Windows the test checks that nothing moves even with the flag on. - the controlling terminal bypass, and
RUNNER_MANUALLY_TRAP_SIGskipping the probe entirely. ENXIOandENOENTmoving the process, and other errno values (EIO,EMFILE) leaving it in place.setpgidfailing, and the native calls throwing.
All 13 WorkerL0 tests pass on Windows and in a Linux container.
Move the libc calls behind IProcessGroupNative so Worker's logic can be tested with a mock. The tests cover the feature flag gate (including that the move happens before the job starts), the controlling terminal and RUNNER_MANUALLY_TRAP_SIG bypasses, unexpected errno values from the terminal probe, setpgid failure and exceptions from the native calls.
…ess-group # Conflicts: # src/Runner.Common/Constants.cs

Fixes #4775. Also fixes actions/runner-images#14833. Related: dotnet/runtime#131944.
Problem
On hosted macOS runners, every job step shares one process group with the runner stack:
That group is orphaned, because its leader's parent is
launchd. If a member exits while the group has a stopped member, the kernel sendsSIGHUPandSIGCONTto every process in the group. .NET'sProcess.Kill(entireProcessTree: true)SIGSTOPs each process before killing it, so a step that calls it can killRunner.Listenerandhosted-compute-agent. The job then ends with "The hosted runner lost communication with the server", step timeouts never fire and logs are lost. In our runs, 10 of 13 jobs lost the runner this way. Running the same repro in its own session and process group passed 3 of 3, with the runner still alive.Captures (process tables, signal logs, spindump): https://github.com/thomhurst/ModularPipelines/releases/tag/diag-runtime-131944
Fix
After the job message arrives and before any step starts,
Runner.Workercallssetpgid(0, 0)to move into its own process group. This only happens when theactions_runner_worker_own_process_groupfeature flag is true, so the change can be rolled out and turned off from the service side. Job steps inherit that group, so:Runner.Listeneror whatever supervises it;Runner.Listener) is in the same session but a different group. Steps therefore don't getSIGHUPeither. This is the layout a shell's job control creates, which is why the problem never reproduces from a terminal.The worker leaves the process group as it is when:
/dev/ttyopens), so interactiverun.shkeeps today's Ctrl+C and job-control behaviour;RUNNER_MANUALLY_TRAP_SIGis set, becauserun.shthen usesset -m(a group that is not orphaned) and forwardsSIGINTto the whole group;open(2)on/dev/ttyfails with an errno other thanENXIOorENOENT).The change only applies outside Windows. Failures are best effort: they are logged and the job runs in the inherited group, as it does today.
Testing
Runner.Workerbuilds for osx-arm64, linux-x64 and win-x64 with 0 warnings.WorkerL0tests cover the feature flag gate, the terminal andRUNNER_MANUALLY_TRAP_SIGbypasses, unexpected errno values,setpgidfailure and exceptions from the native calls, using a mock ofIProcessGroupNative. They pass on Windows and Linux./dev/ttyprobe returnsENXIOwithout a terminal andsetpgidmoves the process. Under a pty, the terminal is found and the group is left as it is.macos-latestusingsetsid, as described above.