Skip to content

termination-watcher: per-event runner lookup paginates every runner; dominates App rate limit on ephemeral fleets #5572

Closed

Description

@ronniecoleman-hadrian

Overview

With instance_termination_watcher.enable_runner_deregistration = true (the multi-runner default), the termination watcher reacts to every EC2 shutting-down state change by minting an installation token and calling findRunnerByInstanceId(), which iterates every page of GET /orgs/{org}/actions/runners (per_page: 100) looking for a runner whose name contains the instance id (lambdas/functions/termination-watcher/src/deregister.ts).

Two things make this expensive on ephemeral fleets:

  1. The lookup almost always finds nothing. GitHub removes an ephemeral runner's registration when its job completes, which happens before the instance terminates itself. By the time the shutting-down event arrives the registration is already gone, and a not-found result is the worst case: every page is read before the watcher concludes nothing is there.
  2. The cost is quadratic in fleet activity: (instance terminations per hour) x ceil(registered runners / 100). At a few hundred registered runners that is 3 to 5 list requests per termination, all charged to the GitHub App installation's primary rate limit, which is shared with scale-up (generate-jitconfig), scale-down, job-retry and pool.

Observed impact

In one deployment of the multi-runner module (v7.10.1, ephemeral JIT runners, a few hundred registered runners at peak), GitHub's API Insights attributed ~52% of all requests on the installation to GET /organizations/:id/actions/runners, all from the termination watcher. Over a 10 hour sample the watcher ran ~29.6k times and made ~70k list requests to achieve 9 successful deregistrations (99.97% "Runner not found in GitHub, may have already been deregistered"). The installation hit its hourly quota during busy hours, generate-jitconfig started returning 429, and no new runners could be created for 15 to 25 minutes at a time across every pool sharing the App.

CloudWatch gave no warning because the GitHubAppRateLimitRemaining metric is only emitted from three call sites (jitconfig, GET job, GET runner/{id}); the watcher's list requests are invisible to it.

Suggested fixes

  1. Exact-name lookup (this is what the linked PR does). The runner modules tag every instance with ghr:runner_name_prefix, and runners register as <prefix><instance-id>. The list-runners API accepts a name query parameter that returns the single matching runner. One request regardless of fleet size; the paginated scan can remain as a fallback for instances without the tag.
  2. Consider defaulting enable_runner_deregistration to false in multi-runner (the standalone termination-watcher module already defaults to false). The per-event path is mostly a no-op for ephemeral runners, scale-down already deregisters the idle runners it terminates, GitHub purges offline ephemeral registrations after about a day, and the new scheduled registration-janitor (feat: add stateless registration cleanup with multi-App support #5465) is the right place for reconciling the leftovers. Opt-in matches the cost profile better.
  3. Emit GitHubAppRateLimitRemaining from an Octokit request hook so every request through a client contributes a sample, instead of three hand-picked call sites. The current metric reads as a floor, not a total, and hides exactly the kind of consumer described here.

Happy to follow up with a PR for (2) and/or (3) if maintainers agree on direction; (1) is small and self-contained.

Project version

v7.10.1 (the lookup is unchanged on main as of 7b54664).

Activity

  1. Brend-Smits commented on Nov 5, 2026

    @Brend-Smits
    Contributor

    Thanks for filing this issue, I think only the exact-name fix is needed for now. Will review your PR now :)

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