Skip to content

Fail the job when the worker process cannot be launched - #4790

Draft
salmanmkc wants to merge 3 commits into
mainfrom
salmanmkc-fail-job-on-worker-launch-error
Draft

salmanmkc wants to merge 3 commits into
mainfrom
salmanmkc-fail-job-on-worker-launch-error

Conversation

@salmanmkc

@salmanmkc salmanmkc commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When Runner.Worker can't be started at all (e.g. it's blocked by an application control policy such as Windows Smart App Control, Code Integrity event 3077), the job is left assigned and in progress with zero steps until it's cancelled manually.

Root cause in JobDispatcher.RunAsync:

  1. ProcessInvoker.ExecuteAsync is async, so the Win32Exception from Process.Start is captured in a faulted workerProcessTask rather than thrown.
  2. The listener then tries to send the job message over a pipe nobody is reading. This (or awaiting the faulted worker task) throws a non-OperationCanceledException, which isn't handled.
  3. The exception escapes RunAsync without calling CompleteJobRequestAsync and without cancelling lockRenewalTokenSource. Disposing the CTS doesn't cancel it, so the lock keeps being renewed every 60s and the service thinks the job is still running.

Fix

Behind a new feature flag actions_runner_fail_job_on_worker_launch_failure, after StartServer the listener checks whether the worker task has already faulted. If so it:

  • logs and prints The runner failed to start the worker process 'Runner.Worker': <reason>
  • reports it to the service: an error issue on the job timeline record + JobCompletedEvent(Failed) for classic jobs, or CompleteJobAsync(Failed) with an error annotation for run-service jobs
  • stops lock renewal and completes the job request as Failed

The issue is tagged with a new internal telemetry value WORKER_LAUNCH_FAILURE.

Tests

Three L0 tests in JobDispatcherL0 simulate a launch Win32Exception:

  • classic: job completes as Failed, the job message is never sent, lock renewal stops, the job timeline record is marked failed with the launch error issue (tagged WORKER_LAUNCH_FAILURE), and a failed JobCompletedEvent is raised
  • run service: same, plus CompleteJobAsync(Failed) with an annotation containing the launch error
  • flag off: old behavior is kept, the job message is still sent to the worker and nothing is reported or completed by the listener

Manual end-to-end test

Built the runner layout from this branch (osx-arm64), registered it as a self-hosted runner on a test repo, and made bin/Runner.Worker non-executable (chmod -x) to simulate the launch being blocked.

  • Flag off (current behavior): job stays in_progress with 0 steps; listener keeps renewing the lock every 60s; a normal cancel does not complete it, and the runner can't pick up the next queued job until the stuck run is force-cancelled.
  • Flag on (forced on locally): job completes as failure within ~1s with the annotation The runner failed to start the worker process 'Runner.Worker': An error occurred trying to start process '.../bin/Runner.Worker' ... Permission denied; lock renewal stops.
  • After restoring chmod +x, the same runner picked up the next job and it succeeded.

Notes for reviewers

  • I noticed the existing DispatchesJobRequest / DispatchesOneTimeJobRequest tests throw early on an unregistered IJobNotification singleton and pass vacuously. Not changed here.
  • Other non-cancellation exceptions in this section can still leave lock renewal running; this PR only addresses the launch failure case.
  • The flag is read from the job message variables, so the service needs to send actions_runner_fail_job_on_worker_launch_failure as a job variable for this to take effect. Until then it's a no-op.

If Runner.Worker fails to start (for example when blocked by an
application control policy such as Windows Smart App Control), the
launch exception was captured in the faulted worker task. The listener
then failed to send the job message, the exception escaped RunAsync
without completing the job request, and lock renewal kept running, so
the job stayed in progress with zero steps.

Behind the actions_runner_fail_job_on_worker_launch_failure feature
flag, detect the faulted launch, report an error issue/annotation,
stop lock renewal and complete the job as failed.
@salmanmkc
salmanmkc force-pushed the salmanmkc-fail-job-on-worker-launch-error branch from 7dd646f to c241814 Compare October 16, 2026 19:12
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.

1 participant