A scale set's static maxRunners has to be safe for the pool's real worst case, every pod at its limit at once, so it leaves real idle capacity unused whenever the jobs in flight need less than that. autoscaler (an in-cluster Deployment, same shape/placement as heartbeat above) raises and lowers maxRunners across every profile with autoscale: true (one or more, possibly from different orgs, named by AUTOSCALER_TARGETS), based on real, current memory usage and pressure, never on job identity or GitHub Actions queue depth: every consuming repo's CI keeps using its scale set's own runs-on label unchanged, and no job is ever classified as light or heavy. When more than one profile is pooled, they share one combined budget rather than each getting a fixed slice: the algorithm below runs against the pool's combined currentRunners/maxRunners, and a change is handed to whichever pooled profile's own headroom (its maxRunners minus its currentRunners) makes it the right target: raises go to the profile with the least headroom (closest to genuinely needing more), lowers take from the profile with the most (its capacity is going unused), one runner at a time, and a lower never takes a profile below its own currentRunners. RBAC is scoped to exactly what it reads/writes: cluster-wide nodes.metrics.k8s.io and nodes get/list, and pods get/list for the ceiling; per pooled profile, get/patch on that AutoscalingRunnerSet by name, get/list on ephemeralrunners (to count the running runners and to name the job a runner is running), get/list on events and pods, and pods.metrics.k8s.io get/list in its own namespace; and get/patch on its own status ConfigMap by name, with no wildcards.
Each poll (AUTOSCALER_POLL_SECONDS, default 45s):
- For every pooled profile, counts its running runners from its
EphemeralRunnerresources (every one that has not finished: a phase other thanSucceededorFailed, so a pending runner counts, because its pod already holds a slot) and reads its per-pod hard memory limit (spec.template.spec.containers[0].resources.limits.memory) straight from its liveAutoscalingRunnerSet, never a static config value, so both always match what is actually deployed. The running count is not read from theAutoscalingRunnerSet's status: in the ARC release this role pins (0.15) that status carries onlyphaseandobservedGeneration, so a count read from it would always be empty. A failed read of the runners stops the poll instead of counting zero. Sums the running counts into one combined total, and takes the largest of the pod memory limits as the threshold a raise or lower must leave room for. - Sums real, current memory usage of every pooled profile's running runner pods, from the metrics API's pod list for each profile's own namespace (
scripts/autoscaler-usage.jq); this, not a static per-pod request or limit, is the entire point of "usage-driven". It does not usekubectl top pod, which fails a whole namespace while any pod in it has no metrics, as every new runner pod has none until metrics-server first samples it. A runner pod placed on a node, not finished and missing from the list is unmeasured, and assumed to use its own memory limit (its scale set's limit when it sets none), the most it can reach. Lowering is decided on the measured usage, so a new pod never lowers the pool by itself; a raise also needs a pod's room with every unmeasured pod at its limit, and the pool holds until they are measured otherwise. - Reads cluster-wide memory-availability pressure via
kubectl top nodes, taking the worst-case (minimum) available-memory percentage across the nodes runner pods may use, not an average — a pool average can look healthy while the specific node a new runner pod would actually land on is not, consistent with the algorithm's own bias toward lowering eagerly (lowering never disrupts in-flight jobs). With the node eligibility label set (github_runner_arc_node_label_key, passed asAUTOSCALER_NODE_SELECTOR) only nodes carrying it are read, otherwise every node: a node outside the label runs no runner pod, so its pressure says nothing about where the next one lands, and when its kubelet drops out its missing metrics would otherwise fail safe on every poll. The same holds for a node inside the label that is notReady(its kubelet stopped reporting or reported a fault): it is left out of this check by the definition the ceiling uses (scripts/autoscaler-node.jq), since it places no runner pod andkubectl top nodesprints<unknown>for it. This is a genuine improvement over the pod's own earlier host-pinned design, which could only ever see one fixed machine's pressure via/proc/meminfo, not the whole pool's. No swap-pressure signal: metrics-server's API has no swap field at all, and the only alternative (the kubelet's own Summary API) needs a materially broader RBAC grant for a signal most kubelet versions don't even surface unless an off-by-default feature gate is on — dropping swap detection is a deliberate, documented trade-off once the pod is genuinely unpinned to any node, not an oversight; memory-availability pressure remains the dominant signal (the incident the values file's own comments were tuned from). - Works out the ceiling, how many pooled runner pods the nodes can place now, from the live cluster (
scripts/autoscaler-ceiling.jq). It reads every pooled profile's runner pod spec from itsAutoscalingRunnerSetand takes the largest request among them, per resource, as the runner pod (a container that sets only a limit counts at its limit, as it will once its pod is created, and sidecars, init containers and pod overhead count as the scheduler counts them). A node counts when every pooled profile's runner pods could be placed on it now: it carries theirnodeSelector, isReady, is not cordoned, and their tolerations match each of itsNoScheduleandNoExecutetaints; a node that is not ready or unreachable is left out until it is back. On each, allocatable CPU and memory less the requests of the pods on it that are not pooled runner pods, divided by the runner pod's request, and its pod capacity (allocatable.pods) less those pods, give how many fit; the smallest of the three, rounded down, is the node's figure, and the ceiling is the sum. The pooled runner pods are left out so that runners already running never lower the ceiling they count towards; every other pod still holding requests counts, a non-pooled scale set's runners included. Node affinity is not read: the role gives an autoscaled profile none, and a pod one would keep off a counted node is caught as unschedulable below.AUTOSCALER_MAX_CEILING(github_runner_arc_autoscaler_max_ceiling, or, when exactly one pooled profile setssizing, that profile's own derived figure) is an optional upper bound on it; empty leaves it unbounded. The ceiling worked out is kept in the status ConfigMap'sceilingkey, andstatus.jsonreportsceiling,ceiling_bound,ceiling_measuredand, per node, the runners it places or why it is not counted. When the nodes, the pods or a template cannot be read, or a figure in them is missing or is not a Kubernetes quantity, the poll prints why on stderr, keeps the last ceiling it worked out (or the bound, before it has one) for lowering and rebalancing, and does not raise the pool. Reading every node's pods needsget/liston pods cluster-wide, which the autoscaler's service account holds for this alone, as the heartbeat's does. - Raises the combined
maxRunnersby exactly +1 per cycle (never straight to a computed target) once headroom has covered a full pod's hard limit forAUTOSCALER_RAISE_CONFIRM_POLLS(default 2) consecutive polls, capped at the ceiling, and only in a poll that worked the ceiling out. - Lowers the combined
maxRunnersto the ceiling when the pooled total is above it, even when nothing else is wrong: each profile's own staticmaxRunnerscan sum to more than the ceiling, every Helm upgrade restores those, and the ceiling falls when a node goes, so the cap is enforced rather than only bounding raises. - Rebalances a pool that is healthy and already holds as many runners as it may: the pooled total is at the ceiling, memory headroom covers a pod, there is no pressure and no unschedulable runner pod. Slots are fixed per profile, so without this a profile that has used all of its own while another sits idle would queue for capacity the pool has. When one profile's running count has reached its own
maxRunnersand another has at least one spare slot, it moves exactly one slot from the profile with the most spare slots to the saturated one, never changing the combined total, never taking the donor below its own running count and never below one runner (so a quiet profile can always start a job), and only once the same imbalance has been seen forAUTOSCALER_RAISE_CONFIRM_POLLSconsecutive polls, so a burst that ends within a poll or two moves nothing. The count of consecutive polls is kept in the status ConfigMap'srebalance-confirm-countkey besideraise-confirm-count, and every poll that is not a confirmed imbalance resets it to zero. Under pressure, with an unschedulable pod, above the ceiling or below it (where a raise hands the new slot to the profile with the least headroom) the slot-moving never runs. - Lowers the combined
maxRunnersimmediately, with no delay or averaging, the moment headroom drops below a pod's hard limit or real pressure is detected — lowering never disrupts in-flight jobs, since ARC only gates new claims. Never patches any pooled profile below its own currently-running count, nor below one runner: a scale set atmaxRunners0 asks for no runner, so a job queued for it would wait with nothing to start it, and the cluster keeps no record of a queued job the autoscaler could see. A pool therefore never goes below one runner per pooled profile, whatever the floor, pressure or ceiling say, and a profile left at 0 by something else counts as saturated, so rebalancing gives it a slot back. - Treats any unschedulable runner pod (
PodScheduled=False, reasonUnschedulable) like pressure: the memory budget sums every node's capacity, so it cannot see a node that is tainted for disk pressure or a request that fits no single node. It lowers the combinedmaxRunnersto the running count and never raises while one exists. - Also collects the peak memory each job's runner measured for itself: the runner image's job-completed hook (
runner-hooks/job-completed.sh, set throughACTIONS_RUNNER_HOOK_JOB_COMPLETED) reads the container cgroup'smemory.peak, which a spike shorter than the poll cannot escape, and posts it as aJobMemoryPeakEvent in the pod's namespace. The autoscaler reads those Events each poll and keeps the maximum per repository, workflow ref and job id under the status ConfigMap'sjob-peakkey (kubectl get configmap autoscaler-status -n github-runner-platform -o jsonpath='{.data.job-peak}'), in MiB. Keeping the maximum means a forged low figure lowers nothing and re-reading an Event changes nothing. The hook never fails the job it ends. To post an Event the runner pods' service account, which otherwise holds no permission, getscreateoneventsin its own namespace and nothing else (github_runner_arc_record_job_peaks, default on;falseremoves the grant). A job's code runs in the same container and can read the same token, so the worst it can do with that permission is post events in its own runner namespace. - Records, per job, the highest memory a runner pod running it has been seen at, in the status ConfigMap's
job-memorykey (kubectl get configmap autoscaler-status -n github-runner-platform -o jsonpath='{.data.job-memory}'), keyed by repository, workflow ref and job name with the peak in MiB, the number of observations and when it was last seen. It is sampled once per poll from the metrics server, so it is a lower bound that a spike shorter than the poll escapes; it shows how far below a pod's request jobs sit, which is what decides whether an accurate in-pod measurement (see the per-job sizing issue) is worth building. Entries unseen for 30 days are dropped, and a failure to keep the record never affects a capacity decision. - Optionally reads per-node pressure from the nodes' own
/proc/pressure(github_runner_arc_autoscaler_node_pressure_enabled). Apsi-reporterDaemonSet (scripts/psi-reporter.sh, in the autoscaler's image) runs on each node runner pods may use, tolerating every taint, and patches that node's own key of one ConfigMap with theavg10of its io, cpu and memory pressure. The reading is not taken from the kubelet's summary API, because on a cgroup v1 node that reports every pressure field as 0 whatever the node is doing. The autoscaler lowers the combinedmaxRunnersby exactly one each poll, never below the running count, while any node's I/O "full" stall is at or overAUTOSCALER_IO_PRESSURE_PCT(default 10) or, when set above 0, its cpu "some" stall is at or overAUTOSCALER_CPU_PRESSURE_PCT, and it does not raise the pool while any node has no report newer than three polls, since whether that node can take more is then unknown. This is the signal for a pool whose nodes differ: memory can have room on a node whose disk is already the limit. - Fails safe on any memory measurement error (
kubectl top nodesor the metrics API's pod list failing, or the node list failing, or aReadynode's figure that cannot be parsed), but not on a pod that merely has no metrics yet, nor on a node that is notReady: lowers the combined total towardAUTOSCALER_FLOOR(github_runner_arc_autoscaler_floor) immediately rather than skipping the cycle silently. A failure reading the scale sets' own state or their pods exits non-zero instead, since fail-safe needs that state to lower anything and the API server is then unreachable anyway. This combined floor need not equal any one profile's own values-filemaxRunners, since each profile's Helm upgrade reverts to its own static floor independently of how the pool's combined floor is set.
Because the ceiling is the tighter of CPU and memory on each node, shrinking the runner pod's CPU request raises it only on nodes where CPU is what decides. Halving a 2 CPU, 7Gi pod to 1 CPU was measured on a two-node pool and not taken: memory then decided on both nodes, so it bought one runner (a ceiling of 5 became 6), while every job that keeps more than one core busy would be throttled to one, and the autoscaler records memory only, so there was no CPU history to weigh that against. Revisit it when CPU history exists (the node pressure reporter's cpu figures, or a per-job CPU record), when one more runner is worth that throttling, or when a node with too few cores for the larger pod needs a 1 CPU pod to take work.
Ships with AUTOSCALER_DRY_RUN=true by default: it computes and logs the target and writes its own status, but never patches. Generate real concurrent traffic to watch it react: gh workflow run test-autoscaler.yml, then watch kubectl logs -n github-runner-platform deploy/autoscaler -f and kubectl get configmap autoscaler-status -n github-runner-platform -o jsonpath='{.data.status\.json}'. Only set AUTOSCALER_DRY_RUN=false after watching real dry-run output across genuine CI traffic. Status and its raise-confirm counter live in a shared Kubernetes ConfigMap (autoscaler-status, pre-created empty so neither pod's own ServiceAccount ever needs create RBAC on it, only get/patch) rather than a bind-mounted directory, since the two pods can land on different nodes now — scripts/heartbeat.sh reads that same ConfigMap back out and republishes it as a second file in the heartbeat gist, reusing its existing gist-write credential rather than giving the autoscaler its own.
A Helm upgrade of a scale set (the role runs one when the release's rendered values or chart differ from what is installed) reverts maxRunners to the values file's safe floor. On Helm 4, which applies releases server-side, the autoscaler's patches make it the manager of maxRunners, so the role forces conflicts on the controller and scale-set releases (force_conflicts, only over the fields the chart sets); without that the upgrade would fail instead of reverting. The role's install_org.yml triggers one immediate autoscaler poll after every such upgrade (kubectl exec deploy/autoscaler -- ..., reaching the pod through the API server regardless of which node it's on), so the safe-floor window after a redeploy is seconds, not a full poll interval.