Skip to content

[WSLC] (1/2) Forward host stdin to state-aware exec - #1562

Merged
Soham Das (SohamDas2021) merged 5 commits into
mainfrom
sohamdas2021-wslc-stdin-forwarding
Oct 27, 2026
Merged

Soham Das (SohamDas2021) merged 5 commits into
mainfrom
sohamdas2021-wslc-stdin-forwarding

Conversation

@SohamDas2021

@SohamDas2021 Soham Das (SohamDas2021) commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

📖 Description

The WSLc state-aware exec path now forwards stdin to the process. Before, the process always read end-of-file at once.

This is part 1 of 2: it covers the state-aware (container lifecycle) path. Part 2 will add stdin to the create-and-run (one-shot) path.

  • wxc-exec: a piped or redirected stdin is streamed to the command, and closing it sends end-of-file. A terminal stdin isn't forwarded; the executor warns and the command reads end-of-file.
  • SDKs: stdin is opt-in, so existing callers see no change. spawn_in_container / SpawnInContainer / spawnInContainer still give a WSLc command immediate end-of-file. The new spawn_in_container_with_stdin / SpawnInContainerWithStdin(Async) / spawnInContainerWithStdin return a process with a writable stdin; closing it sends end-of-file. A new FFI export, mxc_exec_state_aware_with_stdin_json, backs them; the existing export is unchanged.
  • Input is streamed, so a stdin that never closes doesn't block the exec, and a slow reader doesn't hold up other execs or lifecycle commands. If input can't be fully delivered, the exec fails or is cancelled rather than finishing on truncated input. A process that closes its stdin early keeps running, and its unread input is discarded.
  • Timeout and cancellation: the WSLc SDK closes a process's stdin whenever it is signalled, and SDK 3.0.3 can't kill a single process anyway. So a process reading forwarded stdin isn't signalled on timeout or cancellation. Its stdin stays open, and its container is quarantined and deleted about a minute later. The command never mistakes cut-short input for complete input.
  • The daemon accepts more connections, so stdin connections don't use up the room kept for lifecycle commands. The daemon protocol goes from version 8 to 9.
  • CI: a new WSLc test bundle runs the .NET and Node stdin tests in scheduled validation on the WSLc hosts. The isolation-session bundle workflow now serves both backends, as Package.Backend.TestBundle.Job.yml.

🔗 References

Part of #1258. AB#63911794.

🔍 Validation

  • cargo fmt --all -- --check, cargo clippy (workspace and --features wslc), cargo test --workspace (2,884 passed) and cargo test -p mxc-sdk -p mxc_ffi --features mxc-sdk/wslc (3,249 passed): all passed. New regression tests fail without their fixes.
  • WSLc E2E (run_wslc_all_tests.ps1, release x64): state-aware 138/138, including the new stdin cases; full WSLc suite 40/40.
  • .NET with MxcWithWslc and the live WSLc tests (MXC_ENABLE_WSLC_TESTS=1): 358 total, 0 failed, no WSLc test skipped.
  • Node npm test: 446 passed, 0 failed. Node WSLc state-aware integration test: passed. Other Node integration tests fail locally without a packaged SDK, and the one-shot UDP rejection test expects the async spawn to throw synchronously, so it fails regardless; this PR touches neither.
  • The new scheduled CI workflow hasn't run yet; it runs after merge.

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c4bfcc08-7702-4e6c-9d89-67a533cced13
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c4bfcc08-7702-4e6c-9d89-67a533cced13
Copilot AI balanced review requested due to automatic review settings October 22, 2026 17:04
@SohamDas2021
Soham Das (SohamDas2021) requested a review from a team as a code owner October 22, 2026 17:04
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

V1 compatibility changes and failure paths that can expose incomplete input as normal EOF remain unresolved.

5 open issues
What changed in this PR

This PR adds stdin forwarding to WSLc container lifecycle execution in MXC, covering CLI input and SDK process streams. Create-and-run execution and interactive terminal input remain unsupported.

