Skip to content

Initial prune image support in wslc service#40132

Open
yao-msft wants to merge 13 commits intofeature/wsl-for-appsfrom
user/yaosun/pruneimage
Open

Initial prune image support in wslc service#40132
yao-msft wants to merge 13 commits intofeature/wsl-for-appsfrom
user/yaosun/pruneimage

Conversation

@yao-msft
Copy link
Copy Markdown

@yao-msft yao-msft commented Apr 8, 2026

Summary of the Pull Request

Initial prune image support in wslc service

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Added tests.

@yao-msft yao-msft requested a review from a team as a code owner April 8, 2026 00:13
Copilot AI review requested due to automatic review settings April 8, 2026 00:13
Copy link
Copy Markdown
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

This PR adds initial “image prune” support to the WSLC session API by plumbing a new COM method through WSLCSession into the Docker Engine /images/prune endpoint, and validating the behavior with new Windows tests.

Changes:

  • Adds IWSLCSession::PruneImages along with new IDL types/options/results for image pruning.
  • Implements image prune in WSLCSession and DockerHTTPClient, including Docker schema support for prune responses.
  • Adds a new ImagePrune test and a small RAII helper for freeing prune results.

Reviewed changes

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

Show a summary per file
File Description
test/windows/WSLCTests.cpp Adds ImagePrune test coverage for prune behavior and error paths.
src/windows/wslcsession/WSLCSession.h Declares the new PruneImages COM method on WSLCSession.
src/windows/wslcsession/WSLCSession.cpp Implements WSLCSession::PruneImages, including filter translation and result marshaling.
src/windows/wslcsession/DockerHTTPClient.h Adds prune filter struct and PruneImages method declaration.
src/windows/wslcsession/DockerHTTPClient.cpp Implements POST /images/prune request with Docker filters query param.
src/windows/service/inc/wslc.idl Introduces prune-related structs/enums and adds PruneImages to IWSLCSession.
src/windows/inc/docker_schema.h Adds PruneImageResult schema used to parse Docker prune responses.
src/windows/common/wslutil.h Adds ImagePruneResult RAII wrapper for WSLCPruneImagesResults.
Comments suppressed due to low confidence (1)

src/windows/service/inc/wslc.idl:660

  • Adding a new method to the existing COM interface IWSLCSession changes the vtable layout for all subsequent methods (e.g., CreateContainer and later), which is a binary-breaking change for any existing clients built against the previous IDL. To preserve COM ABI compatibility, add a new interface (e.g., IWSLCSession2 with a new IID) that extends IWSLCSession, and implement/query that from the session object instead of inserting methods into IWSLCSession.
    // Image management.
    HRESULT PullImage([in] LPCSTR Image, [in, unique] LPCSTR RegistryAuthenticationInformation, [in, unique] IProgressCallback* ProgressCallback);
    HRESULT BuildImage([in] const WSLCBuildImageOptions* Options, [in, unique] IProgressCallback* ProgressCallback, [in, unique, system_handle(sh_event)] HANDLE CancelEvent);
    HRESULT LoadImage([in] WSLCHandle ImageHandle, [in, unique] IProgressCallback* ProgressCallback, [in] ULONGLONG ContentLength);
    HRESULT ImportImage([in] WSLCHandle ImageHandle, [in] LPCSTR ImageName, [in, unique] IProgressCallback* ProgressCallback, [in] ULONGLONG ContentLength);
    HRESULT SaveImage([in] WSLCHandle OutputHandle, [in] LPCSTR ImageNameOrID, [in, unique] IProgressCallback * ProgressCallback, [in, unique, system_handle(sh_event)] HANDLE CancelEvent);
    HRESULT ListImages([in, unique] const WSLCListImageOptions* Options, [out, size_is(, *Count)] WSLCImageInformation** Images, [out] ULONG* Count);
    HRESULT DeleteImage([in] const WSLCDeleteImageOptions* Options, [out, size_is(, *Count)] WSLCDeletedImageInformation** DeletedImages, [out] ULONG* Count);
    HRESULT TagImage([in] const WSLCTagImageOptions* Options);
    HRESULT InspectImage([in] LPCSTR ImageNameOrId, [out] LPSTR* Output);
    HRESULT PruneImages([in, unique] const WSLCPruneImagesOptions* Options, [out] WSLCPruneImagesResults* Result);

    // Container management.
    HRESULT CreateContainer([in] const WSLCContainerOptions* Options, [out] IWSLCContainer** Container);
    HRESULT OpenContainer([in, ref] LPCSTR Id, [out] IWSLCContainer** Container);
    HRESULT ListContainers([out, size_is(, *Count)] WSLCContainerEntry** Containers,
                                            [out] ULONG* Count,
                                            [out, size_is(, *PortsCount)] WSLCContainerPortMapping** Ports,
                                            [out] ULONG* PortsCount);
    HRESULT PruneContainers([in, unique, size_is(FiltersCount)] WSLCContainerPruneFilter* Filters, [in] DWORD FiltersCount, [in] ULONGLONG Until, [out] WSLCPruneContainersResults* Result);

Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue left a comment

Choose a reason for hiding this comment

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

Change looks good, minor comments

Copilot AI review requested due to automatic review settings April 10, 2026 02:11
Copy link
Copy Markdown
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

if (Options != nullptr)
{
RETURN_HR_IF(E_INVALIDARG, WI_IsFlagSet(Options->Flags, WSLCPruneImagesFlagsDanglingTrue) && WI_IsFlagSet(Options->Flags, WSLCPruneImagesFlagsDanglingFalse));
RETURN_HR_IF(E_INVALIDARG, WI_IsAnyFlagSet(static_cast<WSLCPruneImagesFlags>(Options->Flags), ~WSLCPruneImagesFlagsValid));
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

PruneImages validates dangling flags and unknown bits, but it doesn't validate the Labels pointer/count relationship. If Options->LabelsCount > 0 while Options->Labels is nullptr, the call currently succeeds and silently ignores the requested filters. Please add an argument check (similar to ListImages) to reject this case (e.g., return E_INVALIDARG when LabelsCount > 0 && Labels == nullptr).

Suggested change
RETURN_HR_IF(E_INVALIDARG, WI_IsAnyFlagSet(static_cast<WSLCPruneImagesFlags>(Options->Flags), ~WSLCPruneImagesFlagsValid));
RETURN_HR_IF(E_INVALIDARG, WI_IsAnyFlagSet(static_cast<WSLCPruneImagesFlags>(Options->Flags), ~WSLCPruneImagesFlagsValid));
RETURN_HR_IF(E_INVALIDARG, Options->LabelsCount > 0 && Options->Labels == nullptr);

Copilot uses AI. Check for mistakes.
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