Skip to content

fix(ssm): delete expired runner parameters as pages are listed - #5464

Merged
guicaulada merged 1 commit into
mainfrom
gc/fix/ssm-housekeeper-pagination
Sep 24, 2026
Merged

guicaulada merged 1 commit into
mainfrom
gc/fix/ssm-housekeeper-pagination

Conversation

@guicaulada

@guicaulada guicaulada commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

The SSM housekeeper accumulates every parameter page before deleting anything. A later listing failure prevents all cleanup, and an omitted Parameters array on the first page silently discards later candidates.

Delete eligible parameters as each page arrives, including pages after empty responses. Isolate deletion failures per parameter, preserve the existing age and dry-run protections, and stop starting new work with ten seconds remaining. A later listing failure leaves earlier deletions completed.

Cleanup is stateless: every invocation starts a fresh scan of current parameters. Successfully deleted parameters disappear from subsequent listings, leaving the remaining work for later scheduled runs. Pagination tokens exist only within an invocation.

Validation: all 115 storage-provider tests pass, including empty pages, deletion before later-page failure, fresh scans after partial cleanup, and continuing past a failed deletion. Runtime TypeScript, ESLint, Prettier, Lambda bundle build, and diff checks pass. No AWS deployment or live parameter deletion was performed.

Independent of native SSM expiration-policy work in #5265. Companion PRs: #5463 and #5465.

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@guicaulada guicaulada changed the title fix(ssm): retain cleanup candidates after empty parameter pages fix(ssm): clean parameter pages incrementally and resume interrupted sweeps Sep 23, 2026
@guicaulada
guicaulada force-pushed the gc/fix/ssm-housekeeper-pagination branch from a3c2764 to f6062e4 Compare September 23, 2026 14:14
@guicaulada guicaulada changed the title fix(ssm): clean parameter pages incrementally and resume interrupted sweeps fix(ssm): delete expired runner parameters as pages are listed Sep 23, 2026
@Brend-Smits
Brend-Smits requested a balanced review from Copilot September 23, 2026 16:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The incremental cleanup behavior is correctly implemented, documented, and covered by focused tests.

Review effort: Balanced
Findings: None

What changed in this PR

Refactors SSM cleanup to process parameters incrementally, improving resilience to listing and deletion failures.

Changes:

  • Deletes eligible parameters page by page with isolated failures.
  • Adds Lambda deadline awareness and stateless retry behavior.
  • Expands tests and documents cleanup semantics.
File Description
modules/​runner-config/​ssm-housekeeper/​README.md Documents incremental cleanup behavior.
lambdas/​libs/​storage-providers/​core/​index.ts Adds optional remaining-time callback.
lambdas/​libs/​storage-providers/​aws/​ssm/​runner-config-housekeeper.ts Implements incremental, deadline-aware cleanup.
lambdas/​libs/​storage-providers/​aws/​ssm/​runner-config-housekeeper.test.ts Tests pagination and failure handling.
lambdas/​functions/​control-plane/​src/​lambda.ts Supplies Lambda remaining runtime.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@guicaulada
guicaulada merged commit d815b76 into main Sep 24, 2026
13 of 14 checks passed
@guicaulada
guicaulada deleted the gc/fix/ssm-housekeeper-pagination branch September 24, 2026 13:44
NickAnge added a commit to NickAnge/terraform-aws-github-runner that referenced this pull request Oct 6, 2026
Reapplies github-aws-runners#5464, which was unintentionally reverted by github-aws-runners#5477. That commit
carried housekeeper files from a branch that predated github-aws-runners#5464, restoring the
list-everything-then-delete loop and dropping the remaining-time guard,
its Lambda wiring, tests, and README notes.
Brend-Smits pushed a commit that referenced this pull request Oct 7, 2026
#5477 (`445269c`) unintentionally reverted #5464: the SSM housekeeper
again lists every parameter before deleting anything, loses candidates
when the first page omits `Parameters`, and has no remaining-runtime
guard. A late listing failure or timeout can therefore prevent cleanup
from making progress.

Reapply #5464 unchanged on current main, restoring page-by-page
deletion, pagination through empty pages, isolated deletion failures,
the ten-second runtime guard and its Lambda wiring, tests, and README
notes. The restored patch has the same stable patch ID as #5464.

