Repository navigation
[WSLC] (1/2) Forward host stdin to state-aware exec - #1562
Conversation
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
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
V1 compatibility changes and failure paths that can expose incomplete input as normal EOF remain unresolved.
5 open issues
V1 wait APIs now close untaken stdin and break ownership behavior · New V1 stdin forwarding changes EOF behavior and can block streaming calls · New Propagate native stdin write failures instead of treating them as success · New Close stdin after confirmed process termination on timeout or cancellation · New Cancel exec when stdin admission reply fails after relay claim · New
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
Gudge (MGudgin)
left a comment
There was a problem hiding this comment.
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 incontrol_server.rs:1792and: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.
…ty, CI bundle Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c4bfcc08-7702-4e6c-9d89-67a533cced13
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved stdin ownership and interruption gaps can deadlock waits, strand abandoned executions, or allow incomplete input to be processed.
4 open issues
5 resolved since last review
Propagate native stdin write failures instead of treating them as success V1 stdin forwarding changes EOF behavior and can block streaming calls V1 wait APIs now close untaken stdin and break ownership behavior Cancel exec when stdin admission reply fails after relay claim Close stdin after confirmed process termination on timeout or cancellation
Review effort: Balanced
| 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
There was a problem hiding this comment.
🟡 Changes recommended
Silent client disconnection can strand execs indefinitely, and interruption tests can pass after container deletion erases their evidence.
6 open issues
Detect executor loss before stdin or output activity · New Blocked stdin prevents disconnect detection and cleanup Interrupted stdin relay can publish incomplete input Stdin setup failure signals process before safe cleanup Wait hangs when untaken stdin is not closed Verify markers persist independently of container cleanup · New
Review effort: Balanced
| 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
| 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); |
Gudge (MGudgin)
left a comment
There was a problem hiding this comment.
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.


📖 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.spawn_in_container/SpawnInContainer/spawnInContainerstill give a WSLc command immediate end-of-file. The newspawn_in_container_with_stdin/SpawnInContainerWithStdin(Async)/spawnInContainerWithStdinreturn 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.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) andcargo test -p mxc-sdk -p mxc_ffi --features mxc-sdk/wslc(3,249 passed): all passed. New regression tests fail without their fixes.run_wslc_all_tests.ps1, release x64): state-aware 138/138, including the new stdin cases; full WSLc suite 40/40.MxcWithWslcand the live WSLc tests (MXC_ENABLE_WSLC_TESTS=1): 358 total, 0 failed, no WSLc test skipped.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 asyncspawnto throw synchronously, so it fails regardless; this PR touches neither.✅ Checklist
Cargo.lock, thedependency-feed-checkcheck passes (see pull request builds)📋 Issue Type