Skip to content

[WSLC] State-aware lifecycle: live exec output streaming + provision fs-delegation gate (PR 2c/3) - #806

Merged
Soham Das (SohamDas2021) merged 4 commits into
mainfrom
user/sodas/wslc-state-aware-2c
Aug 13, 2026
Merged

Soham Das (SohamDas2021) merged 4 commits into
mainfrom
user/sodas/wslc-state-aware-2c

Conversation

@SohamDas2021

@SohamDas2021 Soham Das (SohamDas2021) commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

📖 Description


Summary

Third increment of the WSLc state-aware sandbox lifecycle. Brings execInSandbox to Windows Sandbox streaming parity (Tier 1): stdout/stderr are relayed to the caller live as the container produces them, instead of being buffered and returned only at exit. Also closes a filesystem delegation gap in state-aware provision so it enforces the same object-normalization + delegation + overlap checks as the one-shot path.

Live exec output streaming (Tier 1)

  • The daemon relays container stdout/stderr over a per-exec channel; state_aware.rs flushes chunks to the caller as they arrive (with a short coalescing gate) rather than accumulating the full capture buffer first.
  • New E2E wslc_state_aware_exec_drip fixture proves output is streamed, not buffered — the drip liveness check observes an inter-chunk gap of ~2s on the real WSLc host.
  • Piped stdin remains deferred to Tier 2 (blocked on the WSLc SDK's IO-handle/callback exclusivity) — tracked in [WSLC] State-aware exec: forward piped stdin to the container (blocked on WSLC SDK) #804.

Provision filesystem-delegation gate

State-aware provision previously built daemon volume mounts from the raw caller policy, skipping the object-identity normalization, D3 delegation check, and denied-path overlap validation that one-shot start_container runs. It now mirrors the one-shot order — normalize_object_conflicts → check_delegation → validate_denied_path_overlap on the normalized policy — closing delegation-bypass, alias-bypass, and post-normalization overlap holes.

Review hardening (from 3-model review of the initial change)

  • Bounded live-output channel — the live relay uses a bounded mpsc::channel(256) with blocking_send backpressure (runs on the SDK's native IO callback threads, never the async runtime) instead of an unbounded channel, removing a daemon OOM hazard on high-volume output while preserving byte fidelity.
  • Leak-path drain termination — write_exec_result now close()s the output receiver before draining on the exit arm, so a leaked/killed container's sender can't keep the drain loop alive indefinitely.
  • Overlap re-check on normalized policy — provision re-runs validate_denied_path_overlap after normalization (which only ever grows deniedPaths), rejecting denials nested under a mount that only surface post-normalization.

Testing

  • cargo fmt --all -- --check clean; cargo clippy -D warnings clean on wslc_common and the daemon.
  • wslc_common 166 unit tests + daemon 18 unit tests (incl. new leak_path_drains_queued_then_terminates).
  • State-aware E2E 55/55 on the real WSLc host; drip liveness gap ~2s confirms live streaming after the blocking_send change.

Coming in the pipeline

  • PR 3/3 — TypeScript SDK: Wslc*Config/*Result types + branded SandboxId<'wslc'>
    and helper prefix wiring, mirroring the LXC state-aware SDK surface.

GitHub Actions runs the PR validation build automatically. The ADO pipeline
(MXC-PR-Build) is the Azure version of the PR pipeline, kept in parity with the GitHub
Actions build; it runs on merge to main, and Microsoft reviewers with write access can trigger it
on a PR with /azp run. See docs/pull-requests.md.

If the dependency-feed-check check fails on a new dependency, the crate must be added to
the feed before the PR can pass. See docs/pull-requests.md
for the steps.

Microsoft Reviewers: Open in CodeFlow

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.

Pull request overview

Adds live stdout/stderr streaming to state-aware WSLc execution and closes filesystem-policy validation gaps during provisioning.

Changes:

  • Streams bounded output chunks through the daemon protocol.
  • Applies filesystem normalization, delegation, and overlap validation.
  • Adds live-streaming E2E and daemon tests.

Reviewed changes

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

Show a summary per file
File Description
tests/scripts/run_wslc_state_aware_tests.ps1 Adds streaming assertions and strengthens output checks.
tests/configs/wslc_state_aware_exec_drip.json Adds delayed-output streaming fixture.
src/backends/wslc/daemon/src/session_manager.rs Connects SDK output callbacks to a bounded channel.
src/backends/wslc/daemon/src/control_server.rs Relays output frames before terminal status.
src/backends/wslc/common/src/state_aware.rs Streams output and adds filesystem policy gates.
src/backends/wslc/common/src/daemon_client.rs Adds callback-based streaming execution.
src/backends/wslc/common/src/container_steps.rs Adds optional live-output sinks to process callbacks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@SohamDas2021
Soham Das (SohamDas2021) force-pushed the user/sodas/wslc-state-aware-2c branch from 39c76fa to 9b110a8 Compare August 12, 2026 00:22

@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 for two blocking live-streaming issues: the bounded queue blocks inside the WSLc SDK callback path even though the existing implementation documents that this callback thread must never stall, and the output-first biased select! can prevent a completed/leaked execution from ever sending its terminal frame. These can respectively deadlock exit delivery and leave clients streaming forever.

Range verified: e5e4e050b7224e678fe5900d9b5e64766cc73b0b...9b110a87bf06b1e0239bd13dd24ce4fa6b39c5f6 (7 files, +670/-140). The merge base exactly matches GitHub's PR base. The locally captured git diff and gh pr diff are byte-for-byte identical at 1,290 lines.

Verified clean, with receipts: the provision path now applies normalization, delegation, and denied-overlap validation to the tightened policy in the intended order; the repository already has focused canonical alias/junction tests in policy_mapping.rs and one-shot junction E2Es; live-output frame ordering and finite leak-path termination have useful unit tests; Windows-specific modules/tests remain correctly gated. No Windows/WSL runtime tests were run as part of this filing.

Verified pre-existing - not independently attributed to this PR

  • src/backends/wslc/common/src/daemon_protocol.rs is byte-identical base vs head. Its JSON Vec<u8> representation is cited only because this PR newly makes it the high-volume per-chunk streaming format.
  • src/backends/wslc/common/src/wsl_container_runner.rs and src/backends/wslc/common/src/stream_buffer.rs are byte-identical base vs head. Their explicit non-blocking callback-thread invariant is supporting evidence for the new bounded-channel backpressure finding, not a separate defect charged to this PR.

Requested findings not filed after verification

  • Callback panic/concurrency coverage was withdrawn: the production sink is internally constructed, uses thread-safe mpsc::Sender, and has no demonstrated panic path beyond process-fatal allocation failure; testing an arbitrary panicking closure would not validate production behavior.
  • Global-stdio coupling and best-effort local write behavior predate this PR; the change moves those writes from post-run buffers to live chunks but does not introduce the architectural coupling itself.
  • The junction/symlink coverage finding was withdrawn because the shared overlap validator already has focused symlink/junction/absent-tail tests and the one-shot runner has real junction E2Es; repeating all of those through this orchestration helper would add little signal.
  • Racing blocked senders against receiver closure primarily tests Tokio's channel contract rather than repository logic; the material repository defect is blocking the SDK callback in the first place.

Medium and Low comments are non-blocking; the two High findings are the merge conditions for this review.

@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 Aug 12, 2026
Base automatically changed from user/sodas/wslc-state-aware-2b to main August 12, 2026 20:50
@SohamDas2021
Soham Das (SohamDas2021) requested a review from a team August 12, 2026 20:50
@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs-Attention Requires attention or a decision from the MXC maintainers. and removed Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. labels Aug 12, 2026
Copilot AI review requested due to automatic review settings August 12, 2026 21:14
@SohamDas2021
Soham Das (SohamDas2021) force-pushed the user/sodas/wslc-state-aware-2c branch from 9b110a8 to bd05283 Compare August 12, 2026 21:14

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.

Pull request overview

Copilot reviewed 44 out of 46 changed files in this pull request and generated 2 comments.

Suppressed comments (4)

tests/scripts/run_wslc_state_aware_tests.ps1:3

  • Declare the PowerShell 7 requirement. This harness uses ProcessStartInfo.ArgumentList at lines 176 and 237; under Windows PowerShell 5.1 that property is null, so both direct invocation and the new aggregate runner fail before any test executes.
    tests/scripts/run_wslc_all_tests.ps1:341
  • The delegated harness intentionally exits 0 when the daemon is missing or the backend is unavailable (its lines 99 and 368), but this code converts every such skip into Pass = true, Skipped = false. The aggregate summary therefore reports state-aware coverage as passed when zero state-aware tests ran. Have the child return a distinguishable skip status/result and map it to Skipped = true.
    docs/wsl/wslc-state-aware.md:59
  • This claims stdin is forwarded, but the implementation explicitly returns a null stdin handle and issue #804 records that callback-mode output makes stdin forwarding impossible with the current SDK. Document stdin as unsupported/deferred so users do not build commands that silently receive EOF.
| exec | `WslcCreateContainerProcess` in the warm container; stream stdout/stderr, forward stdin, return the process exit code. A timeout SIGKILLs the **process**, not the container. |

src/backends/wslc/daemon/src/session_manager.rs:199

  • The PR description says this channel uses blocking_send backpressure and preserves byte fidelity, but this implementation uses try_send, drops the current and all subsequent chunks when full, and turns an otherwise successful exec into a truncation error. Either align the implementation with the stated contract (without blocking the SDK exit-callback thread) or update the PR contract to explicitly describe lossy overflow behavior.
        match tx.try_send((kind, chunk.to_vec())) {
            Ok(()) => {}
            Err(TrySendError::Full(_)) => {
                overflowed.store(true, Ordering::Relaxed);
                return;

Comment thread src/core/mxc_engine/src/state_aware.rs Resolved
Address the two blocking review findings on the live exec-output stream:

- enqueue_output now uses try_send with an overflowed latch instead of
  blocking_send, so the WSLc SDK I/O callback thread (which also delivers
  the exit callback) is never parked when a slow pipe client stops draining.
- write_exec_result biases the select toward the done branch so a completed
  or leaked exec always writes its terminal frame; a latched overflow turns
  a clean Exit into a truncation Error via terminal_frame.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: f3ae1af2-7b79-4340-a5ce-a5402e7ede3d
Copilot AI review requested due to automatic review settings August 12, 2026 21:43
@SohamDas2021
Soham Das (SohamDas2021) force-pushed the user/sodas/wslc-state-aware-2c branch from bd05283 to f9d3f8f Compare August 12, 2026 21:43

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.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.

Suppressed comments (2)

src/backends/wslc/daemon/src/session_manager.rs:199

  • The PR description says this queue uses blocking_send backpressure and preserves byte fidelity, but this implementation uses try_send, drops this and all subsequent output on Full, and converts an otherwise successful exec into an error. Either document the implemented fail-on-overflow contract in the PR description or implement the claimed backpressure behavior; the current summary materially misstates the operational behavior.
        match tx.try_send((kind, chunk.to_vec())) {
            Ok(()) => {}
            Err(TrySendError::Full(_)) => {
                overflowed.store(true, Ordering::Relaxed);
                return;

src/backends/wslc/common/src/state_aware.rs:134

  • Please update docs/wsl/wslc-state-aware.md with this behavior change. Its exec table still says stdin is forwarded (line 59), while #804 and this implementation explicitly defer stdin, and lines 66–67 still describe output as relayed from captured buffers rather than live chunks. The backend guide is now materially inconsistent with the implementation.
    /// Runs one command in the warm container, relaying its stdout/stderr to the
    /// executor's own stdio **live** as the daemon streams it, then hands back an
    /// [`ExecHandle`] with sentinel pipe handles and a waiter that yields the
    /// captured exit code (so the dispatcher's `relay_exec_to_stdio` is a thin
    /// call-through, mirroring the IsolationSession and Windows Sandbox backends).

Co-authored-by: Copilot <[email protected]>

Copilot-Session: f3ae1af2-7b79-4340-a5ce-a5402e7ede3d
Copilot AI review requested due to automatic review settings August 12, 2026 21:56
@SohamDas2021
Soham Das (SohamDas2021) force-pushed the user/sodas/wslc-state-aware-2c branch from f9d3f8f to 7ac1559 Compare August 12, 2026 21:56

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.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated no new comments.

Suppressed comments (5)

src/backends/wslc/common/src/state_aware.rs:325

  • The new gate is bypassed by --dry-run. dispatch_state_aware calls validate_provision and returns before provision on a dry run (state_aware_dispatch.rs:105-109), while this backend's validation hook only runs validate_provision_policy (state_aware.rs:209-215), which does not perform object normalization or delegation. As a result, dry-run can report success for an inaccessible or alias-conflicting policy that real provision rejects. Run this shared gate from the validation hook as well (discarding the normalized policy there), or otherwise ensure dry-run executes the same filesystem checks.
    // WSLc provision-time filesystem-policy gate (D6 normalization → D3
    // delegation → denied-path overlap), shared verbatim with the one-shot
    // runner via `policy_mapping::apply_provision_policy_gate`. The daemon must
    // mount the tightened policy, so a writable alias of a readonly object never
    // leaks and a persistent daemon never mounts a path the phase caller could
    // not delegate.

src/backends/wslc/daemon/src/control_server.rs:428

  • The public WSLc lifecycle documentation now contradicts this behavior: docs/wsl/wslc-state-aware.md:59 says exec forwards stdin, while these lines correctly state that stdin is unavailable and deferred to #804; lines 66-67 also still describe output as relayed from completed capture buffers rather than streamed live. Update that backend guide in this PR so consumers do not rely on unsupported stdin or outdated buffering semantics.
/// Output streaming (process -> `Stdout`/`Stderr`) is live. Client `Stdin`
/// frames are NOT forwarded: the WSLc SDK consumes all process IO handles once
/// any `WslcSetProcessSettingsCallbacks` is registered (the callback path this
/// live output streaming depends on), so `WslcGetProcessIOHandle(STDIN)` is
/// unavailable. Piped stdin would require a handle-mode rearchitecture (no
/// callbacks; `ReadFile` threads for stdout/stderr + `WriteFile` for stdin) and
/// is deferred; stdin forwarding is tracked in issue #804.

src/backends/wslc/daemon/src/session_manager.rs:167

  • This newly added explanation is already stale: StreamFrame payloads are base64 strings after the protocol change, not JSON number arrays. The 64 KiB bound remains safe, but the stated expansion rationale conflicts with daemon_protocol.rs:198-203.
/// Max bytes per enqueued live-output chunk. A single SDK callback can deliver
/// an arbitrarily large buffer; splitting it here bounds each queue entry's
/// allocation and keeps the resulting `Stdout`/`Stderr` frame well under the
/// protocol's `MAX_FRAME_SIZE` (a `Vec<u8>` serializes as a JSON number array,
/// ~4x expansion), so a large callback can never overflow a frame and abort the
/// stream before its terminal frame.

tests/scripts/run_wslc_state_aware_tests.ps1:435

  • $dripSleepSec does not control the sleep; the command is hard-coded to sleep 3 in wslc_state_aware_exec_drip.json. Following this de-flaking instruction would therefore only change the diagnostic text, not widen the observed gap. Point maintainers to update the fixture (and keep this value synchronized), or build the request from the variable.
    # from false-failing under CI load). Widen $dripSleepSec, not $dripMinGapSec,
    # if a slower host is ever observed.

src/backends/wslc/daemon/src/session_manager.rs:199

  • This contradicts the PR summary's stated hardening: the description says the bounded channel uses blocking_send backpressure and preserves byte fidelity, but this implementation uses try_send and drops the remainder once full. The code explicitly reports truncation, so either update the PR contract to disclose that high-volume/slow-consumer output can be lost, or change the design if lossless streaming is required.
    for chunk in bytes.chunks(LIVE_OUTPUT_MAX_CHUNK_BYTES) {
        match tx.try_send((kind, chunk.to_vec())) {
            Ok(()) => {}
            Err(TrySendError::Full(_)) => {
                overflowed.store(true, Ordering::Relaxed);
                return;

@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.

Verified all nine prior review findings at 7ac1559.

Local verification:

  • cargo fmt --all -- --check
  • cargo test -p wslc_common: 182 passed
  • cargo test -p wxc_wslc_daemon: 22 runnable tests passed; 2 WSL2-host lifecycle tests ignored

The live WSL2 E2E suite was not run locally.

@SohamDas2021
Soham Das (SohamDas2021) merged commit 32a4c44 into main Aug 13, 2026
23 checks passed
@SohamDas2021
Soham Das (SohamDas2021) deleted the user/sodas/wslc-state-aware-2c branch August 13, 2026 19:17
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Needs-Attention Requires attention or a decision from the MXC maintainers. label Aug 13, 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.

3 participants