actions-runner-controller/github/actions
Rob Howie ff7b81dc8f fix: add health check to detect and recover stale EphemeralRunner registrations
fix: add health check to detect and recover stale EphemeralRunner registrations

## Summary

Adds a GitHub-side registration health check to the `EphemeralRunnerReconciler`. During reconciliation of a running EphemeralRunner that has a valid `RunnerId`, the controller now calls `GetRunner()` against the GitHub Actions API to verify the registration still exists. If the API returns 404 (registration gone), the runner is marked as failed so the `EphemeralRunnerSet` can provision a replacement.

This also fixes `deleteRunnerFromService` to tolerate 404 from `RemoveRunner`, since a runner whose registration was already invalidated will also 404 on removal. Previously this caused `markAsFailed` to error and trigger a requeue loop, preventing cleanup of stale runners.

A redundant pod phase check was removed from the health check path — `checkRunnerRegistration` is only called from within the `cs.State.Terminated == nil` branch (container confirmed running), so the phase check was unnecessary and could cause false negatives since the local `EphemeralRunner` object may not have the updated phase yet.

## Changes

- **`ephemeralrunner_controller.go`**: New `checkRunnerRegistration()` method that calls `GetRunner()` and returns unhealthy only on confirmed 404. Transient API errors (500, timeouts, etc.) are logged and ignored to avoid false positives. Called during reconciliation when a running pod has a non-zero `RunnerId`.
- **`ephemeralrunner_controller.go`**: `deleteRunnerFromService()` now treats 404 from `RemoveRunner` as success, since the runner is already gone.
- **`ephemeralrunner_controller_test.go`**: Two new test cases — one verifying a 404 from `GetRunner` marks the runner as failed, another verifying a 500 does not. Both simulate a running pod container status before the health check triggers.
- **`fake/client.go`**: New `WithRemoveRunnerError` option for the fake client to support testing the 404 removal path.

## Issues Fixed

### Directly fixes

- **#4396** — *ARC runners did not recover automatically after GitHub Outage*: Runners that lost their GitHub-side registration during the [2026-03-05 GitHub Actions incident](https://www.githubstatus.com/incidents/g9j4tmfqdd09) remained stuck indefinitely because the `EphemeralRunnerReconciler` never verified registration validity. This change adds exactly that verification — on each reconciliation of a running runner, `GetRunner()` confirms the registration exists. If it returns 404, the runner is marked failed and replaced.

- **#4395** — *GHA Self-hosted runner pods are running but the runner status is showing offline*: Runner pods were running for 5-7+ hours showing "Listening for Jobs" but marked offline in GitHub. The pods' registrations were invalidated server-side (same incident), but the controller had no mechanism to detect this. The new health check detects the 404 and triggers cleanup, preventing these zombie runners from accumulating.

### Partially addresses

- **#4397** — *Stale TotalAssignedJobs causes permanent over-provisioning after platform incidents*: This issue has two components: (1) zombie runner pods occupying slots, and (2) the listener's `TotalAssignedJobs` remaining inflated. This PR fixes component (1) — by detecting and cleaning up runners with invalidated registrations, the controller stops accumulating zombie pods. However, the listener-side `TotalAssignedJobs` inflation (a separate code path in `listener.go` → `worker.go`) is not addressed by this change and still requires either a session reconnect mechanism or CR deletion to clear.

- **#4307** — *Ephemeral Runners seem to get stuck when job is canceled or interrupted*: Reports runners getting stuck with `Registration <uuid> was not found` errors in BrokerServer backoff loops after job cancellation. The health check would detect that the registration is gone (404 from `GetRunner`) and mark these runners as failed rather than leaving them in an infinite backoff loop.

- **#4155** — *EphemeralRunner and its pods left stuck Running after runner OOMKill*: Runners that are OOMKilled can end up in a state where the pod is technically running but the runner process is non-functional, and the registration may become stale. The health check provides a secondary detection mechanism — if the GitHub-side registration is invalidated for a non-functional runner, it will be caught and cleaned up.