Changes:

  • Adds a separate stdin connection, bounded buffering, and per-exec writer threads; advances the daemon protocol to version 9.
  • Exposes SDK stdin and changes .NET waits to close untaken input.
  • Adds stdin regression scenarios and updates backend documentation and SDK changelogs.
File Description
tests/​scripts/​run_wslc_state_aware_tests.ps1 Adds CLI stdin and backpressure scenarios.
src/​mxc-sdk/​tests/​wslc_daemon_ipc.rs Sets stdin explicitly in existing IPC tests.
src/​mxc-sdk/​src/​lib.rs Documents lifecycle stdin availability.
src/​mxc-sdk/​src/​core/​mxc_common/​state_aware_backend.rs Updates WSLc stdio contract documentation.
src/​mxc-sdk/​src/​core/​mxc_common/​exec_stream.rs Updates pipe ownership documentation.
src/​mxc-sdk/​src/​bin/​wslc_daemon/​stdin_writer.rs Adds dedicated, cancellable stdin writers.
src/​mxc-sdk/​src/​bin/​wslc_daemon/​session_manager.rs Tracks stdin channels and attachment ownership.
src/​mxc-sdk/​src/​bin/​wslc_daemon/​main.rs Registers the Windows stdin writer module.
src/​mxc-sdk/​src/​bin/​wslc_daemon/​control_server.rs Handles stdin connections, framing, and relay failures.
src/​mxc-sdk/​src/​backends/​wslc/​common/​state_aware.rs Bridges CLI and SDK input to the daemon.
src/​mxc-sdk/​src/​backends/​wslc/​common/​sandbox.rs Clarifies create-and-run stdin limitations.
src/​mxc-sdk/​src/​backends/​wslc/​common/​daemon_protocol.rs Adds stdin requests and protocol version 9.
src/​mxc-sdk/​src/​backends/​wslc/​common/​daemon_client.rs Streams input over a separate daemon connection.
src/​mxc-sdk/​src/​backends/​wslc/​common/​container_steps.rs Acquires and manages native process stdin.
sdk/​node/​tests/​integration/​wslc-state-aware.test.ts Adds binary round-trip and EOF scenarios.
sdk/​node/​src/​v1/​container-process.ts Documents WSLc stdin availability.
sdk/​node/​CHANGELOG.md Records lifecycle stdin support.
sdk/​dotnet/​Microsoft.Mxc.Sdk/​V1/​MxcProcess.cs Closes untaken stdin when waiting.
sdk/​dotnet/​Microsoft.Mxc.Sdk/​V1/​MxcLifecycle.cs Closes input for captured lifecycle execution.
sdk/​dotnet/​Microsoft.Mxc.Sdk.Tests/​V1/​MxcLifecycleWslcE2ETests.cs Adds live SDK stdin and ownership scenarios.
sdk/​dotnet/​Microsoft.Mxc.Sdk.Tests/​MxcProcessTests.cs Tests untaken stdin closure during wait.
sdk/​dotnet/​CHANGELOG.md Records stdin support and changed wait behavior.
docs/​development/​architecture/​container-lifecycle.md Updates lifecycle stream availability.
docs/​backends/​wslc/​wslc-state-aware.md Documents stdin transport, limits, and failures.
docs/​backends/​wslc/​wsl-container-getting-started.md Explains supported stdin flows.

Review effort: Balanced

@SohamDas2021 Soham Das (SohamDas2021) changed the title [WSLC] Forward host stdin to state-aware exec [WSLC] Forward host stdin to state-aware exec (1/2) Oct 22, 2026
@SohamDas2021 Soham Das (SohamDas2021) changed the title [WSLC] Forward host stdin to state-aware exec (1/2) [WSLC] (1/2) Forward host stdin to state-aware exec Oct 22, 2026

@MGudgin Gudge (MGudgin) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Summary

