Repository navigation
Description
Describe the bug
runners_maximum_count is enforced only by the scale-up lambda. The pool lambda (adjustPool) has no knowledge of the maximum and tops up purely against pool_size, so a warm pool can drive the total number of runners far past runners_maximum_count. With a non-ephemeral (reuse) pool under a sustained burst of queued jobs, this is effectively unbounded: I observed a pool configured with pool_size = 40 / runners_maximum_count = 100 grow to 300+ running on-demand runners.
Current behavior
The pool lambda's top-up logic, in lambdas/functions/control-plane/src/pool/pool.ts (adjust()):
const numberOfRunnersInPool = calculatePooSize(ec2runners, runnerStatusses);
const topUp = event.poolSize - numberOfRunnersInPool;
if (topUp > 0) {
await createRunners(...);
}Two compounding facts:
- No cap check.
adjust()never readsRUNNERS_MAXIMUM_COUNT. The pool lambda's Terraform env block (modules/runners/pool/main.tf) does not set it either — onlymodules/runners/scale-up.tfdoes. - Idle-only counting.
calculatePooSize()counts only runners that are idle (busy === false && status === 'online'). Busy runners are excluded fromnumberOfRunnersInPool.
Under a sustained wave of queued jobs, runners created to fill the pool are immediately picked up and become busy, so they stop counting toward numberOfRunnersInPool. Every scheduled pool cycle therefore sees ~0 idle runners and launches another full pool_size batch — with no upper bound. Meanwhile the scale-up lambda is correctly refusing to launch (logging "maximum number of runners reached" and re-queuing jobs), so the two lambdas actively disagree about the cap.
Observed log signature during one such episode (one runner type, ~1 hour):
- pool lambda:
The pool will be topped up with 40 runners.repeated each cycle (+40, +40, +38, +40, +40 …), no cap message. - scale-up lambda:
currentRunnersread accurately at 150–310,maximum number of runners reachedlogged on every invocation, zero runners created by scale-up.
So the entire overshoot was produced by the pool lambda, while scale-up honored the limit.
Steps to reproduce
- Configure a non-ephemeral runner type with a warm pool, e.g.
pool_configwithsize = 40andrunners_maximum_count = 100, on themulti-runnermodule. - Send a sustained burst of queued jobs matching that runner type (more concurrent jobs than
pool_size), enough to keep newly created runners busy across multiple pool schedule intervals. - Observe total running runners climb past
runners_maximum_count(well beyond it for a long-running burst), driven by the pool lambda's top-up, while the scale-up lambda logs "maximum number of runners reached".
Expected behavior
The pool must never push the total number of runners (busy + idle) above runners_maximum_count. The pool's top-up should be clamped by the remaining headroom under the global cap.
Proposed fix
The pool lambda already fetches every running runner for the type via listEC2Runners({ ..., statuses: ['running'] }), so the current total (busy + idle) is just ec2runners.length — no extra API call is needed.
1. lambdas/functions/control-plane/src/pool/pool.ts (adjust()):
const maximumRunners = parseInt(process.env.RUNNERS_MAXIMUM_COUNT || '-1'); // -1 = unlimited (matches scale-up)
...
let topUp = event.poolSize - numberOfRunnersInPool;
// The pool must not push total runners (busy + idle) past the configured maximum.
// ec2runners is every running runner for this type, so its length is the current total.
if (maximumRunners !== -1) {
topUp = Math.min(topUp, maximumRunners - ec2runners.length);
}
if (topUp > 0) {
await createRunners(...);
}2. Thread the value into the pool lambda's environment (Terraform):
modules/runners/pool/main.tfenv block:RUNNERS_MAXIMUM_COUNT = var.config.runners_maximum_countmodules/runners/pool/variables.tf: addrunners_maximum_countto theconfigobjectmodules/runners/pool.tf(themodule "pool"call):runners_maximum_count = var.runners_maximum_count(the variable already exists inmodules/runners/variables.tf)
3. Tests (pool.test.ts): e.g. poolSize=2, max=5, 5 running ⇒ expect 0 createRunners; poolSize=2, max=5, 3 running ⇒ expect top-up of 2 (headroom-limited).
Defaulting the env to '-1' preserves current behavior when it is unset and matches the documented "-1 disables the maximum check" semantics, so the change is backward-compatible.
Relationship to #5062
#5062 added Math.max(0, …) in scale-up to stop a negative TotalTargetCapacity being sent to CreateFleet when currentRunners already exceeds maximumRunners. That guards the crash symptom; this issue is the root cause of how currentRunners exceeds maximumRunners in the first place (the pool lambda creating past the cap). The two are complementary.
Environment
- Module version: observed on 7.6.0; code paths above verified present on
main/ v7.8.0. multi-runnermodule, organization-level, non-ephemeral ("reuse") runner type with a warm pool, on-demand capacity.
Activity
fix(pool): clamp pool top-up to runners_maximum_count (github-aws-run…