Skip to content

Comments

Add WSLAContainer flag to auto delete container after exit#14196

Merged
kvega005 merged 19 commits intomicrosoft:feature/wsl-for-appsfrom
kvega005:user/kevinve/auto-delete-containers
Feb 23, 2026
Merged

Add WSLAContainer flag to auto delete container after exit#14196
kvega005 merged 19 commits intomicrosoft:feature/wsl-for-appsfrom
kvega005:user/kevinve/auto-delete-containers

Conversation

@kvega005
Copy link

Summary of the Pull Request

Add support for Docker-style auto-remove (Rm) flag for containers

  • Persist and restore the WSLAContainerFlagsRm flag in container metadata.
  • Automatically delete containers with the Rm flag after they stop, using a detached thread.
  • Add tests to verify auto-remove behavior and flag persistence across sessions.

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

@kvega005 kvega005 marked this pull request as ready for review February 11, 2026 19:00
@kvega005 kvega005 requested a review from a team as a code owner February 11, 2026 19:00
Copilot AI review requested due to automatic review settings February 11, 2026 19:00
Copy link
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

Adds Docker-style auto-remove behavior for WSLA containers by persisting an Rm-style flag in container metadata and triggering container deletion automatically after the container stops.

Changes:

  • Persist/restore WSLAContainerFlags in WSLAContainerMetadataV1 so flags survive service/session restarts.
  • Implement auto-delete on container stop events when WSLAContainerFlagsRm is set.
  • Add a new Windows test covering auto-remove behavior and flag persistence across sessions.

Reviewed changes

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

File Description
test/windows/WSLATests.cpp Adds ContainerAutoRemove test validating async deletion and persistence across sessions.
src/windows/wslaservice/exe/WSLAContainerMetadata.h Extends persisted container metadata to include Flags.
src/windows/wslaservice/exe/WSLAContainer.cpp Persists flags into metadata on create/open and triggers auto-delete on stop events.

Copy link
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.

LGTM, minor comments in the tests.

This turned out to be more complex problem than we thought. Thank you for doing this !

launcher.SetContainerFlags(WSLAContainerFlagsRm);

auto container = launcher.Launch(*m_defaultSession);
auto process = container.GetInitProcess();
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: process is unused in this scope

VERIFY_ARE_EQUAL(container.State(), WslaContainerStateRunning);
VERIFY_SUCCEEDED(container.Get().Stop(WSLASignalSIGKILL, 0));

// verifyContainerDeleted("test-auto-remove");
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: We should remove that comment since it refers to a previous version of the tests

wil::com_ptr<IWSLAContainer> notFound;
VERIFY_ARE_EQUAL(m_defaultSession->OpenContainer("test-auto-remove", &notFound), HRESULT_FROM_WIN32(ERROR_NOT_FOUND));
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think it would also be a good idea to add test coverage for the "stop detection" code path.

To do that we could create a container with the AutoRm flag that just does "echo foo", and validate that after the init process has exited, the container gets deleted (we'll probably have to check with a timeout since that won't be synchronous though, but we can use wsl::shared::retry::RetryWithTimeout for that)

@kvega005 kvega005 requested a review from OneBlue February 20, 2026 18:33
@kvega005 kvega005 merged commit 30bf97d into microsoft:feature/wsl-for-apps Feb 23, 2026
6 checks passed
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.

2 participants