Skip to content

Generate custom container name on empty input#40432

Open
yao-msft wants to merge 11 commits intomasterfrom
user/yaosun/autocontainername
Open

Generate custom container name on empty input#40432
yao-msft wants to merge 11 commits intomasterfrom
user/yaosun/autocontainername

Conversation

@yao-msft
Copy link
Copy Markdown
Contributor

@yao-msft yao-msft commented May 6, 2026

Summary of the Pull Request

When containerOptions.Name is empty, generate our own container name.

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.

Copilot AI review requested due to automatic review settings May 6, 2026 00:56
@yao-msft yao-msft requested a review from a team as a code owner May 6, 2026 00:56
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 changes WSLC container creation so that when a caller does not provide a container name, the service generates a human-readable name (using a descriptor + mountain word list), and adds tests that validate the generated name format and uniqueness.

Changes:

  • Add descriptor/mountain word lists for generated container names.
  • Generate a unique container name during WSLCSession::CreateContainer() when no name is provided.
  • Expand WSLC tests to validate the generated name format and uniqueness; update test include paths accordingly.

Reviewed changes

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

File Description
src/windows/wslcsession/WSLCSession.cpp Adds container name generation helpers and injects generated names into container creation when name is absent.
src/windows/wslcsession/ContainerNameGenerator.h Introduces the descriptor/mountain constants used for name generation and test validation.
test/windows/WSLCTests.cpp Adds coverage for generated-name format and uniqueness when creating unnamed containers.
test/windows/CMakeLists.txt Adds include path so tests can include the new name constants header.

Comment thread src/windows/wslcsession/WSLCSession.cpp Outdated
Comment thread src/windows/wslcsession/WSLCSession.cpp
Comment thread src/windows/wslcsession/WSLCSession.cpp Outdated
Comment thread src/windows/wslcsession/WSLCSession.cpp Outdated
Comment thread src/windows/wslcsession/ContainerNameGenerator.h
Comment thread test/windows/WSLCTests.cpp
// When retry > 0, appends a random digit (0-9) to reduce collisions.
std::string GenerateContainerName(int retry)
{
static std::mt19937 s_gen(std::random_device{}());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I can't find a definite mention that this class is safe to use from multiple threads without synchronization.

Given that, I would recommend not marking it static unless we find a guarantee that it's thread safe

std::uniform_int_distribution<size_t> leftDist(0, c_descriptors.size() - 1);
std::uniform_int_distribution<size_t> rightDist(0, c_mountains.size() - 1);

auto name = std::string(c_descriptors[leftDist(s_gen)]) + "_" + c_mountains[rightDist(s_gen)];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: This could be simplified to:

auto name = std::format("{}_{}", c_descriptors[leftDist(s_gen)], c_mountains[rightDist(s_gen)]);

std::unordered_set<std::string> existingNames;
for (const auto& c : m_containers)
{
existingNames.insert(c->Name());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looping through all the containers will make us create a copy of each container name. Instead of doing this, I think just iterating through m_containers after generating the name would be OK, since we expect conflicts to be very uniquely

// Fallback to a GUID name
if (generatedName.empty())
{
GUID guid{};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probably a good idea to log an event if we ever hit this


// Generate a unique container name if the user didn't provide one.
std::string generatedName;
auto options = *containerOptions;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copying the entire structure feels a bit rough here. Going through it, I think that the default copy behavior for this struct will do the right thing, but I would have a preference for adding an additional name argument to Create() so we don't have to do this

add_library(wsltests SHARED ${SOURCES} ${HEADERS})

target_include_directories(wsltests PRIVATE ${CMAKE_SOURCE_DIR}/src/windows/WslcSDK)
target_include_directories(wsltests PRIVATE ${CMAKE_SOURCE_DIR}/src/windows/WslcSDK ${CMAKE_SOURCE_DIR}/src/windows/wslcsession)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Instead of adding an include path, I would recommend moving that header to src/windows/common so we don't need to do a special case for it

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