Repository navigation
Description
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:
- 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-downevent 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. - 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
- 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 anamequery 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. - Consider defaulting
enable_runner_deregistrationtofalseinmulti-runner(the standalonetermination-watchermodule already defaults tofalse). 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 scheduledregistration-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. - Emit
GitHubAppRateLimitRemainingfrom 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
Brend-Smits commentedon Nov 5, 2026
Thanks for filing this issue, I think only the exact-name fix is needed for now. Will review your PR now :)
fix(termination-watcher): look up the runner by exact name instead of…