#5469 already includes an equivalent restoration commit (`762583d`).
This PR separates that restoration from the batching changes so it can
land independently. Once merged, #5469 can rebase and drop its duplicate
restoration commit.

Validation: 127 storage-provider tests and 22 Lambda wrapper tests
passed. ESLint and Prettier passed for the changed TypeScript files; the
control-plane Lambda bundle build and `git diff --check` passed. No AWS
deployment or live parameter deletion was performed.
Brend-Smits added a commit that referenced this pull request Oct 22, 2026
🤖 I have created a release *beep* *boop*
---


##
[8.0.0](v7.11.0...v8.0.0)
(2026-10-21)


### ⚠ BREAKING CHANGES

* **terraform:** require Terraform 1.5.6
([#5261](#5261))

### Features

* **compute-providers:** add AWS EC2 provider modules
([#5343](#5343))
([ffa299f](ffa299f))
* **dynamic-labels:** add a capacity-type label to choose spot or
on-demand per job
([#5485](#5485))
([edecd36](edecd36))
* **dynamic-labels:** add allow-list mode to the AWS dynamic labels
policy
([#5411](#5411))
([05984f6](05984f6))
* **examples:** add multi-runner-v2 example
([#5367](#5367))
([f2779cc](f2779cc))
* **github-app:** select app by rate limit budget
([#5391](#5391))
([668d8da](668d8da))
* **github-app:** use ssm manifest for extra apps
([#5282](#5282))
([33c3332](33c3332))
* **multi-runner:** add experimental config translation
([#5284](#5284))
([dd24d33](dd24d33))
* **multi-runner:** consume resolved experimental config
([#5340](#5340))
([ff8bfc2](ff8bfc2))
* **multi-runner:** move v1 state into v2 modules
([#5415](#5415))
([e8d7956](e8d7956))
* **orchestration-providers:** add webhook provider modules
([#5344](#5344))
([c05c9b3](c05c9b3))
* **runner-config:** add provider-aware runner configuration
([#5345](#5345))
([42b1261](42b1261))
* **runners:** add network_interfaces for advanced EC2 launch template
configuration
([#5427](#5427))
([1e72c14](1e72c14))
* **scale-down:** opt-in idle confirmation window before terminating
not-busy runners
([#5397](#5397))
([595f3e5](595f3e5))
* **scale-set:** add scale set orchestration in Terraform
([#5299](#5299))
([937fe15](937fe15))
* **storage:** add runner config consumer
([#5358](#5358))
([138309c](138309c))
* support native SSM expiration policies for runner token parameters
([#5265](#5265))
([2dca7f9](2dca7f9))
* **terraform:** add SSM storage provider boundary
([#5454](#5454))
([d04c5da](d04c5da))
* **terraform:** require Terraform 1.5.6
([#5261](#5261))
([f335b32](f335b32))


### Bug Fixes

* allow null amd_sev_snp/nested_virtualization in cpu_options vali…
([#5430](#5430))
([0b5ec3d](0b5ec3d))
* **control-plane:** clarify partial runner creation test name
([#5339](#5339))
([b1dd396](b1dd396))
* **deps:** bump actions/deploy-pages from 5.0.0 to 5.0.1 in the github
group
([#5418](#5418))
([1a691ea](1a691ea))
* **deps:** bump github/codeql-action/upload-sarif from 4.36.3 to 4.37.8
([#5317](#5317))
([fdb4385](fdb4385))
* **deps:** bump
google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml
from 2.5.0 to 2.5.1
([#5331](#5331))
([1523a66](1523a66))
* **deps:** bump ossf/scorecard-action from 2.4.3 to 2.4.4
([#5319](#5319))
([d798070](d798070))
* **deps:** bump step-security/harden-runner from 2.19.4 to 2.21.0
([#5318](#5318))
([c81927a](c81927a))
* **deps:** bump step-security/harden-runner from 2.19.4 to 2.21.1
([#5386](#5386))
([48b0c42](48b0c42))
* **deps:** bump step-security/harden-runner from 2.21.1 to 2.22.1
([#5532](#5532))
([5ccf8b3](5ccf8b3))
* **deps:** bump terraform-linters/setup-tflint from 6.3.0 to 6.3.1
([#5419](#5419))
([5f0ecef](5f0ecef))
* **deps:** bump terraform-linters/setup-tflint from 6.3.1 to 6.3.2
([#5515](#5515))
([4c4191f](4c4191f))
* **deps:** bump the github group with 3 updates
([#5330](#5330))
([ab6edf5](ab6edf5))
* **deps:** bump the github group with 3 updates
([#5446](#5446))
([7bb9280](7bb9280))
* **deps:** bump the github group with 3 updates
([#5504](#5504))
([aa08de3](aa08de3))
* **deps:** bump the github group with 5 updates
([#5531](#5531))
([c5b9a47](c5b9a47))
* **deps:** bump zizmorcore/zizmor-action from 0.6.2 to 0.6.3
([#5387](#5387))
([62aef5d](62aef5d))
* **deps:** bump zizmorcore/zizmor-action from 0.6.3 to 0.6.4
([#5447](#5447))
([aa24dc0](aa24dc0))
* **ec2:** avoid launch template tag conflict for on-demand
capacity-type overrides
([#5522](#5522))
([dc9e820](dc9e820))
* **ec2:** improve failure observability
([#5335](#5335))
([91751ef](91751ef))
* fail over rate-limited GitHub App requests
([#5523](#5523))
([7453956](7453956))
* fix typo in variable
([#5462](#5462))
([0786125](0786125))
* **github-runner:** record the rate-limit metric even when the call
fails
([#5426](#5426))
([5026cd9](5026cd9))
* **lambda:** bump @babel/core from 7.23.9 to 7.29.7 in /lambdas
([#5181](#5181))
([3729cf7](3729cf7))
* **lambda:** bump @humanfs/node from 0.16.6 to 0.16.8 in /lambdas
([#5336](#5336))
([f7dd7cb](f7dd7cb))
* **lambda:** bump axios from 1.18.0 to 1.18.1 in /lambdas
([#5223](#5223))
([21d27f1](21d27f1))
* **lambda:** bump axios from 1.18.1 to 1.20.0 in /lambdas
([#5502](#5502))
([e2f9e5e](e2f9e5e))
* **lambda:** bump browserslist from 4.22.3 to 4.28.8 in /lambdas
([#5329](#5329))
([27e7d53](27e7d53))
* **lambda:** bump fast-uri from 3.1.2 to 3.1.5 in /lambdas
([#5242](#5242))
([9c3e28c](9c3e28c))
* **lambda:** bump fast-uri from 3.1.5 to 3.1.6 in /lambdas
([#5337](#5337))
([07bbc87](07bbc87))
* **lambda:** bump fast-uri from 3.1.6 to 3.1.8 in /lambdas
([#5488](#5488))
([3062702](3062702))
* **lambda:** bump follow-redirects from 1.16.0 to 1.16.1 in /lambdas
([#5540](#5540))
([a7b6dea](a7b6dea))
* **lambda:** bump js-yaml from 3.15.0 to 3.15.1 in /lambdas
([#5264](#5264))
([a3116bd](a3116bd))
* **lambda:** bump js-yaml from 3.15.1 to 3.15.2 in /lambdas
([#5398](#5398))
([3db123f](3db123f))
* **lambda:** bump proxy-addr from 2.0.7 to 2.0.8 in /lambdas
([#5510](#5510))
([faf57cd](faf57cd))
* **lambda:** bump source-map-js from 1.2.1 to 1.2.2 in /lambdas
([#5511](#5511))
([e058e05](e058e05))
* **lambda:** bump undici from 6.28.0 to 6.28.1 in /lambdas
([#5489](#5489))
([3ff5877](3ff5877))
* **lambda:** create log groups before functions
([#5324](#5324))
([2f844ab](2f844ab)),
closes
[#5323](#5323)
* **migration-test:** preserve unreserved job retry concurrency
([#5516](#5516))
([feba645](feba645))
* **multi-runner:** gate v2 routing with experimental feature
([#5404](#5404))
([b448845](b448845))
* **multi-runner:** make v2 inputs independent
([#5368](#5368))
([45d3d0e](45d3d0e))
* **multi-runner:** route v1 and v2 runners separately
([#5346](#5346))
([cfac174](cfac174))
* **pages:** configure GitHub Pages deployment environment
([#5334](#5334))
([f081004](f081004))
* **pool-lambda:** grant permission to terminate failed EC2 runners
([#5538](#5538))
([0043890](0043890))
* re-indent commands in CONTRIBUTING.md guide
([#5305](#5305))
([547a98b](547a98b))
* retain arm64 build coverage in lambda workflow
([#5535](#5535))
([80078d7](80078d7))
* **runners:** guard SEGMENT against set -u in start-runner.sh
([#5233](#5233))
([182b37d](182b37d))
* **runners:** support instance requirements in EC2 Fleet overrides
([#5314](#5314))
([4f80654](4f80654))
* **scale-set:** implement review followups
([#5477](#5477))
([445269c](445269c))
* **ssm:** batch housekeeper parameter deletions
([#5469](#5469))
([28a5135](28a5135))
* **ssm:** delete expired runner parameters as pages are listed
([#5464](#5464))
([d815b76](d815b76))
* **ssm:** restore incremental housekeeper cleanup
([#5508](#5508))
([22b9310](22b9310))
* **storage:** add SSM adapter diagnostics
([#5385](#5385))
([d08be31](d08be31))
* **webhook:** cache only a successful config load
([#5519](#5519))
([a2fea96](a2fea96))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Signed-off-by: Brend Smits <[email protected]>
Co-authored-by: runners-releaser[bot] <194412594+runners-releaser[bot]@users.noreply.github.com>
Co-authored-by: Brend Smits <[email protected]>
guicaulada added a commit that referenced this pull request Oct 27, 2026
…#5463)

Scale-down waits for the complete EC2 inventory before removing active
runners. With large fleets, listing can fail or time out before any
cleanup happens. Orphan cleanup can also terminate a runner whose
registration ID tag is missing without checking GitHub, or stop
processing other runners after one failure.

Process EC2 inventory in bounded pages of up to 100 instances and clean
each page before requesting the next. Look up registrations by valid
GitHub runner ID or exact full runner name instead of listing the entire
organization/repository. Verify orphan registrations, remove
false-positive orphan markers, preserve unverifiable runners, and
isolate failures per runner. Existing busy checks, bypass-removal, boot
grace, and idle detection remain in place.

Cleanup is stateless. Every invocation starts from current inventory;
successfully terminated instances are no longer listed on subsequent
runs. Pagination tokens exist only within the invocation. A deadline
guard stops starting new work with ten seconds remaining, and a later
listing failure retains earlier cleanup. Busy, retained, or failed items
can be checked again on the next invocation.

The idle allowance is shared across pages within an invocation and
recalculated on the next run. Eviction ordering applies within each
page; strict global oldest/newest ordering requires collecting the whole
fleet. Repeated scheduled scans reconcile pagination shifts as instances
disappear. Custom compute providers without the optional paging
capability retain their existing list-based path, including a complete
owner-listing fallback when GitHub identity fields are absent. Only
successful complete listings are cached.

Both Terraform scale-down paths supply the configured runner-name
prefix. EC2 trusts an instance prefix tag only when it matches that
configuration. Missing or mismatched tags without a valid GitHub ID
cause cleanup to retain the instance; affected instances need their tags
or registration IDs corrected before automatic cleanup. An exact-name
miss without an ID also retains the instance because a custom script may
have registered a different name. Unverifiable identity is reported at
error level before unnecessary authentication when possible.

Validation: 395 control-plane tests, 312 compute-provider tests, and
seven mocked Terraform tests pass, covering cleanup before later-page
failure, fresh scans of reduced inventory, cross-page idle allowance,
deadline handling, direct GitHub ID lookup, and isolated failures.
Runtime TypeScript, ESLint, Prettier, Lambda bundle build, and diff
checks pass. The compute-provider package's separate TypeScript check
has existing Vitest configuration typing errors, reproduced with
unchanged compute-provider code. No AWS deployment or live termination
was performed.

Independent companion PRs: #5464 (SSM cleanup) and #5465 (opt-in
registration reconciliation).



Operational logs report per-page counts and final scan totals,
successful termination counts, scan completeness, deadline exits, and
orphan termination. These observations replace the old full-fleet
before/after count on the EC2 path; dashboard migration and the
additional per-instance GitHub API cost are documented. EC2 paging
honors request cancellation before sending a request.
guicaulada added a commit that referenced this pull request Oct 27, 2026
Missed deregistration events can leave offline GitHub runners behind
after their compute resources disappear. The termination watcher handles
termination events and busy-runner retries, but cannot discover
historical registrations or missed events. Scale-down also cannot
discover this backlog because it starts from existing compute instances.
This scheduled reconciliation complements both paths.

Add an opt-in `modules/registration-janitor` module deploying a separate
scheduled Lambda from the existing termination-watcher archive with
GitHub App/GHES authentication. Discovery processes each runner-group
page immediately, verifies candidates individually, and queues work
before fetching later pages. Candidate errors are isolated; unavailable
pages are skipped, with advancement to another group after three
consecutive page failures. Retained instances and failed checks do not
consume the queued-candidate limit.

Scanning is stateless. Every invocation starts from current GitHub
inventory; registrations deleted by earlier cleanup are no longer
listed. Pagination is local to each invocation. A deadline guard stops
starting new work with ten seconds remaining. Busy, retained, or failed
registrations may be checked again, and subsequent scans reconcile
shifting page boundaries.

Scope is an organization, explicit runner groups, an exact
account-exclusive runner-name prefix, and every AWS region using that
prefix. Any non-terminated EC2 state protects the registration. Offline,
non-busy registrations with absent instances enter SQS for a second
observation at least 15 minutes later. These messages carry candidate
identity and observation time for deletion safety. Confirmation searches
group membership page by page, then rechecks EC2 absence and current
GitHub identity/offline/busy state before deletion. Incomplete or failed
lookups never establish absence. Confirmation failures retry
independently through SQS and its dead-letter queue; duplicate deletion
treats 404 as success. Scope changes invalidate candidates, and
candidates expire after 24 hours. Dry-run is the default and suppresses
queueing and deletion.

The account-exclusive prefix and complete region list are required
configuration because tags cannot prove ownership after an instance
disappears. This implementation handles organization EC2 runners in one
account and multiple regions. Repository runners and cross-account
inventory remain outside its scope. Delayed observations reduce races
but are not an atomic GitHub/EC2 transaction.

Additional GitHub Apps are supported through the existing credential
manifest format. Discovery selects an App for each group page, and
confirmation selects one per candidate. Selection prefers observed
remaining quota, skips throttled Apps for one minute when another is
available, and tries another configured App after authentication
failure. App JWT and installation-token authentication use the same
credential and resolve access for the requested owner. Terraform passes
the optional manifest and grants read access to its configured
credential parameters. Single-App configurations remain supported.
Existing termination-watcher behavior is unchanged by this PR.

The GitHub cleanup flow uses a compute-provider interface for
runner-name interpretation, backing-resource lookup, and inventory
scope. EC2 is the first bundled provider; it performs per-candidate
lookups across the configured regions. Providers must throw on
incomplete or failed lookups rather than report absence. Provider type
and normalized scope are included in candidate validation. Additional
providers can be registered without changing GitHub discovery or
confirmation; this Terraform module currently supplies EC2 configuration
and permissions.

Validation: 109 termination-watcher package tests, 315 compute-provider
tests, and four mocked Terraform tests pass. A non-EC2 test provider
exercises discovery and confirmation without AWS inventory calls.
Regressions cover fresh discovery after earlier deletion, queueing
before later-page failure, independent failures, candidate-budget
fairness, paged membership verification, deadline handling, paired App
authentication, quota selection, authentication fallback, and
manifest/IAM wiring. Runtime TypeScript, ESLint, Prettier, Terraform
validation/formatting, generated documentation, Lambda bundle build, and
diff checks pass. Optional package-wide coverage thresholds already fail
in existing deregistration/retry code on unchanged main; no thresholds
were lowered. TFLint is unavailable locally. No AWS deployment or live
registration deletion was performed.

Independent companion PRs: #5463 (incremental scale-down) and #5464
(incremental SSM cleanup).


Compute-provider configuration and IAM are separated from shared cleanup
permissions. Deployment uses one janitor per provider and ownership
scope. Confirmation checks its time budget before authentication,
membership pages, resource lookup, GitHub recheck, and deletion;
unfinished records are retried independently.


Each invocation reuses installation clients per App, owner, runner type,
and GitHub endpoint while re-evaluating quota/cooldown selection before
cache lookup. Authentication failures are not cached, and client caches
do not persist between invocations. Discovery emits a summary of scanned
pages, queued candidates, retained resources, dry-run candidates,
failures, and stop reason. Both handler paths set fresh request context.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants