← Back to Pull requests

fix(ephemeralrunner): fail runners whose image cannot be pulled #4672

Open
KR-Ravindra opened this pull request with 152 lines diff across 2 files
View on GitHub
KR-Ravindra KR-Ravindra commented on Sep 19, 2026 23:34 UTC
Author

Problem

A runner pod whose image cannot be pulled stays Pending forever and the EphemeralRunner never fails.

reconcileOwnerAndPod inspects the runner container only through cs.State.Terminated. A container waiting on
InvalidImageName, ErrImageNeverPull, ImagePullBackOff or ErrImagePull never terminates, so the reconciler keeps
taking the cs.State.Terminated == nil branch ("runner is still running"), Status.Failures stays empty, and the
scale set keeps counting that runner as pending work. Nothing times it out, so the slot is held until someone deletes
the pod and the EphemeralRunner by hand.

Reproduces on master with a runner template pointing at ghcr.io/actions/actions-runner:tag-that-does-not-exist,
an invalid reference, or imagePullPolicy: Never with the image absent from the node. Reported in #4654.

Fix

Treat an unpullable image as a pod failure and route it through the existing failure path
(deleteEphemeralRunnerOrPod), so it uses the same backoff and maxFailures accounting as every other pod failure:
the pod is recreated, and a permanently broken image walks the runner to Failed instead of hanging.

InvalidImageName and ErrImageNeverPull cannot resolve on their own, so they count immediately. ImagePullBackOff
and ErrImagePull do recover in practice (registry rate limits, a node that has just come up), so they only count
once the pod has been waiting longer than a 5 minute grace period.

No API or configuration change.

How tested

go test ./controllers/actions.github.com/ passes (envtest, KUBEBUILDER_ASSETS from make setup-envtest).

Two new tests:

  • TestImagePullFailure, a table test over the waiting reasons and the grace-period boundary.

  • An envtest case, "It should fail the runner when its image can never be pulled", which puts the runner container in

  • InvalidImageName and expects a recorded failure plus a recreated pod. With the new branch disabled it fails:

    [FAILED] Timed out after 20.001s.
    the image error should be recorded as a runner failure
    

    One open question for you: 5 minutes is a guess for the retryable reasons. Happy to make it configurable on the
    controller, or to drop the grace period and only act on the two permanent reasons, whichever you prefer.

    Fixes #4654

    _Implementation assisted by an AI agent I operate; I reviewed the diff and ran the tests myself._

    Diff: 152 lines (+152 / -0) across 2 files Reviewer: KR-Ravindra Review duration: 21263m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.49) × (1 − Review Confidence (0.79)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.49 · 152 lines diff across 2 files
    0.49
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 2 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    79%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.301
    Self Review self_review
    0.140
    Real PR Conversation Timeline
    4 items
    Copilot Copilot commented on code on Sep 20, 2026 01:57 UTC
    Code Review
    controllers/actions.github.com/ephemeralrunner_controller.go:1
    @@ -444,6 +475,15 @@ func (r *EphemeralRunnerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
     		log.Info("Waiting for runner container status to be available")
     		return ctrl.Result{}, nil
     
    +	case imagePullStuck:
    +		log.Info(
    +			"Runner container cannot pull its image, deleting pod as failed so it is retried and eventually fails",
    +			"reason", imagePullReason,
    +			"message", cs.State.Waiting.Message,
    +			"image", cs.Image,
    +		)
    +		return ctrl.Result{}, r.deleteEphemeralRunnerOrPod(ctx, &ephemeralRunner, pod, log)

    In the image-pull failure path the controller deletes the pod via deleteEphemeralRunnerOrPod/deletePodAsFailed, which records EphemeralRunner.Status.Reason/Message from pod.Status.{Reason,Message}. For image pull errors the pod typically stays in PodPending with empty pod.Status fields (the details are in cs.State.Waiting), so the failure will be counted but the EphemeralRunner status won’t indicate why it failed.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 20, 2026 01:57 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🟡 Changes recommended

    The image-pull failure path currently won’t persist the waiting reason/message onto the EphemeralRunner status (it uses empty pod.Status fields for PodPending), reducing debuggability and observability of the new failure mode.

    Get a fresh assessment by requesting another Copilot review.

    Review effort: Lite
    Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>

    <details open>
    <summary><strong>Open (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Image pull failures lose the pod error details](#discussion_r4055683429) · New

  • </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    This PR fixes a reconciliation gap in the EphemeralRunner controller where runner pods stuck in Pending due to unpullable images would never be treated as failed, causing the EphemeralRunner to remain non-terminal and hold capacity indefinitely.

    Changes:

  • Add image-pull waiting-state detection with a 5-minute grace period for retryable reasons (ImagePullBackOff, ErrImagePull) and immediate handling for permanent reasons (InvalidImageName, ErrImageNeverPull).

  • Route “image can’t be pulled” pods through the existing failure/deletion path so retries and maxFailures accounting apply.

  • Add unit and envtest coverage for the waiting-reason logic and the end-to-end controller behavior.
  • | File | Description |
    | ---- | ----------- |
    | controllers/​actions.github.com/​ephemeralrunner_controller.go | Detects image-pull waiting reasons and deletes/retries pods that are stuck on unpullable images. |
    | controllers/​actions.github.com/​ephemeralrunner_controller_test.go | Adds a unit table test for image-pull logic and an envtest validating runner failure + pod recreation on InvalidImageName. |
    </details>

    ---

    💡 <a href="/actions/actions-runner-controller/new/master?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>

    KR-Ravindra KR-Ravindra commented on code on Sep 21, 2026 05:57 UTC
    Code Review
    controllers/actions.github.com/ephemeralrunner_controller.go:1
    @@ -444,6 +475,15 @@ func (r *EphemeralRunnerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
     		log.Info("Waiting for runner container status to be available")
     		return ctrl.Result{}, nil
     
    +	case imagePullStuck:
    +		log.Info(
    +			"Runner container cannot pull its image, deleting pod as failed so it is retried and eventually fails",
    +			"reason", imagePullReason,
    +			"message", cs.State.Waiting.Message,
    +			"image", cs.Image,
    +		)
    +		return ctrl.Result{}, r.deleteEphemeralRunnerOrPod(ctx, &ephemeralRunner, pod, log)

    Good catch, fixed in b4b10d0b. You are right that the pod is still Pending on this path, so pod.Status.Reason and pod.Status.Message are both empty and the failure was being recorded with nothing to explain it.

    deletePodAsFailed now falls back to the runner container's waiting state when pod.Status.Reason is empty, so the EphemeralRunner reports InvalidImageName / ImagePullBackOff and the kubelet's message. Doing it there rather than in the new branch also covers any other failure where the pod never started. The envtest case now asserts Status.Reason == "InvalidImageName" alongside the failure count and the pod re-creation.

    Drafted with AI assistance and checked against the code before posting.

    Reviewers
    Assignees
    KR-Ravindra KR-Ravindra
    Labels
    risk: low confidence: 79.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.5% (MEDIUM) · Higher = larger blast radius
    48.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 79.3% · Lower = rushed or shallow review
    79.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 10% · Safe to merge
    10%