microsoft / microsoft/WSL

wslc build uses a stale build context after a Windows directory is deleted and recreated at the same path

Open
#41,287 3 comments 0 reactions 1 assignee View on GitHub

@OneBlue is already working on this.

Since Aug 10, 2026.

wslc
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

### Windows Version

Microsoft Windows [Version 10.0.26200.8893]

### WSL Version

2.9.4.0

### Are you using WSL 1 or WSL 2?

- [x] WSL 2
- [ ] WSL 1

### Kernel Version

6.18.35.2-1

### Distro Version

_No response_

### Other Software

- WSLC 2.9.4.0
- Docker Desktop, used only as a control to build the same recreated context successfully
- PowerShell on Windows

### Repro Steps

1. In PowerShell, create a minimal build context:

```powershell
$context = Join-Path $env:TEMP "wslc-stale-context-repro"
Remove-Item $context -Recurse -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path $context | Out-Null

@'
FROM busybox:latest
COPY marker.txt /marker.txt
RUN test -f /marker.txt
'@ | Set-Content (Join-Path $context "Dockerfile") -Encoding ascii

"first directory" | Set-Content (Join-Path $context "marker.txt") -Encoding ascii
```

2. Build the context:

```powershell
wslc build --no-cache --tag wslc-stale-context-repro $context
```

The first build succeeds.

3. Delete the complete context directory and recreate it at the identical
Windows path:

```powershell
Remove-Item $context -Recurse -Force
New-Item -ItemType Directory -Path $context | Out-Null

@'
FROM busybox:latest
COPY marker.txt /marker.txt
RUN test -f /marker.txt
'@ | Set-Content (Join-Path $context "Dockerfile") -Encoding ascii

"recreated directory" | Set-Content (Join-Path $context "marker.txt") -Encoding ascii
Get-ChildItem $context
```

`Get-ChildItem` shows that `Dockerfile` and `marker.txt` exist.

4. Run the same WSLC build again:

```powershell
wslc build --no-cache --tag wslc-stale-context-repro $context
```

WSLC reports that `/marker.txt` is not found.

5. Build the same recreated context with Docker Desktop:

```powershell
docker build --no-cache --tag docker-context-control $context
```

Docker builds it successfully.

6. Copy the context to a new path and build it with WSLC:

```powershell
$newContext = "$context-new"
Copy-Item $context $newContext -Recurse
wslc build --no-cache --tag wslc-new-context-control $newContext
```

WSLC builds successfully from the new path.

7. Terminate the WSLC session and retry the original path:

```powershell
wslc system session terminate
wslc build --no-cache --tag wslc-stale-context-repro $context
```

The original path works again.

### Expected Behavior

Every `wslc build` invocation should read the current files from the build
context path supplied to that invocation.

After a Windows directory is deleted and recreated at the same path, WSLC
should detect that the underlying directory has changed and refresh or recreate
the context mount. `COPY marker.txt /marker.txt` should succeed because
`marker.txt` exists in the current context and is not excluded by
`.dockerignore`.

The result should not depend on whether the same path was used by an earlier
build in the current WSLC session. No session restart should be necessary.

### Actual Behavior

The first WSLC build succeeds. After deleting the complete Windows context
directory and recreating it at the identical path, subsequent WSLC builds act as
if the recreated context does not contain `marker.txt`.

The failure includes:

```text
failed to calculate checksum ... "/marker.txt": not found
```

Using `--no-cache` does not change the result.

The same recreated directory builds successfully with Docker Desktop. WSLC also
builds successfully when the files are copied to a different path. Running
`wslc system session terminate` makes the original path work again.

This suggests that WSLC retains a build-context mount associated with the
deleted directory object and reuses that stale mount when the same Windows path
is supplied again.

### Diagnostic Logs
```
ERROR: failed to solve: failed to compute cache key: failed to calculate
checksum of ref a62b46cc-b843-4094-b82f-a20b93d48306:
"/marker.txt": not found

Error code: E_FAIL
Exit code: 1
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.