-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Persist port mapping and volume information for containers across WSLA sessions #14118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/wsl-for-apps
Are you sure you want to change the base?
Persist port mapping and volume information for containers across WSLA sessions #14118
Conversation
There was a problem hiding this 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 support for persisting WSLA container metadata (volumes, port mappings, and TTY settings) in Docker container labels, enabling containers to be recovered with full configuration across WSLA session restarts.
Changes:
- Introduced a JSON-based metadata schema stored in Docker labels to persist container configuration (volumes, ports, TTY)
- Changed WSLA_VOLUME.HostPath API from LPCWSTR to LPCSTR for consistency with other string fields
- Refactored port mapping logic to support both creation-time and recovery-time scenarios
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/windows/wslaservice/exe/WSLAContainerMetadata.h | New metadata schema with JSON serialization for volumes, ports, and TTY settings |
| src/windows/wslaservice/exe/WSLAContainer.h | Updated type signatures to use WSLAVolumeMount and WSLAPortMapping from metadata schema |
| src/windows/wslaservice/exe/WSLAContainer.cpp | Implemented metadata serialization on Create(), deserialization on Open(), and refactored port/volume handling |
| src/windows/inc/docker_schema.h | Added Labels field to CreateContainer request for metadata storage |
| src/windows/wslaservice/inc/wslaservice.idl | Breaking API change: WSLA_VOLUME.HostPath changed from LPCWSTR to LPCSTR |
| src/windows/common/WSLAContainerLauncher.h | Updated AddVolume and Create method signatures to use std::string instead of std::wstring |
| src/windows/common/WSLAContainerLauncher.cpp | Updated implementation to handle string-based paths and added Create method |
| test/windows/WSLATests.cpp | Added comprehensive recovery test and updated existing tests for string-based path API |
OneBlue
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks good, added a couple minor comments
There was a problem hiding this 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 4 comments.
There was a problem hiding this 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 3 comments.
| // Delete the host folder to simulate volume folder being missing on recovery | ||
| cleanup.reset(); | ||
|
|
||
| // Create a new session - this should succeed even though the volume folder is gone |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is slightly misleading. The session creation succeeds not because "the volume folder is gone" but because the container was already deleted in the previous session (line 2544). When OpenContainer is called, it returns ERROR_NOT_FOUND because the Docker container no longer exists, not because of the missing volume folder. Consider updating the comment to clarify that the container was deleted before the session was created.
| // Delete the host folder to simulate volume folder being missing on recovery | |
| cleanup.reset(); | |
| // Create a new session - this should succeed even though the volume folder is gone | |
| // Delete the host folder to simulate the volume folder being missing before recovery. | |
| cleanup.reset(); | |
| // Create a new session. This succeeds because the container was deleted in the previous | |
| // session; OpenContainer below is expected to return ERROR_NOT_FOUND for the missing | |
| // container, regardless of the missing volume folder. |
| // Try to open the container - this should fail due to missing metadata. | ||
| wil::com_ptr<IWSLAContainer> container; | ||
| auto hr = session->OpenContainer("test-invalid-metadata", &container); | ||
| VERIFY_ARE_EQUAL(hr, E_UNEXPECTED); |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test expects E_UNEXPECTED, but the implementation throws E_INVALIDARG when the metadata label is missing. In WSLAContainer.cpp line 794-798, THROW_HR_IF_MSG throws E_INVALIDARG when dockerContainer.Labels.find(WSLAContainerMetadataLabel) returns end(). Change the expected error code to E_INVALIDARG to match the actual implementation.
| VERIFY_ARE_EQUAL(hr, E_UNEXPECTED); | |
| VERIFY_ARE_EQUAL(hr, E_INVALIDARG); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this 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 6 comments.
benhillis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some of these copilot comments are legit.
…kvega005/WSL into user/kevinve/container-metadata
| GUID volumeId; | ||
| THROW_IF_FAILED(CoCreateGuid(&volumeId)); | ||
|
|
||
| auto parentVMPath = std::format("/mnt/{}", wsl::shared::string::GuidToString<char>(volumeId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I liked having the container name as prefix, but now that it might be empty, we could use the container id (since it's always guaranteed to be set)
Summary of the Pull Request
Added support to persist WSLA container metadata (port mappings, volume mounts, TTY setting) in a Docker label. This enables running containers with their full configuration when opening them from previous sessions.
Changes
New Container Metadata Schema (
docker_schema.h)Added
WSLAContainerMetadataLabelconstant for the label keyAdded
ContainerMetadatastruct with JSON schema for storing:Container Creation (
WSLAContainer.cpp)Create(), serialize metadata to JSON and store in Docker labelContainer Recovery (
WSLAContainer.cpp)Open(), read metadata from Docker labelTests (
WSLATests.cpp)Added
ContainerVolumeAndPortRecoveryFromStoragetest that:PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed