← Back to Pull requests

Runner: count work in cpu.idle cgroups as idle for routing and overbooking #21

Open
unknown opened this pull request with 366 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 29, 2026 04:56 UTC
Author

A miner running beside a runner (XMRig at CPUSchedulingPolicy=idle) keeps every core at 100% in /proc/stat, so the runner reported cpu_idle ≈ 0. Clients then routed jobs to the weakest idle runner instead of the 16-core ones, and overbooked jobs waited for idle cores that never appeared.

The sampler now finds processes whose cgroup, or a parent, has cpu.idle set (systemd's CPUWeight=idle), charges each of their threads' tick deltas to the CPU it last ran on, and subtracts that from the pool's busy time that feeds cpu_idle and overbooking admission. A cpu.idle cgroup only gets cores nothing else wants. Per-thread SCHED_IDLE alone is deliberately not counted: it yields only within its own cgroup, so a miner in system.slice would still take up to about half a contended core from offload.slice. Per-CPU busy on the dashboard and the host CPU graph keep the real figure. The README says how to mark a miner's unit.

Done lines
1. CPU time of threads in a cpu.idle cgroup on a runner's offered CPUs no longer counts as busy in its reported cpu_idle.
2. Overbooking admission therefore treats cores held only by such work as idle.
3. Other work, including per-thread SCHED_IDLE outside an idle cgroup, still counts as busy.
4. The dashboard's per-CPU busy is unchanged.

Budget: ≤60 non-test lines, ≤2 code files, no new options. Actual: about 60 non-test lines in internal/runner/metrics.go, a test, one sentence each in docs/design.md and README.md.

Touch every side: runner only; no API or protocol change (the existing cpu_idle field becomes truthful), jobs and sessions alike, all runtimes. /proc/<pid>/{cgroup,task/*/stat} and cpu.idle are world-readable, so a user-level runner sees a root miner.

Review

  • Round 1 (independent Claude reviewer on the done lines and diff): P1, SCHED_IDLE doesn't yield across cgroups, so the first version would overbook onto contended cores; P2, a per-thread policy behind a normal main thread was missed. Both fixed by keying on cgroup cpu.idle (second commit). P3s noted: ticks charged to the CPU a thread last ran on, tid reuse, first interval of a new thread lost; all are bounded by the per-CPU clamp or conservative.
  • Testing

  • go vet ./... and go test ./... pass (via offload run).

  • TestReadIdleClass builds a fake /proc and cgroup tree: a process in a child of an idle slice (its own cpu.idle 0, the parent's 1) with threads on CPUs 0 and 3 and a command name holding spaces and parentheses, plus a process in a normal slice; it checks the per-CPU deltas and that the normal one is ignored.

  • Checked the stat field offsets against a live XMRig thread on vps.

  • Not yet tested on a live runner: after merge I'll set CPUWeight=idle on the miners, run offload host upgrade, and check cpu_idle on vps and vps-zeno.
  • 🤖 Generated with Claude Code (Claude Opus 5.5)

    Diff: 366 lines (+274 / -92) across 4 files Reviewer: coderabbitai[bot] Review duration: 9m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.43) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 366 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.353
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #21"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.7% (MEDIUM) · Higher = larger blast radius
    42.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.4% · Safe to merge
    24.4%