Requesting changes on the V1 SDK compatibility changes and the stdin error/completion paths. This review contains nine inline findings: two P0 / critical SDK compatibility alerts, four additional High findings (including the new SDK path's functional-validation gap), and three Medium findings. The P0 labels are MXC's SDK compatibility category, not security-vulnerability ratings. The Medium documentation claim is non-blocking by itself.

I rechecked every finding against base e2e02d9b5d583aeba3c6433a2d6791919d86c43a and head 019591ce27910c4cdf1e331faff855669bc38ec9. The base is the merge base. GitHub and local diffs have identical source changes and hunk ranges; only C# function-name labels in hunk headers differ. Every inline anchor is an added line at this head.

Checked and retained protections

  • Stdin attachment still verifies the run token and permits a single claim in src/mxc-sdk/src/bin/wslc_daemon/session_manager.rs:801-829. Matching wrong-token and second-attachment tests are present in control_server.rs:1792 and :1839; this is source/test inspection, not a claim that I ran those tests.
  • The stdin relay enforces frame/chunk caps before accepting data in control_server.rs:688-701; the protocol's chunk bound is 64 KiB. No weakening of those guards is alleged by this review.

Findings outside the diff

None require an out-of-diff primary anchor. Finding 6 references the unchanged CI dispatcher as supporting evidence, but is anchored to the new SDK stdin bridge it does not cover. Finding 9 is a claim mismatch anchored to the added claim itself.

Verified pre-existing - not charged as existing defects

scripts/ci/run_backend_validation_tests.ps1 is byte-identical at base and head. Its existing WSLc case invokes the CLI suite. I am not charging the author for an old dispatcher bug: finding 6 is newly_exposed_by_change, specifically the missing scheduled functional coverage for the newly added SDK exec_piped path. No unrelated pre-existing defects are included.

Verification limits

This filing rechecked source, attribution, anchors, existing tests, and CI wiring. I did not rerun live WSLc or cross-platform .NET execution. Runtime race/error findings state the triggering code path; the coverage finding is missing validation evidence, not a claim that a live suite failed.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. label Oct 23, 2026
…ty, CI bundle

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c4bfcc08-7702-4e6c-9d89-67a533cced13
Copilot AI balanced review requested due to automatic review settings October 23, 2026 22:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment on lines +1387 to +1391
Err(error) => {
// A process holding a stdin nobody writes or closes would never
// see end-of-file, so it is killed rather than left to run.
let _ =
sdk.WslcSignalProcess(process_guard.as_raw(), WslcSignal::WSLC_SIGNAL_SIGKILL);
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c4bfcc08-7702-4e6c-9d89-67a533cced13
Copilot AI balanced review requested due to automatic review settings October 23, 2026 23:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Silent client disconnection can strand execs indefinitely, and interruption tests can pass after container deletion erases their evidence.

6 open issues

Review effort: Balanced

Comment on lines +389 to +392
Assert-True ($r.Stdout -notmatch 'MARKER-FOUND') `
"the command never acted on its cut-short input (stdout: $($r.Stdout.Trim()))"
Assert-True (($r.Stdout -match 'NO-MARKER') -or ($r.ExitCode -ne 0)) `
"the probe ran or the sandbox was quarantined (stderr: $($r.Stderr.Trim()))"
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c4bfcc08-7702-4e6c-9d89-67a533cced13
Copilot AI balanced review requested due to automatic review settings October 26, 2026 17:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment on lines +202 to +206
catch (MxcException)
{
// Its container was deleted before anything could publish.
var gone = Assert.Throws<MxcException>(() => MxcLifecycle.StopContainer(container.Id));
Assert.Equal(ErrorCode.NotProvisioned, gone.Code);

@MGudgin Gudge (MGudgin) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved following the October 26 re-verification. All nine original findings are addressed in the current code or CI wiring. The head and base are unchanged since that verification, so its evidence is reused.

Verification: 21 daemon stdin tests and the specific early-reader-close regression passed. The broader WSLc library run had 367 passes, five sandbox-denied registry failures and three ignored tests. Live WSLc execution was sandbox-blocked; scheduled SDK-suite wiring was inspected, not independently run on a live host.

@SohamDas2021
Soham Das (SohamDas2021) merged commit 79f016b into main Oct 27, 2026
31 checks passed
@SohamDas2021
Soham Das (SohamDas2021) deleted the sohamdas2021-wslc-stdin-forwarding branch October 27, 2026 15:52
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. label Oct 27, 2026
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.

4 participants