Skip to content

Keep the pod of a runner that has not recorded its ID during set cleanup - #4683

Merged
nikola-jokic merged 5 commits into
masterfrom
nikola-jokic-reproduce-busy-runner-cleanup
Sep 28, 2026
Merged

nikola-jokic merged 5 commits into
masterfrom
nikola-jokic-reproduce-busy-runner-cleanup

Conversation

@nikola-jokic

@nikola-jokic nikola-jokic commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Since #4681, a runner pod can start before EphemeralRunner.Status.RunnerID is recorded. Set cleanup could call RemoveRunner(0). If the service returned success or NotFound, it could then drop the registration finalizer and delete a busy runner's pod. The reproducer models that response; the live service's response to ID 0 has not been established.

Fix

  • Skip non-terminal ID-0 runners until their ID appears or they reach one minute old. Requeue and hold the applied spec revision while waiting; completed runners do not wait.
  • After the grace period, request deletion with the registration finalizer intact. Finalization recovers the real ID, reads pod state directly from Kubernetes, and checks with Actions before deleting a live pod. Busy means keep the pod and retry in 30s; other errors retry without dropping protection.
  • Validate positive IDs before initial publication and during cleanup. Regenerate invalid JIT data only when a direct read confirms no pod exists; otherwise retain the pod and secret for repair.
  • Resolve Actions credentials lazily, at most once per set-cleanup or finalizer reconcile. Finalizer name lookup and removal share the same client; later retries resolve it afresh. Credential failures do not block independent local zero-ID deletion requests.

Compared to 0.14.2

0.14.2 This release
ID publication Before pod creation After pod creation
Non-terminal ID-0 set cleanup Calls RemoveRunner(0); non-204 responses block cleanup Bounded wait, then deletion with finalizer protection; never removes ID 0
Registered runner with a reported job Asks the service Skips without a removal call
Finalizer, completed job Synchronous removal No call when already self-deregistered
Finalizer, stopped/missing pod Synchronous removal Confirms pod state, then queues removal
Finalizer, live pod Synchronous removal; 30s retry if busy Same busy guard, with ID recovery when needed

Cost and limits

Normal successful job completion and valid registration paths gain no additional network calls from identity validation or client reuse. Guarded finalization adds a direct Kubernetes pod read and, for live pods, a synchronous Actions call. Slow calls can occupy shared reconcile workers and indirectly delay provisioning; this has not been production-load benchmarked. Spec updates pause scaling while waiting for ID publication. One minute bounds the ID grace period, not total cleanup time. Invalid identity metadata may require repair, and this cannot prevent Kubernetes from terminating pods already being deleted.

Coverage

Regressions cover delayed ID/job publication, malformed identities and repair, stale caches, API/credential failures, busy/NotFound replies, and single credential resolution per finalizer retry. New regressions fail before their fixes; focused coverage passes 20 repetitions. All 33 targeted runner creation/finalization envtest cases pass after the latest change; the broader 75-case runner/set coverage passed on the preceding revision. Build and static analysis pass. These model pod state and service replies, not a live Actions job.

Since #4681 the runner controller records the runner ID only after the pod
exists, so a runner can be executing a job while its status still says 0.
Set cleanup asked the service to remove runner 0, took NotFound as success,
and deleted the runner, which deleted its live pod.

Set cleanup now never asks about ID 0. It waits up to a minute for the ID to
be recorded, holding the applied revision on a spec update, and deletes the
runner directly after that. The runner finalizer asks the service to remove
the registration before deleting a live pod, and requeues in 30s while the
runner is still executing a job.

Co-authored-by: Copilot App <[email protected]>
Copilot AI lite review requested due to automatic review settings September 24, 2026 10:56

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

🟡 Changes recommended

Unresolved critical and moderate cleanup-safety issues remain.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

This PR adds safe cleanup for runners whose IDs are not yet recorded and protects live pods during deregistration.

Changes:

  • Adds grace-period handling for unrecorded runner IDs.
  • Checks the Actions service before deleting live runner pods.
  • Adds focused tests and benchmark updates.
File Summary
controllers/​actions.github.com/​suite_test.go Configures test grace-period behavior.
controllers/​actions.github.com/​runner_unregistration_bench_test.go Updates benchmark pod state.
controllers/​actions.github.com/​ephemeralrunnerset_unrecorded_runner_id_test.go Tests delayed and missing runner IDs.
controllers/​actions.github.com/​ephemeralrunnerset_controller.go Implements ID grace-period cleanup. Review notes: ID-0 runners with jobs can bypass requeue (moderate, 4 votes); eager client resolution can block aged ID-0 cleanup (moderate, 1 vote).
controllers/​actions.github.com/​ephemeralrunner_controller.go Protects live pods during deregistration. Review note: terminal pod phases can bypass container-state checks and remove an active runner (critical, 2 votes).
controllers/​actions.github.com/​ephemeralrunner_controller_test.go Updates finalizer test fixtures.

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

Check container termination before bypassing the live-pod service guard, and apply the zero-ID grace period before skipping runners with reported jobs.

Co-authored-by: Copilot App <[email protected]>

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

🔵 Needs a closer look

The cleanup and finalizer behavior changes are safety-critical and warrant final human review.

Review effort: Lite
Findings: None

Resolved since last review (2)

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

🟡 Changes recommended

Address the unsafe handling of malformed runner IDs and apply the grace period to terminal zero-ID runners.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)

Reject malformed and non-positive registration IDs, read authoritative pod state before releasing finalizer protection, and resolve Actions credentials only when set cleanup needs a service removal.

Cover identity repair, stale caches, client failures, terminal runners, and busy/error/NotFound responses through the real reconcilers.

Co-authored-by: Copilot App <[email protected]>

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

🟡 Changes recommended

The unresolved identity-validation defect can leave runners permanently stuck, and credential resolution is duplicated.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Avoid resolving Actions client twice during finalizer reconcile

controllers/​actions.github.com/​ephemeralrunner_controller.go:1191

When the status ID is zero and the JIT Secret is absent, registeredRunnerID already resolves an Actions client at line 1123 to look up the registration. If that lookup finds an ID and this pod is live, this line resolves the credentials a second time in the same reconcile, contrary to the PR's at-most-once guarantee; the second read can also fail after identity recovery succeeded and unnecessarily block finalization. Memoize the client for the finalizer reconcile or return/reuse the client used by registeredRunnerID.

Share positive-ID parsing between registration and finalization. Preserve an invalid JIT secret if its pod exists or cannot be checked, and allow regeneration only when the pod is confirmed absent.

Resolve finalizer credentials lazily once per reconcile for both name lookup and busy-runner removal, while keeping retries fresh and completed-job paths free of credential reads.

Co-authored-by: Copilot App <[email protected]>

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

🔵 Needs a closer look

The safety-critical lifecycle changes span two reconcilers and synchronous external-service behavior, warranting final human review.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Pin OpenEBS to 4.6.1 and disable unused storage engines and logging components to avoid the inaccessible MinIO images. Wait for the provisioner to become ready and collect diagnostics when installation fails.

Co-authored-by: Copilot App <[email protected]>

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

🔵 Needs a closer look

Runner deletion now coordinates Kubernetes finalizers with live Actions service state, while validation remains based on modeled service responses rather than live jobs.

Review effort: Balanced
Findings: None

@nikola-jokic
nikola-jokic merged commit 67af96c into master Sep 28, 2026
28 checks passed
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