Skip to content

Rebuild the listener when its runner scale set is gone from the Actions service - #4740

Open
sebdanielsson wants to merge 3 commits into
actions:masterfrom
sebdanielsson:fix/listener-rebuild-on-gone-scale-set
Open

sebdanielsson wants to merge 3 commits into
actions:masterfrom
sebdanielsson:fix/listener-rebuild-on-gone-scale-set

Conversation

@sebdanielsson

@sebdanielsson sebdanielsson commented Nov 9, 2026 •

Copy link
Copy Markdown

Fixes #4370.

Problem

#4571 made the controller re-register a runner scale set that is gone from the Actions service, but only when the AutoscalingListener has to be created. A listener that is already running when its scale set disappears (deleted from the org settings, or dropped server-side as described in this comment on #4370) is never healed:

  • the scale set ID is part of the AutoscalingListener spec, so every replacement pod fails createMessageSession with RunnerScaleSetNotFoundException and exits;
  • the listener controller only replaces the pod, so the listener crash-loops forever;
  • nothing changes on the AutoscalingRunnerSet, so its controller never revisits the ID.

Today the only way out is deleting the AutoscalingListener by hand.

Fix

  • Listener: when message session creation fails with scaleset.NotFoundError and the Actions exception is RunnerScaleSetNotFoundException, exit with a dedicated code (ExitCodeRunnerScaleSetNotFound = 3, defined in cmd/ghalistener/config next to the rest of the controller/listener contract). Every other failure still exits 1.
    • The exception name is required because the scaleset client refreshes its admin token inside session creation. A 404 from the GitHub endpoints behind that refresh (installation token, registration token, runner registration: an uninstalled app, lost repository access, a renamed repository) also surfaces as NotFoundError, but says nothing about the scale set.
    • The scaleset client has no sentinel for this exception, so it is matched by name, the same way the client classifies AgentNotFoundException and friends.
  • AutoscalingListener controller: when the dead listener pod exited with that code, delete the AutoscalingListener instead of only its pod. Recovery then goes through the existing path: the AutoscalingRunnerSet controller sees the listener is gone, calls runnerScaleSetGone, re-registers the scale set, re-points the EphemeralRunnerSet with a bumped ActionableRevision, and builds a listener with the new ID.
  • AutoscalingRunnerSet controller: if re-registration resolves the same ID that runnerScaleSetGone just reported missing (the lookups by ID and by name disagree), the annotation patch is a no-op and nothing would bring the reconciler back to create the listener. It now creates the listener in the same reconcile instead of stalling with no listener at all.

Notes

  • Version skew is harmless. An older listener image exits 1 as before, and an older controller treats exit code 3 as any other failure and recreates the pod.
  • The original gha-runner-scale-set-0.13.1 installation fails with RunnerScaleSetNotFoundException #4370 report (listener left on an old ID after an upgrade while the annotation holds the new one) is already handled on master by listener spec drift detection. This PR closes the remaining out-of-band deletion case.
  • A persistently inconsistent service still loops. If the Actions service keeps answering 404 by ID and on session creation while resolving the scale set by name, the listener is rebuilt on every failure: about the rate of today's pod crash loop, with a full listener teardown instead of a pod restart. ARC cannot resolve that state either way; this keeps retrying instead of sitting without a listener.
  • Out of scope:
    • A listener template that overrides restartPolicy restarts the container in place, which the existing dead-pod handling does not see either.
    • runnerScaleSetGone still treats any NotFoundError as gone, so a token-refresh 404 in the controller logs a misleading "no longer exists". It does no harm (the lookups in createRunnerScaleSet fail on the same 404 and back off), and tightening it needs knowing what body GetRunnerScaleSetByID returns for a missing scale set.

Tests

  • cmd/ghalistener:
    • TestExitCodeFromSessionCreation drives the real scaleset client against an httptest server. A RunnerScaleSetNotFoundException from the sessions endpoint exits 3; a 404 from the registration-token endpoint exits 1. The second case fails with the earlier not-found-only check.
    • TestExitCode covers other session failures, a not-found outside session creation, and a generic error.
  • autoscalinglistener_controller_test.go: a listener pod terminated with ExitCodeRunnerScaleSetNotFound leads to the AutoscalingListener being deleted.
  • autoscalingrunnerset_listener_recovery_test.go: runs both reconcilers on one manager and checks the full chain, through the listener finalizer: the scale set is re-registered, the EphemeralRunnerSet and a new listener use the new ID, and the listener gets a pod. It fails against master's listener controller.
  • autoscalingrunnerset_controller_test.go: when the lookup by name resolves the ID that was reported missing, the listener is created with it and no second scale set is registered. It fails without the controller change.
  • go test ./cmd/ghalistener/... ./controllers/actions.github.com/... passes locally (envtest k8s 1.37.0), and golangci-lint v2.15.0 reports no issues.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NZ5218pW65sD2NiDqjXYLQ

…ns service

A listener whose runner scale set was deleted on the Actions service side
crash-loops forever: the scale set ID is part of the AutoscalingListener spec,
so every replacement pod fails session creation with the same 404, and the
re-registration added in actions#4571 only runs when the listener has to be created.

The listener now exits with a dedicated code when session creation returns
not-found. The AutoscalingListener controller deletes the listener instead of
only its pod when it sees that code, which routes recovery through the
existing AutoscalingRunnerSet path: confirm the scale set is gone, register
it again, re-point the EphemeralRunnerSet, and build a listener with the new
ID.

Fixes actions#4370

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NZ5218pW65sD2NiDqjXYLQ
sebdanielsson and others added 2 commits November 9, 2026 23:05
The scaleset client refreshes its admin token inside session creation, so a
404 from the registration-token or runner-registration endpoints also
surfaced as scaleset.NotFoundError. Lost repository access or a renamed
repository would then tear down and rebuild the whole listener on every
crash. Require the Actions exception name as well, and test the
classification against the real client over HTTP.

When re-registration resolves the same ID that was reported missing, the
annotation patch is a no-op and nothing would bring the reconciler back to
create the listener. Create it in the same reconcile instead.

Add an end-to-end spec that runs both reconcilers, covering the hand-off
through the listener finalizer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NZ5218pW65sD2NiDqjXYLQ

This branch has not been deployed

No deployments
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.

gha-runner-scale-set-0.13.1 installation fails with RunnerScaleSetNotFoundException

1 participant