Repository navigation
Add the Windows Sandbox state-aware lifecycle + host daemon (Phase 2) - #578
Merged
Merged
Conversation
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
from
June 26, 2026 19:26
91e0bab to
5d411b0
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase1-one-shot
branch
from
July 7, 2026 04:04
9d5d7e5 to
e3ccb02
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
2 times, most recently
from
July 7, 2026 17:16
569651e to
1830960
Compare
Darren Hoehna (dhoehna)
approved these changes
Jul 8, 2026
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase1-one-shot
branch
from
July 11, 2026 20:17
8e2cb9b to
22cfc41
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
from
July 11, 2026 20:17
1830960 to
9728f3d
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase1-one-shot
branch
from
July 11, 2026 20:23
22cfc41 to
d140ea9
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
from
July 11, 2026 20:23
9728f3d to
e7957bc
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase1-one-shot
branch
2 times, most recently
from
July 13, 2026 19:54
daa4c4a to
153e927
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase1-one-shot
branch
from
July 13, 2026 20:49
5c49b06 to
11367a7
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
from
July 13, 2026 21:17
e7957bc to
e562263
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase1-one-shot
branch
from
July 13, 2026 21:25
11367a7 to
501432b
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
from
July 13, 2026 21:28
e562263 to
b29b708
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase1-one-shot
branch
from
July 14, 2026 17:48
501432b to
1124ea8
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase1-one-shot
branch
2 times, most recently
from
July 15, 2026 18:26
618e389 to
d2ae233
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
from
July 15, 2026 18:27
1191675 to
e4928e9
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase1-one-shot
branch
from
July 15, 2026 18:28
d2ae233 to
053d70a
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
from
July 15, 2026 18:29
e4928e9 to
d24b3e7
Compare
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
from
July 15, 2026 20:28
d24b3e7 to
b11bc6e
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Phase 2 of the Windows Sandbox rewrite by introducing a state-aware lifecycle (provision/start/exec/stop/deprovision) backed by a detached host daemon that holds a single live Windows Sandbox VM across multiple wxc-exec invocations. This integrates into the existing state-aware dispatcher, tightens experimental gating, and updates docs + E2E scripts to cover the new mode.
Changes:
- Add Windows Sandbox support to state-aware dispatch (
wsb:prefix routing +--experimentalgating) and propagate the CLI experimental flag into parsed state-aware requests. - Reintroduce and rewrite the Windows Sandbox daemon crate to hold the VM and serve a nonce-authenticated localhost control protocol (
PING/STOP/EXEC) with single-flight exec. - Update Windows Sandbox and state-aware lifecycle documentation and add a new PowerShell E2E script for the state-aware path.
Show a summary per file
| File | Description |
|---|---|
| tests/scripts/run_windows_sandbox_state_aware_tests.ps1 | New state-aware Windows Sandbox E2E test driver script. |
| tests/scripts/README.md | Documents the new state-aware Windows Sandbox test script. |
| src/core/wxc/src/main.rs | Adds --force-reclaim flag and ensures state-aware requests inherit CLI --experimental. |
| src/core/wxc_common/src/state_aware_dispatch.rs | Routes wsb: sandbox IDs to the Windows Sandbox backend + adds resolver test. |
| src/core/mxc_engine/src/state_aware.rs | Enforces --experimental for state-aware Windows Sandbox/IsolationSession and dispatches WSB runner. |
| src/Cargo.toml | Re-adds Windows Sandbox daemon crate to the workspace members. |
| src/Cargo.lock | Adds lock entries for the daemon crate and its deps. |
| src/backends/windows_sandbox/lifecycle/src/vm.rs | Improves orphan/wedge warning guidance (incl. --force-reclaim). |
| src/backends/windows_sandbox/lifecycle/src/teardown.rs | Adds force-reclaim reconcile path and avoids unreachable!() on unexpected kill-plan gaps. |
| src/backends/windows_sandbox/lifecycle/src/lib.rs | Enables the lifecycle crate’s state-aware module. |
| src/backends/windows_sandbox/lifecycle/src/control_plane.rs | Introduces WXC_WSB_FORCE_RECLAIM plumbing and force-reclaim startup classification + clarifies kill-set widening logic. |
| src/backends/windows_sandbox/lifecycle/src/bridge.rs | Adds host watchdog + capped output capture helpers; simplifies exit-frame API; adds tests. |
| src/backends/windows_sandbox/daemon/src/tcp_bridge.rs | Removes legacy bridge implementation (moved to lifecycle crate). |
| src/backends/windows_sandbox/daemon/src/sandbox_vm.rs | Removes legacy VM management module (moved to lifecycle crate). |
| src/backends/windows_sandbox/daemon/src/rendezvous.rs | Removes legacy rendezvous polling module (moved to lifecycle crate). |
| src/backends/windows_sandbox/daemon/src/pipe_server.rs | Removes legacy “pipe server” (replaced by new control server). |
| src/backends/windows_sandbox/daemon/src/main.rs | New daemon main: owns VM lifecycle, record publishing, IPC binding, crash watchdog, and teardown behavior. |
| src/backends/windows_sandbox/daemon/src/control_server.rs | New nonce-authenticated localhost control protocol with per-connection tasks + single-flight exec. |
| src/backends/windows_sandbox/daemon/Cargo.toml | Adds lifecycle dependency and tokio test-util for daemon tests. |
| docs/windows-sandbox/windows-sandbox.md | Updates high-level doc for dual-mode backend (one-shot + state-aware) and adds state-aware guidance. |
| docs/windows-sandbox/windows-sandbox-reference.md | Expands reference doc for daemon IPC + force-reclaim recovery and state-aware record layout. |
| docs/state-aware-lifecycle/mxc-state-aware-sandbox-api.md | Extends API doc to include Windows Sandbox in state-aware-capable backend set and clarifies prefix error behavior. |
| docs/schema.md | Documents state-aware envelope in schema.md (but currently has a wire-shape issue noted in review comments). |
| .gitignore | Renames the .review/ comment description. |
| .github/copilot-instructions.md | Updates repo instructions to reflect Windows Sandbox state-aware daemon/lifecycle and new test script. |
Review details
- Files reviewed: 24/26 changed files
- Comments generated: 2
- Review effort level: Low
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
3 times, most recently
from
July 16, 2026 17:45
24e8f68 to
9b01ab5
Compare
Huzaifa Danish (huzaifa-d)
approved these changes
Jul 16, 2026
This PR adds the multi-invocation Windows Sandbox lifecycle on top of the authenticated one-shot backend, together with the reviewer-driven hardening for guest output and VM teardown. Details * Implements provision, start, repeated single-flight exec, stop, and deprovision through `WindowsSandboxRunner` and durable owner-only records. * Adds a detached host daemon that owns the live VM, authenticates localhost IPC, reconnects guest data channels, and reclaims only provably-owned orphans. * Routes state-aware backend selection through `mxc_engine` with experimental gating, keeping `wxc-exec` as a thin CLI shell. * Enforces terminal-exit ordering with a daemon-local release token that can be created only after restoring and unlocking the guest slot. * Caps one-shot guest stdout/stderr capture per stream at 64 MiB (drain continues to EOF so the guest still exits cleanly, excess discarded). Truncation is surfaced via a host WARNING and an error_message note so a capped run is never presented as a clean, complete capture. * Adds a host-side execution watchdog (`timeout_ms` + 30s grace) so a frozen guest that never reports completion can no longer hang the host forever. * Adds --force-reclaim: an operator escape hatch that tears down a running WSB VM mxc cannot prove it launched (live snapshot as kill set) instead of wedging the machine-wide singleton. It never overrides a proven reclaim, an active run, or a probe failure, and cannot manufacture liveness. Transported to the detached daemon via the WXC_WSB_FORCE_RECLAIM env var. * Hardens teardown: documents the `plan_kill_set` Windows Sandbox singleton invariant, and replaces an `unreachable!()` in the Owned teardown arm with a logged fail-safe that preserves the marker for a later reconcile. * Softens the teardown-on-exit guarantee in warning + docs to best-effort (a launcher hard-kill can orphan a VM). * Adds state-aware documentation and Windows Sandbox lifecycle E2E coverage. Tests * `cargo test -p windows_sandbox_lifecycle` (172) and `-p wxc_windows_sandbox_daemon` (24) pass, including new coverage for the output cap boundary, the host watchdog firing when the guest never reports exit, force-reclaim precedence rules, and the renamed `classify_unusable_*` / `exec_against_unusable_slot_*` cases. * `cargo fmt --all -- --check` clean; `cargo clippy --workspace --all-targets -- -D warnings` clean; `cargo doc -p windows_sandbox_lifecycle --no-deps` resolves all intra-doc links. * `cargo check --workspace --all-targets`; `cargo check -p mxc_engine -p wxc --all-features`. Co-authored-by: Copilot <[email protected]> Copilot-Session: 5e1a34f4-0c05-4c65-b5ef-fb53eb6ff578 Generated-with: claude-opus-4.8
Gudge (MGudgin)
force-pushed
the
user/gudge/wsb-phase2-state-aware
branch
from
July 16, 2026 21:35
9b01ab5 to
e193f9f
Compare
shschaefer
approved these changes
Jul 16, 2026
Gudge (MGudgin)
pushed a commit
that referenced
this pull request
Jul 17, 2026
This PR fixes four robustness gaps in the Windows Sandbox state-aware daemon and lifecycle that surfaced in post-merge review of #578. Details * Daemon diagnostics are no longer discarded. `spawn_daemon` redirects the detached daemon's stderr to `daemon.log` in the per-sandbox owner-only record directory (append), so boot / teardown / orphan-reclaim failures in the VM-owning process are observable. The start-timeout error now names the concrete log path instead of "see daemon logs". * The streaming exec path gains a host-side watchdog. `handle_exec` wraps `stream_exec_on_guest` in `host_watchdog_deadline(timeout_ms + grace)` (the same helper the one-shot path uses, now `pub`); on expiry it marks the guest slot Unusable and sends the client a synthetic timeout exit frame, so a frozen-but-alive guest can no longer wedge the single-flight slot forever (the VM crash watchdog only fires once the VM processes are gone). * VM-slot contention is reported coherently. A new `HostVmLock::try_acquire` distinguishes genuine contention (the wait timed out) from a real create/wait failure: on contention the daemon exits with a distinct `DAEMON_EXIT_VM_SLOT_BUSY` code that `start` maps to `backend_unavailable`, while a real mutex failure propagates as an opaque backend error (with daemon.log diagnostics) rather than being mis-reported as busy. * The IPC wire protocol is versioned. `DaemonRecord` carries a `protocol_version` (independent of the on-disk `RECORD_SCHEMA_VERSION`, added with `#[serde(default)]` so a pre-versioning record reads back incompatible); `exec` refuses to drive a live daemon left by a different install whose wire version differs, rather than streaming frames against a mismatched peer. `stop`/`deprovision` keep using the stable single-line `STOP` so an orphaned VM can always be reclaimed. * Docs: windows-sandbox-reference.md updated for the daemon.log sink, the exec watchdog, the VM-slot busy mapping, and protocol versioning. Tests * New unit tests: `protocol_compatible` plus a serde-default (pre-versioning record reads incompatible) case for the new record field, `ensure_daemon_protocol` accept/refuse, the `vm_slot_busy` exit-code classifier, and a two-thread `named_mutex_try_acquire` test asserting a contended mutex yields `Ok(None)` (busy) rather than `Err`. The M2 watchdog reuses the one-shot-tested `host_watchdog_deadline` helper and `tokio::time::timeout` pattern. * `cargo fmt --all -- --check` clean; `cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warnings` clean. * `cargo test`: windows_sandbox_lifecycle 177 (+5), wxc_windows_sandbox_daemon 24, mxc_engine 25, wxc 15, wxc_common 453 -- all pass. Co-authored-by: Copilot <[email protected]> Copilot-Session: 5e1a34f4-0c05-4c65-b5ef-fb53eb6ff578 Generated-with: claude-opus-4.8
Darren Hoehna (dhoehna)
added a commit
to dhoehna/mxc
that referenced
this pull request
Jul 17, 2026
Resolve conflict in wxc_common/src/state_aware_dispatch.rs: register both the `lxc` (this PR) and `wsb` (upstream microsoft#578) state-aware backend prefixes in backend_from_prefix, and keep both resolve_backend unit tests. Added `correlation_vector: None` to the lxc test to match the ParsedStateAwareRequest field introduced upstream (microsoft#624). Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2 of the Windows Sandbox rewrite stack: add the state-aware lifecycle
(
provision -> start -> exec* -> stop -> deprovision) for Windows Sandbox on topof the Phase 1 one-shot rewrite, holding a single live VM across separate
wxc-execphase processes behind a persistent detached host-side daemon. The SDKfollows in Phase 3.
Details
windows_sandbox_lifecycle: re-enablesstate_aware.rs-- theStatefulSandboxBackendimpl onWindowsSandboxRunner.provisionvalidates +snapshots the filesystem policy and mints
wsb:<token>;startspawns thedetached daemon (which boots the VM and holds the guest control connection);
execrelays a script over the held connection;stop/deprovisiontear down.A process-global named mutex serialises start/stop/deprovision; the single host
VM slot is enforced.
wxc_windows_sandbox_daemon):control_server.rsserves anonce-authenticated localhost line protocol (
PING/STOP/EXEC), eachconnection on its own task so a long exec can't block a
STOP. Auth nonce viastdin; sandbox token via
--token. Re-added to the workspace members (droppedin Phase 1); the legacy
pipe_server/sandbox_vm/tcp_bridge/rendezvousmodules are deleted (rendezvous now lives in the lifecycle crate).
run_state_awareroutes thewsb:prefix toWindowsSandboxRunnerwith the same--experimentalgate as one-shot;state_aware_dispatchlearns thewsb-> WindowsSandbox prefix mapping.windows-sandbox.md/windows-sandbox-reference.md,schema.md(dual-modebackend row + state-aware envelope section), the state-aware API doc, and
copilot-instructions.md. While touchingschema.mdI reconciled its versiontable to the canonical
schemas/schema-version.json(>=0.4, <=0.8; stable0.7.0-alpha; state-aware 0.6.0-alpha) -- the rewrite had left it at the pre-0.8
<=0.7.run_windows_sandbox_state_aware_tests.ps1(state-aware E2E).Tests
cargo check --workspace --all-targets,cargo clippy --workspace --all-targets -- -D warnings, andcargo fmt --all -- --check: clean.cargo test: windows_sandbox_lifecycle 172 (incl. the state-aware suite),wxc_windows_sandbox_daemon 24 (incl. the renamed
classify_unusable_*/exec_against_unusable_slot_*cases), wxc_common 364 (incl. the newwsbresolver test), wxc 13 -- all passed.
node scripts/versioning/check-schema-versions.js: green.Related Issues