Skip to content

Support return job result as exitcode in hosted runner.#4233

Merged
TingluoHuang merged 1 commit intomainfrom
users/tihuang/setuptelemtry
Feb 10, 2026
Merged

Support return job result as exitcode in hosted runner.#4233
TingluoHuang merged 1 commit intomainfrom
users/tihuang/setuptelemtry

Conversation

@TingluoHuang
Copy link
Member

@TingluoHuang TingluoHuang requested a review from a team as a code owner February 10, 2026 01:14
Copilot AI review requested due to automatic review settings February 10, 2026 01:14
public interface IJobDispatcher : IRunnerService
{
bool Busy { get; }
TaskCompletionSource<bool> RunOnceJobCompleted { get; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't use the bool other than set it to true before.
So i am expose the job result via it.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for hosted runners to return the completed job’s TaskResult as the listener process exit code, enabling improved telemetry/alerting on job failures.

Changes:

  • Change IJobDispatcher.RunOnceJobCompleted from TaskCompletionSource<bool> to TaskCompletionSource<TaskResult>.
  • Update Runner run-once loop to optionally translate the completed job TaskResult into the process return code when ACTIONS_RUNNER_RETURN_JOB_RESULT_FOR_HOSTED is enabled.
  • Update L0 tests to reflect the new TaskResult-based completion signal.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Runner.Listener/Runner.cs Adds hosted-runner env-var toggle and returns exit code based on TaskResult for run-once execution.
src/Runner.Listener/JobDispatcher.cs Propagates run-once job completion as a TaskResult instead of a boolean.
src/Test/L0/Listener/RunnerL0.cs Updates mocks to complete run-once with TaskResult.Succeeded.
src/Test/L0/Listener/JobDispatcherL0.cs Updates assertions to validate TaskResult completion.
Comments suppressed due to low confidence (2)

src/Runner.Listener/JobDispatcher.cs:352

  • RunOnceAsync initializes jobResult to Succeeded and sets _runOnceJobCompleted in finally. If RunAsync(...) throws, the completion source will still be set to Succeeded, which can cause hosted runners to exit with a success code even though dispatch failed. Consider catching exceptions around RunAsync and setting an appropriate failure result (or setting an exception on the TCS) before signaling completion.
        private async Task RunOnceAsync(Pipelines.AgentJobRequestMessage message, string orchestrationId, WorkerDispatcher previousJobDispatch, CancellationToken jobRequestCancellationToken, CancellationToken workerCancelTimeoutKillToken)
        {
            var jobResult = TaskResult.Succeeded;
            try
            {
                jobResult = await RunAsync(message, orchestrationId, previousJobDispatch, jobRequestCancellationToken, workerCancelTimeoutKillToken);
            }
            finally
            {
                Trace.Info("Fire signal for one time used runner.");
                _runOnceJobCompleted.TrySetResult(jobResult);
            }

src/Runner.Listener/Runner.cs:592

  • This PR adds new behavior to return the run-once job TaskResult as the listener process exit code, but there doesn’t appear to be an L0 test that sets returnRunOnceJobResult/ACTIONS_RUNNER_RETURN_JOB_RESULT_FOR_HOSTED and asserts the returned code matches TaskResultUtil.TranslateToReturnCode(...) (including a failure case). Adding a focused unit test would prevent regressions in the exit-code mapping.
                                    if (returnRunOnceJobResult)
                                    {
                                        try
                                        {
                                            var jobResult = await jobDispatcher.RunOnceJobCompleted.Task;
                                            return TaskResultUtil.TranslateToReturnCode(jobResult);
                                        }

@TingluoHuang TingluoHuang force-pushed the users/tihuang/setuptelemtry branch from 806598c to 14a8876 Compare February 10, 2026 01:51
@TingluoHuang TingluoHuang merged commit cdb77c6 into main Feb 10, 2026
12 checks passed
@TingluoHuang TingluoHuang deleted the users/tihuang/setuptelemtry branch February 10, 2026 14:31
dawidmalina pushed a commit to dawidmalina/github-runner that referenced this pull request Feb 26, 2026
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