Skip to content

ci(runner): run.sh --cgroup-parent puts the CI containers under a cgroup of the host's choosing - #4061

Merged
devswha merged 3 commits into
mainfrom
ci/runner-cgroup-parent
Nov 17, 2026
Merged

devswha merged 3 commits into
mainfrom
ci/runner-cgroup-parent

Conversation

@devswha

@devswha devswha commented Nov 17, 2026

Copy link
Copy Markdown
Owner

What

scripts/self-hosted-runner/run.sh --cgroup-parent SLICE starts every container the launcher starts
(the runners, the check slots' keeper, the cache builds and helpers) and the image build's steps under that
cgroup instead of docker's own. With docker's systemd driver on cgroup v2, a host can then give its CI a low
CPU weight: the runners in ovis-ci.slice under a top-level ovis.slice with CPUWeight=20 run at full
speed while the CPU is free and yield to the PC's own sessions (weight 100) when both want it, instead of
being held back by a low runner count. A parent docker cannot use is refused at start (exit 2), before any
registration token, like a CPU list. Without the option nothing changes.

CPUSET_ARGS becomes PLACE_ARGS, which carries --cpuset-cpus and --cgroup-parent together.

Why now

Step 2 of measured CI placement work: the maintainer PC protects its owner's sessions by weight rather than
by a low runner count. Turning it on is a host change (the slice and the launcher's flag), measured on its
own; this pull request only adds the option.

Validation

  • On the maintainer PC (docker 2 / systemd driver): a container started with --cgroup-parent ovis-ci.slice
    lands in /ovis.slice/ovis-ci.slice/docker-<id>.scope. A contention probe (8 CPU-bound processes in a
    normal session beside 16 busy processes in a runner-image container, CPUs 120-127) took 2.5 s alone and
    5.5 s beside the container at default weights; the weighted measurement follows when the slice gets its
    weight.
  • bun run check fast at 77a1bd9 (hosthatch heavy runner): pass.
  • bun test scripts/self-hosted-runner.test.ts: 76 pass; the new tests fail without the change.
  • Reviews: omo reviewer CLEAR at a3bee23 (this head only merges main on top), Codex (gpt-6.1-terra)
    CLEAR at this head.

…er a cgroup of the host's choosing

So a host can give its CI containers a low CPU weight (a system slice under a top-level slice with
CPUWeight=20): the jobs run at full speed while the CPU is free and yield to the PC's own sessions
when both want it, instead of being held back by a low runner count. A parent docker cannot use is
refused at start, like a CPU list.
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Added a --cgroup-parent option to place runner containers and image builds under a specified cgroup.
    • Startup checks that the selected cgroup parent is usable before retrieving a token or starting a container.
  • Documentation
    • Added guidance on cgroup placement, including CPU allocation considerations for systemd cgroup v2.

The self-hosted runner now accepts --cgroup-parent, combines it with --cpuset-cpus as placement arguments, and passes those settings to image builds and container runs. A Docker startup probe rejects an unusable parent before token retrieval or container startup. The README and tests describe and verify this behavior.

Changes: Runner cgroup placement

Layer / File(s) Summary
Placement option contract
scripts/self-hosted-runner/run.sh, scripts/self-hosted-runner/README.md
The launcher parses --cpuset-cpus and --cgroup-parent into placement arguments. The README documents cgroup-parent use with runner containers and image-build steps, including systemd cgroup v2 guidance.
Apply and validate Docker placement
scripts/self-hosted-runner/run.sh, scripts/self-hosted-runner.test.ts
Docker builds and containers receive configured placement arguments. The startup probe rejects an unusable cgroup parent before token retrieval or container startup. Tests check argument placement, omission when unset, and rejection behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Possibly related PRs

  • devswha/ovis#2910: Adds --cpuset-cpus to launcher containers; this change extends the same placement-argument path with --cgroup-parent.
Merge Risk: Minimal · up to 77a1b

This change adds an optional cgroup parent setting for self-hosted runners, and behavior is unchanged when the option is omitted. An unusable parent is rejected at startup. No merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change, the new --cgroup-parent option in run.sh. However, it is phrased awkwardly and says the host chooses the cgroup. The description says the option places containers unde…
Description check Passed The description follows the template's intent. The What section describes the change and its behavior, and the Why now section gives motivation. The Validation section lists the checks run, the result…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change, the new --cgroup-parent option in run.sh. However, it is phrased awkwardly and says the host chooses the cgroup. The description says the option places containers under a slice the host supplies, so the title does not clearly convey the purpose. It uses the ci(runner) prefix, which fits the change.

Full details: Description check

Explanation

The description follows the template's intent. The What section describes the change and its behavior, and the Why now section gives motivation. The Validation section lists the checks run, the results, and the reviews. It does not reference changelog.d or CONTRIBUTING.md checks, and it does not mention contract-test coverage, which is not needed here since no HTTP/WS change is made. The Validation section names the checks run, but it does not explicitly list checks skipped.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4417529 and 77a1bd9.

Files selected for processing: 3

  • scripts/self-hosted-runner.test.ts
  • scripts/self-hosted-runner/README.md
  • scripts/self-hosted-runner/run.sh

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

@devswha
devswha merged commit 6d92efd into main Nov 17, 2026
16 checks passed
@devswha
devswha deleted the ci/runner-cgroup-parent branch November 17, 2026 18:33
@devswha

devswha commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 77a1bd918e09 as 6d92efddbeeb on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Reviewed by the merge pass (the self-hosted runner launcher, a sensitive area: its own two reviews, a fresh omo reviewer and Codex, at this head). The --cgroup-parent value comes only from the host operator's command line; the env file is never sourced and holds only CHECK_HOST_* numbers, so no job or pull request can set it, and unset leaves docker's arguments as on main. It reaches docker quoted as one argument (--privileged, spaces, a newline and * each stay one argument), and the startup probe refuses a name that is not a valid slice with exit 2 before any token or container. No mount, capability, device, network or privileged flag is added, and no kill pattern changed.

Codex raised two points as mediums that the merge pass rules low: the launcher leaves the slice syntax to docker's own check (the probe runs it before anything starts, so a bad name fails closed), and an explicitly empty value is refused at start-up instead of meaning "none" (it fails loudly before any runner starts; an operator who wants none leaves the option out). Other low notes: the tests would not notice an unquoted value (their values have no spaces); with --build a bad parent fails inside docker build with docker's own message rather than the exit-2 refusal; one test pins the order of two docker flags.

devswha added a commit that referenced this pull request Nov 18, 2026
…d from shell and PowerShell files (#4115)

## What

The restore PRs #4081, #4083 and #4087 put back the notes the comment
pass dropped but should have kept (security notes, traps that name what
breaks, platform facts, measured values). They held back eight shell and
PowerShell files, because the refactor kit's comments-only proof cannot
prove them (see "Kit proof" below). This PR puts back the notes in those
files.

| File | Dropped by |
|---|---|
| `install.sh`, `install.ps1` | #4040 |
| `scripts/ci-runner-route.sh`, `scripts/windows-install.test.ps1` |
#4047 |
| `scripts/self-hosted-runner/run.sh`,
`scripts/self-hosted-runner/build-cache-promote.sh`,
`scripts/self-hosted-runner/hook-test-harness.sh`,
`scripts/relay-ios-sim.sh` | #4049 |

The notes were written against older code, so each one was read against
the code beside it now. The second commit changes 12 that no longer
matched, for example:

- `run.sh`: the startup check covers the cgroup parent as well as the
CPU list (#4061), and runners also mount their build cache outbox.
- `install.sh`, `install.ps1`: the install lock is a pid file created
only where none exists, not the folder.
- `install.sh`: the herdr-core plugin build follows
`herdr-plugin.toml`'s pre-flight step (#3800).
- `windows-install.test.ps1`: the case reads `$state.badBinary`, not
`releaseDown`.

No code changes. One code line differs only in its comment:
`install.ps1`'s `} catch { $job = [IntPtr]::Zero }` gets its trailing
note back. No shellcheck or PSScriptAnalyzer directive comes back.

## Kit proof

`~/.dori-sa/kit/refactor-merge/proof.sh 4115` at 4769efc ends with
**FAIL**. Of the 8 files it proves 1 (`install.ps1`) and lists 7 as
differing. Each one's first difference is "inside a string or heredoc":
the kit's shell and PowerShell reader has lost track of the quoting by
then and reads the restored comment as string text. This is the misread
these files were held back for. Each file was checked again with the
language's own parser, base 9df15d6 against this head:

- `shfmt -mn` (shfmt 3.14.1's parser, which drops comments) prints the
same output for `install.sh`, `ci-runner-route.sh`, `run.sh`,
`build-cache-promote.sh` and `hook-test-harness.sh`.
- `relay-ios-sim.sh`: two of its notes are inside the `remote.sh`
heredoc, the script it runs on eamac. They are comments in that script,
but text to this one. `shfmt -mn` gives the same output for the
heredoc's script, and for the file with the heredoc emptied.
- `install.ps1` and `windows-install.test.ps1`: PowerShell 7.6's
`Parser.ParseFile` gives the same token list (comments and newlines left
out) on both sides, 6,005 and 10,476 tokens.

So this PR needs the owner's merge: the kit's rule is to merge only on
PASS.

## Validation

- `bun run check fast`: passed (18,673 unit tests, typecheck, build,
generated themes and types).
- `bash -n` on the six `.sh` files; `bun test
scripts/conventions.test.ts`.
- `git show HEAD~1 HEAD | grep -E '^[+-][^+-]' | grep -vE '^[+-]\s*#'`
prints only that `install.ps1` line.

Left open, not merged, on the owner's word.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
devswha added a commit that referenced this pull request Nov 21, 2026
…ost has room (#4068)

## What

`scripts/self-hosted-runner/run.sh --offer-when-room` (opt-in). A
registered runner is an offer: GitHub hands
it any job with matching labels, whatever its host is doing, so a busy
host keeps taking work (one host's browser
parts took 10.5 to 14.8 min against 8 elsewhere). With the flag, a slot
that is not reserved waits, before it
fetches a registration token, until the host has room:

- no other runner of this host in the same pool is idle (a runner
without a `Runner.Worker` process; the runners
of every launcher copy on the host count), and no other slot of the pool
has claimed room and not started yet:
  at most one idle offer per host and pool;
- no job started on the host in the last 30 s and no runner started in
the last 30 s (pressure shows up late);
- `/proc/pressure/cpu` and `/proc/pressure/memory` "some avg10" are
under `CHECK_HOST_OFFER_CPU_PSI` and
`CHECK_HOST_OFFER_MEMORY_PSI` from the host env file (1 or more;
skipped, with one log line, on a kernel
  without PSI).

The decision and the claim happen under a host-wide `flock`; the state
lives in `~/.cache/ovis-ci-runner`.
Reserved slots (main's runners) are never gated. Without the flag
nothing changes; `--count` stays the hard
maximum and still has to fit `CHECK_HOST_MAX_RUNS`.

## Rollout

Measured host by host: first one host, two hours of real pull-request
runs against the hours before, taken back
if worse; a host's first gated runner runs one real job under a label of
its own before it joins the pool.

## Validation

- `bun test scripts/self-hosted-runner.test.ts`: 91 pass, 7 skip
(namespace-only hook tests). The gate's 15
tests fail without the code they cover (checked by reverting each part);
the fake `docker top` refuses a
  format without a pid column, as Docker 29 does.
- `docker top <runner> -eo pid,etimes,args` checked on the real runner
containers of the maintainer PC: idle
  runners read as idle, busy ones give their job's age.
- `bun run check fast` at this head (hosthatch heavy runner).
- Reviews: four Codex (gpt-6.1-terra) rounds and three omo rounds before
this head; last reads CLEAR at
1d2da1b2 (this head is that change rebased onto main after #4061 merged;
the gate's diff is byte-identical).
Fixed on the way: `docker top` needed a pid column (the gate saw nothing
without it), claims that last until
the container runs and are removed only under the lock, state not under
`XDG_RUNTIME_DIR`, a 0 threshold
refused, a bounded token request, a lock file that cannot be opened no
longer ends a slot's loop.
- Declined, with reasons in the reports: a transient `docker top`
failure lets an offer through (the gate fails
open by design, the worst case being the behaviour without it); a job
that starts and ends between two polls
  is not waited out (it leaves no pressure).

Pre-existing, not from this change: "mounts the build cache read-only
..." runs about 3.6 s against its 5 s
timeout on main too and can time out under host load.

---------

Co-authored-by: devswha <[email protected]>
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