Repository navigation
Fix WaitForHelixJobCompletion pre-expansion race (ExitCode -4 / Send to Helix 404) - #17130
Conversation
WaitForHelixJobCompletion waited 1s after submission then polled Job.PassFailAsync, treating the job complete when Working==0 && Total!=0. Immediately after submission the only work item present is the system item "HelixController Work Queueing" (finishes ~instantly), so under HelixController expansion lag the wait returned prematurely. Downstream this completed the AzDO Test Run early; real work items later reported to a Completed run, were rejected, and ended up ExitCode -4, with the Send-to-Helix download 404ing. Mirror the robust completion detection the JobMonitor already uses: - Complete when Job.DetailsAsync reports Finished != null, or when the real work items (excluding "HelixController Work Queueing") number at least InitialWorkItemCount and all have terminal ExitCodes. - Add a 4-hour max-wait fallback that errors clearly if a job never expands and never reports a job-level error. - Preserve job-level error handling and cancellation behavior. Adds unit tests covering the system-item-only, all-expected-terminal, and job-level-Finished cases. Fixes dotnet#17129 Co-authored-by: Copilot <[email protected]> Copilot-Session: be2120bf-5298-4ac7-aebd-7344585914df
There was a problem hiding this comment.
Pull request overview
This PR fixes a race in WaitForHelixJobCompletion where a Helix job could be treated as “complete” before the controller expands and publishes the real work items, leading to early AzDO test-run completion and downstream ExitCode -4 / “Send to Helix” 404 failures.
Changes:
- Replaces the pre-expansion-prone
PassFailAsynccompletion heuristic with jobDetailsAsync+ work-item enumeration, filtering out the system “HelixController Work Queueing” work item. - Adds a max-wait timeout path intended to fail clearly if a job never expands and never reports a job-level error.
- Adds unit tests covering system-item-only behavior, terminal work-item completion, and job-level
Finishedshort-circuiting.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Microsoft.DotNet.Helix/Sdk/WaitForHelixJobCompletion.cs | Updates completion detection to avoid pre-expansion false positives by using JobDetails + real work-item terminal detection, and adds a timeout fallback. |
| src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/WaitForHelixJobCompletionTests.cs | Adds tests for the new “don’t complete on system item” and “complete when expected items are terminal / job finished” logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Compute the real work-item list before the completion check so the job-level Finished path also logs 'is completed with N finished work items' as before, instead of a bare 'is completed'. Co-authored-by: Copilot <[email protected]> Copilot-Session: be2120bf-5298-4ac7-aebd-7344585914df
Remove the 4-hour MaxHelixJobCompletionWait fallback. The original task had no internal wall-clock cap and relied on the cancellation token (AzDO job/pipeline timeout or build cancellation) to break the wait loop; a fixed cap risks failing legitimately long-running Helix jobs. The InitialWorkItemCount + terminal-exit-code check fixes the premature-completion race, and the cancellation token continues to bound any expansion hang as before. Co-authored-by: Copilot <[email protected]> Copilot-Session: be2120bf-5298-4ac7-aebd-7344585914df
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
this isn't implemented in the code from what I can see (I actually think this is better, not sure if we have some stress tests that take longer) |
That's because I yelled at it and told it not to get too uppity and implement new features ;) |
Fixes #17129.
Problem
WaitForHelixJobCompletionwaited 1 second after submitting a Helix job, then polledJob.PassFailAsyncand treated the job as complete whenpf.Working == 0 && pf.Total != 0. Immediately after submission the only work item that exists is the system itemHelixController Work Queueing, which finishes almost instantly (exit 0). The real work items are not written until the HelixController asynchronously expands the job. Under expansion lag (queue/controller congestion) the poll sawTotal=1, Working=0and returned prematurely.Downstream this completed the AzDO Test Run early; the real work items ran later, reported to a Completed test run, were rejected (
TestCaseResults cannot be added or updated for a test run which is in Completed state), ended upExitCode -4, and the "Send to Helix" download 404'd.Fix
Mirror the robust completion detection the JobMonitor already uses (
JobMonitorRunner.AreAllWorkItemsTerminalAsync+HelixService.ListWorkItemsAsync):Job.DetailsAsyncreportsFinished != null, or when the real work items (excludingHelixController Work Queueing) number at leastInitialWorkItemCountand all have terminalExitCodes.DetailsAsyncis now called every poll (it suppliesFinished/InitialWorkItemCount), so the previous% 12-iteration throttle on the error check is no longer needed — error checking now happens every poll as well.Tests
Adds
WaitForHelixJobCompletionTestscovering: system-item-only does not complete, completes once expected real work items are terminal, and job-levelFinishedshort-circuits.Notes
Each poll now makes two API calls (
DetailsAsync+WorkItem.ListAsync) instead of onePassFailAsync, matching the JobMonitor pattern. This is a modest increase in API load, notablyListAsyncon very large jobs.