Skip to content

Pool lambda (adjustPool) ignores runners_maximum_count, causing unbounded over-provisioning under sustained load #5186

Closed

Description

@jeff-french

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:

  1. No cap check. adjust() never reads RUNNERS_MAXIMUM_COUNT. The pool lambda's Terraform env block (modules/runners/pool/main.tf) does not set it either — only modules/runners/scale-up.tf does.
  2. Idle-only counting. calculatePooSize() counts only runners that are idle (busy === false && status === 'online'). Busy runners are excluded from numberOfRunnersInPool.

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: currentRunners read accurately at 150–310, maximum number of runners reached logged 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

  1. Configure a non-ephemeral runner type with a warm pool, e.g. pool_config with size = 40 and runners_maximum_count = 100, on the multi-runner module.
  2. 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.
  3. 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.tf env block: RUNNERS_MAXIMUM_COUNT = var.config.runners_maximum_count
  • modules/runners/pool/variables.tf: add runners_maximum_count to the config object
  • modules/runners/pool.tf (the module "pool" call): runners_maximum_count = var.runners_maximum_count (the variable already exists in modules/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-runner module, organization-level, non-ephemeral ("reuse") runner type with a warm pool, on-demand capacity.

Activity

  1. added a commit that references this issue on Jul 3, 2026
    a4ecd11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions