Skip to content

test: retry transient WSL2 import failures in Windows smoke setup - #338047

Merged
Dmitriy Vasyura (dmitrivMS) merged 2 commits into
mainfrom
agents/fix-smoke-wsl-import-retry
Sep 25, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 2 commits into
mainfrom
agents/fix-smoke-wsl-import-retry

Conversation

@dmitrivMS

@dmitrivMS Dmitriy Vasyura (dmitrivMS) commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Windows / Electron-Smoke fails before any smoke test runs, in Prepare WSL Dev Container smoke tests (run 36120855518, job 108025747515):

Import exit code: -1
Import output:
The virtual machine or container with the specified identifier is not running.
...
Explicit WSL2 import failed with exit code -1. WSL1 is not supported by this test.

Root cause

This is a transient failure of the inbox WSL on the hosted Windows Server 2022 image (wsl.exe 10.0.20348, kernel 5.10.16). It is not caused by a code change. The diagnostics added in #337242/#337438 show the sequence:

  • The WSL2 kernel MSI installs with exit code 0.
  • Microsoft-Windows-Hyper-V-Worker-Admin logs the WSL utility VM as started successfully at 09:59:56 and connected to virtual network at 09:59:59.
  • In the same second it logs 'Virtual Machine' was shut down by the guest operating system.
  • wsl --import then returns -1 with the HCS error above.
  • No distribution or files are left behind. LxssManager, vmcompute and hns are running, both optional features are enabled, and no reboot is pending.

So the machine is set up correctly; the first utility-VM boot just died. The PR that surfaced this (#337895) only touches chat code.

Frequency

These counts come from the last 400 runs of pr.yml (about 15 hours; 222 Windows Electron-Smoke jobs that completed as success or failure). 9 of those jobs failed in the WSL setup step:

Failure mode Jobs
wsl --import exit -1, The virtual machine or container ... is not running. 3 (108025747515, 108029388564, 108027000353)
wsl --import exit -1, 0x80041001 1 (108008742001)
step timed out after 15 min while importing 1 (107934540288)
Docker/apt crashed inside the distro (containerd panic, apt segfault) 2
curl: (18) partial download of the pinned server 2

This PR targets the first two rows: the import fails fast with -1, which accounts for about 1.8% of Windows smoke jobs. The same class of failure was earlier reported with The interface is unknown (#337242).

Fix

  • Retry wsl --import up to 3 times.
  • After each failed attempt, keep writing the full diagnostics. They now go to import-<distro>-attempt-<n>.log, so the logs artifact shows whether a retry on the same host helps.
  • Before retrying, reset the host: wsl --unregister any partial distro, run wsl --shutdown so the next attempt boots a fresh utility VM, recreate the empty install directory, and back off 10s then 20s.
  • If the third attempt fails, throw the same error as before.

wsl --shutdown stops every distro on the host. That is safe here because CI agents are dedicated to the job and the distro is created by this script. The script is shared by GitHub Actions and Azure Pipelines, so both get the retry. The step normally takes about 80s and has a 15-minute timeout, so there is room for the retries.

Not addressed here, since they are different failure modes:

  • Import hangs: the import can still hang until the step times out.
  • Crashes inside the distro: the containerd panic and apt segfault happen after import.
  • curl: (18) partial downloads: curl's --retry does not retry exit code 18 unless --retry-all-errors is passed.

Validation

  • The PowerShell parser reports no errors.
  • I extracted the import loop and the diagnostics functions and ran them against a fake wsl.cmd that fails the import N times. With 0 failures it imports on attempt 1. With 2 failures it retries twice (unregister, shutdown, 10s then 20s backoff) and succeeds on attempt 3. With 3 failures it throws after 3 attempts. Each failed attempt writes its own diagnostics log.
  • I did not run a real WSL import locally, because it would change the host's WSL state. This PR's Windows Electron-Smoke job covers the success path on a hosted agent.

On hosted Windows agents, `wsl --import --version 2` intermittently fails
with exit code -1 right after the WSL2 kernel is installed, e.g. "The
virtual machine or container with the specified identifier is not
running." or 0x80041001, while the Hyper-V worker log shows the utility
VM starting and being shut down by the guest seconds later.

Keep collecting the existing diagnostics for every failed attempt, then
unregister any partial distro, shut WSL down, and retry the import up to
three times before failing the job.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings September 25, 2026 20:37
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the engineering VS Code - Build / issue tracking / etc. label Sep 25, 2026

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

🟢 Approval recommended

The bounded retry safely preserves existing success and final-failure behavior while addressing the documented transient failures.

Review effort: Balanced
Findings: None

What changed in this PR

Adds bounded retries for transient WSL2 import failures during Windows smoke-test setup.

Changes:

  • Retries failed imports up to three times with backoff.
  • Preserves per-attempt diagnostics and resets WSL between attempts.
File Description
test/​smoke/​wslDevContainer.ps1 Adds WSL import retry, diagnostics, reset, and backoff logic.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as ready for review September 25, 2026 20:51
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit fb63c29 into main Sep 25, 2026
35 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the agents/fix-smoke-wsl-import-retry branch September 25, 2026 21:26
@vs-code-engineering vs-code-engineering Bot added this to the 1.140.0 milestone Sep 25, 2026
Alexandru Dima (alexdima) added a commit that referenced this pull request Oct 18, 2026
The Windows Server 2022 agents only have the inbox WSL (wsl.exe 10.0.20348). With the 2021 standalone WSL2 kernel (5.10.16), its utility VM intermittently hangs on import, shuts down right after boot, or crashes processes such as apt-get and containerd. Earlier fixes (#337229, #337644, #338047) worked around single symptoms.

- Install the WSL release pinned in build/checksums/wsl.txt (3.0.3) from build/azure-pipelines/common/wsl.psm1, verifying its SHA256 and Microsoft signature, and log the host CPU and WSL versions.
- Cache the installer by that pin: actions/cache, filled on main by pr-node-modules.yml, and Cache@2 in the product build. This replaces the daily kernel installer cache.
- Run every wsl.exe call with a timeout, so a hung import is retried on a fresh utility VM and diagnostics and cleanup can't hang.
- Retry downloads on all errors.

Co-authored-by: Copilot <[email protected]>
Alexandru Dima (alexdima) added a commit that referenced this pull request Oct 18, 2026
#342344)

* ci: tolerate WSL Dev Container provisioning failures in PR smoke tests

The Windows PR smoke step that provisions WSL flaked 16 times between Oct 10 and 17. Every flake happened inside the runner's WSL2 VM, never in a download: either wsl --import hung until the step timed out (9), or apt-get/containerd crashed right after the first boot (7). A re-run on a new VM passes.

Provisioning only sets up test infrastructure, so in PR CI a failure no longer fails the job. The WSL suite skips itself at runtime, so the shard split doesn't change. Lower the setup timeout from 15 to 10 minutes, since a healthy setup takes under 2. The Azure DevOps product build still requires the suite.

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

* ci: install current WSL on Windows smoke agents and bound wsl.exe calls

The Windows Server 2022 agents only have the inbox WSL (wsl.exe 10.0.20348). With the 2021 standalone WSL2 kernel (5.10.16), its utility VM intermittently hangs on import, shuts down right after boot, or crashes processes such as apt-get and containerd. Earlier fixes (#337229, #337644, #338047) worked around single symptoms.

- Install the WSL release pinned in build/checksums/wsl.txt (3.0.3) from build/azure-pipelines/common/wsl.psm1, verifying its SHA256 and Microsoft signature, and log the host CPU and WSL versions.
- Cache the installer by that pin: actions/cache, filled on main by pr-node-modules.yml, and Cache@2 in the product build. This replaces the daily kernel installer cache.
- Run every wsl.exe call with a timeout, so a hung import is retried on a fresh utility VM and diagnostics and cleanup can't hang.
- Retry downloads on all errors.

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

* TEMPORARY: probe WSL setup on 20 Windows agents (remove before merge)

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

* TEMPORARY: diagnose the wsl-desktop sanity launch failure (remove before merge)

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

* Remove the temporary WSL probe workflow

100 of 100 probe VMs provisioned WSL successfully in 92-124 seconds.

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

* build: update the WSL step expectations in the test checkpoint template test

The kernel cache day and kernel installer cache steps were replaced by a single version-keyed WSL installer cache.

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

* ci: fail the Windows smoke job again when WSL provisioning fails

Skipping the WSL Dev Container suite after a failed setup hid real regressions in the setup or the WSL path behind a green job. It was a stopgap while setup flaked on the inbox WSL; with current WSL installed, a failed setup should fail the PR. Restore the 15-minute step timeout so the bounded import retries have room.

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

---------

Co-authored-by: Copilot <[email protected]>
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Nov 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

engineering VS Code - Build / issue tracking / etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants