Skip to content

Conversation

@kvega005
Copy link

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 WSLAContainerMetadataLabel constant for the label key

  • Added ContainerMetadata struct with JSON schema for storing:

    • Volume mounts (host path, VM path, container path, read-only flag)
    • Port mappings (host port, VM port, container port, family, mapped-to-host flag)
    • TTY setting

Container Creation (WSLAContainer.cpp)

  • On Create(), serialize metadata to JSON and store in Docker label

Container Recovery (WSLAContainer.cpp)

  • On Open(), read metadata from Docker label
  • Re-mount volumes and re-map ports using stored configuration

Tests (WSLATests.cpp)

  • Added ContainerVolumeAndPortRecoveryFromStorage test that:

    • Creates a container with volumes and ports
    • Recovers it in a new session and verifies port/volume work
    • Verifies session creation succeeds when host folder for volume is missing

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 requested a review from a team as a code owner January 28, 2026 00:44
Copilot AI review requested due to automatic review settings January 28, 2026 00:44
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

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

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.

Change looks good, added a couple minor comments

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

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

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

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

Comment on lines +2547 to +2550
// 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
Copy link

Copilot AI Jan 30, 2026

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.

Suggested change
// 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.

Copilot uses AI. Check for mistakes.
// 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);
Copy link

Copilot AI Jan 30, 2026

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.

Suggested change
VERIFY_ARE_EQUAL(hr, E_UNEXPECTED);
VERIFY_ARE_EQUAL(hr, E_INVALIDARG);

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Copy link
Member

@benhillis benhillis left a 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 kvega005 requested a review from benhillis January 30, 2026 18:46
GUID volumeId;
THROW_IF_FAILED(CoCreateGuid(&volumeId));

auto parentVMPath = std::format("/mnt/{}", wsl::shared::string::GuidToString<char>(volumeId));
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 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)

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