- **#3821** — *AutoscalingRunnerSet gets stuck thinking runners exist when they do not*: Reports the AutoscalingRunnerSet believing runners exist when no pods are present, requiring CR deletion to recover. While the root cause may vary, stale registrations that the controller cannot clean up (due to `RemoveRunner` 404 errors causing requeue loops) are one contributing factor. The 404 tolerance in `deleteRunnerFromService` directly addresses this cleanup path.

## Test Plan

- [x] Unit test: `GetRunner` returning 404 → runner marked as failed
- [x] Unit test: `GetRunner` returning 500 → runner NOT marked as failed (transient error tolerance)
- [x] Unit test: `RemoveRunner` returning 404 → deletion succeeds (runner already gone)
- [ ] Integration: Deploy to a test cluster, manually delete a runner's registration via the GitHub API, verify the controller detects and replaces it
- [ ] Integration: Simulate incident conditions by blocking `broker.actions.githubusercontent.com` for running runners, then unblocking — verify stale runners are detected and replaced
2026-03-09 09:31:17 +00:00
..
fake fix: add health check to detect and recover stale EphemeralRunner registrations 2026-03-09 09:31:17 +00:00
testdata Update all dependencies, conforming to the new controller-runtime API (#3949) 2025-03-11 15:52:52 +01:00
testserver Update all dependencies, conforming to the new controller-runtime API (#3949) 2025-03-11 15:52:52 +01:00
actions_server_test.go Update all dependencies, conforming to the new controller-runtime API (#3949) 2025-03-11 15:52:52 +01:00
byte_order_mark_test.go Remove network requests from actions.NewClient (#2219) 2023-01-31 10:55:23 +00:00
client.go Switch client to scaleset library for the listener and update mocks (#4383) 2026-02-24 14:17:31 +01:00
client_generate_jit_test.go Include the HTTP status code in jit error (#4361) 2026-01-29 16:40:17 +01:00
client_job_acquisition_test.go upgrade(golangci-lint): v2.1.2 (#4023) 2025-04-17 16:14:31 +02:00
client_proxy_test.go Add support for proxy (#2286) 2023-02-21 17:33:48 +00:00
client_runner_scale_set_message_test.go Propagate max capacity information to the actions back-end (#3431) 2024-04-16 14:00:40 +02:00
client_runner_scale_set_session_test.go Include more context to errors raised by github/actions client (#4032) 2025-04-11 11:36:15 +02:00
client_runner_scale_set_test.go Refactor actions client error to include request id (#3430) 2024-04-16 12:57:44 +02:00
client_runner_test.go upgrade(golangci-lint): v2.1.2 (#4023) 2025-04-17 16:14:31 +02:00
client_tls_test.go Update all dependencies, conforming to the new controller-runtime API (#3949) 2025-03-11 15:52:52 +01:00
config.go Treat `.ghe.com` domain as hosted environment (#2480) 2023-04-04 14:43:45 -04:00
config_test.go Typo in test name caused test to not execute (#4330) 2025-11-27 15:31:57 +01:00
errors.go Fix `AcivityId` typo in error strings (#4359) 2026-01-21 01:14:26 +01:00
errors_test.go Fix `AcivityId` typo in error strings (#4359) 2026-01-21 01:14:26 +01:00
github_api_request_test.go Add exponential backoff when generating runner reg tokens (#3724) 2024-09-04 12:23:31 +02:00
identifier_test.go Allow use of client id as an app id (#4057) 2025-05-16 16:21:06 +02:00
mocks_test.go Fix tests and generate mocks (#4384) 2026-02-24 13:36:01 +01:00
multi_client.go Azure Key Vault integration to resolve secrets (#4090) 2025-06-11 15:53:33 +02:00
multi_client_test.go Azure Key Vault integration to resolve secrets (#4090) 2025-06-11 15:53:33 +02:00
sessionservice.go Switch client to scaleset library for the listener and update mocks (#4383) 2026-02-24 14:17:31 +01:00
types.go Remove ephemeral runner when exit code != 0 and is patched with the job (#4239) 2025-09-17 21:40:37 +02:00
user_agent_test.go Modify user agent format with subsystem and is proxy configured information (#3116) 2023-12-08 13:16:29 +01:00