Repository navigation
[WSLC] State-aware lifecycle: live exec output streaming + provision fs-delegation gate (PR 2c/3) - #806
Conversation
11dae67 to
39c76fa
Compare
There was a problem hiding this comment.
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.
39c76fa to
9b110a8
Compare
Gudge (MGudgin)
left a comment
There was a problem hiding this comment.
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.rsis byte-identical base vs head. Its JSONVec<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.rsandsrc/backends/wslc/common/src/stream_buffer.rsare 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.
9b110a8 to
bd05283
Compare
There was a problem hiding this comment.
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.ArgumentListat 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 toSkipped = 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_sendbackpressure and preserves byte fidelity, but this implementation usestry_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;
… add provision delegation regression tests
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
bd05283 to
f9d3f8f
Compare
There was a problem hiding this comment.
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_sendbackpressure and preserves byte fidelity, but this implementation usestry_send, drops this and all subsequent output onFull, 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.mdwith 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
f9d3f8f to
7ac1559
Compare
There was a problem hiding this comment.
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_awarecallsvalidate_provisionand returns beforeprovisionon a dry run (state_aware_dispatch.rs:105-109), while this backend's validation hook only runsvalidate_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:59says 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:
StreamFramepayloads are base64 strings after the protocol change, not JSON number arrays. The 64 KiB bound remains safe, but the stated expansion rationale conflicts withdaemon_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
$dripSleepSecdoes not control the sleep; the command is hard-coded tosleep 3inwslc_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_sendbackpressure and preserves byte fidelity, but this implementation usestry_sendand 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;
Gudge (MGudgin)
left a comment
There was a problem hiding this comment.
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.
📖 Description
.github/copilot-instructions.md.Summary
Third increment of the WSLc state-aware sandbox lifecycle. Brings
execInSandboxto 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-awareprovisionso it enforces the same object-normalization + delegation + overlap checks as the one-shot path.Live exec output streaming (Tier 1)
state_aware.rsflushes chunks to the caller as they arrive (with a short coalescing gate) rather than accumulating the full capture buffer first.wslc_state_aware_exec_dripfixture proves output is streamed, not buffered — the drip liveness check observes an inter-chunk gap of ~2s on the real WSLc host.Provision filesystem-delegation gate
State-aware
provisionpreviously built daemon volume mounts from the raw caller policy, skipping the object-identity normalization, D3 delegation check, and denied-path overlap validation that one-shotstart_containerruns. It now mirrors the one-shot order —normalize_object_conflicts→check_delegation→validate_denied_path_overlapon the normalized policy — closing delegation-bypass, alias-bypass, and post-normalization overlap holes.Review hardening (from 3-model review of the initial change)
mpsc::channel(256)withblocking_sendbackpressure (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.write_exec_resultnowclose()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.provisionre-runsvalidate_denied_path_overlapafter normalization (which only ever growsdeniedPaths), rejecting denials nested under a mount that only surface post-normalization.Testing
cargo fmt --all -- --checkclean;cargo clippy -D warningsclean onwslc_commonand the daemon.wslc_common166 unit tests + daemon 18 unit tests (incl. newleak_path_drains_queued_then_terminates).blocking_sendchange.Coming in the pipeline
Wslc*Config/*Resulttypes + brandedSandboxId<'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 GitHubActions build; it runs on merge to
main, and Microsoft reviewers with write access can trigger iton a PR with
/azp run. See docs/pull-requests.md.If the
dependency-feed-checkcheck fails on a new dependency, the crate must be added tothe feed before the PR can pass. See docs/pull-requests.md
for the steps.
Microsoft Reviewers: Open in CodeFlow