Skip to content

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

Description

Windows Version

Microsoft Windows [Version 10.0.26200.8893]

WSL Version

2.9.4.0

Are you using WSL 1 or WSL 2?

  • 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:

    $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:

    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:

    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:

    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:

    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:

    $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:

    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:

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions