Skip to content

Commit b815cf5

Browse files
fix(windows): end sandbox processes when the gateway is killed (#5299)
Own each MXC sandbox generation with a kill-on-close job and place children in that job at process creation. Restrict inherited handles, use non-inheritable gateway sockets, and cover hard-kill and restart behavior with regression tests. Closes #5298 Signed-off-by: ashwind <ashwind@nvidia.com> Signed-off-by: Shailendra Singh <shailendras@nvidia.com>
1 parent 8a93cab commit b815cf5

15 files changed

Lines changed: 2439 additions & 62 deletions

File tree

‎.agents/skills/build-openshell-mxc-windows/SKILL.md‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ variable by default). Require both a nonempty response and the OpenShell proxy
478478
CA issuer; never replace these assertions with an insecure TLS request. This
479479
fixture permits unavailable CRL information using best-effort Schannel revocation
480480
for the ephemeral private CA; this is not revocation qualification. This
481-
scenario is not part of the default seven offline-capable E2E scenarios.
481+
scenario is not part of the default offline-capable E2E scenarios.
482482

483483
The default `host-service` scenario runs the HTTP fixture on host `127.0.0.1`
484484
and a dynamic port, then checks two nonce-bound replies from direct curl requests
@@ -489,6 +489,26 @@ firewall modification is required. A failed host health check or workload
489489
request fails the test. This verifies direct localhost connectivity; retain
490490
the existing shared proxy SSRF controls.
491491

492+
The default `gateway-kill` and `gateway-restart` scenarios cover gateway loss.
493+
`gateway-kill` hard-kills the gateway and requires every sandbox process under it
494+
(the supervisor, `wxc-exec`, the boundary and the workload) to end and a
495+
replacement gateway to bind the port. `gateway-restart` sends a real Ctrl-C with
496+
a persisted SQLite database, requires a logged graceful shutdown and every
497+
sandbox process to end, then restarts on the same database and requires the
498+
record to still be listed, its workload not to be running, and the record to be
499+
deletable with its name reusable. Use `-Scenario gateway-kill` or
500+
`-Scenario gateway-restart` for focused checks. Report the behavior accurately:
501+
gateway exit ends workloads and MXC has no restart recovery, unlike the Docker,
502+
Podman and VM drivers, which stop and recover sandboxes on a graceful restart
503+
(MXC reports `gateway_manages_lifecycle: false`). Never describe MXC as
504+
stop-and-recover. A graceful stop ends workloads with or without the
505+
per-generation job; the job is what covers a hard kill, so do not cite
506+
`gateway-restart` as evidence for the job. If recovery is added, update
507+
`gateway-restart`, the driver README and `WINDOWS.md` together. These scenarios
508+
send Ctrl-C and track process trees, so run them on a host you can disturb;
509+
they track only processes under their own gateway and leave other sandboxes
510+
alone.
511+
492512
When reporting `windows:ci`, distinguish these categories:
493513

494514
- Passed tests from the full x64 workspace test log.

‎Cargo.lock‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎WINDOWS.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ under development and is not a production-qualified security boundary:
2828
Treat the gateway host as trusted.
2929
- Foreground main-process attachment and ConPTY resize are unavailable. Create
3030
command workloads with `--detach`.
31-
- Gateway restart recovery for live MXC generations is not supported.
31+
- Gateway exit ends sandbox workloads, and there is no restart recovery. When
32+
the gateway process ends (a graceful stop with Ctrl-C, a crash, or a kill), the
33+
sandbox processes it started end with it, workloads included. After the gateway
34+
restarts on the same database, each sandbox record is still listed but its
35+
workload is not restarted, and its phase is not updated to show that the
36+
workload ended (for example `Provisioning` after a graceful stop, `Ready` after
37+
a hard kill). Delete the record to reuse its name. The Docker, Podman and VM
38+
drivers stop sandboxes on a graceful gateway stop and recover them on restart;
39+
MXC does not provide that recovery. See
40+
[gateway exit and restart](https://github.com/NVIDIA/OpenShell/blob/windows/crates/openshell-driver-mxc/README.md#gateway-exit-and-restart).
3241

3342
See the Windows branch's [MXC driver documentation](https://github.com/NVIDIA/OpenShell/blob/windows/crates/openshell-driver-mxc/README.md)
3443
for the current capabilities and enforcement limits, and its

‎crates/openshell-driver-mxc/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ uuid = { workspace = true }
3737
openshell-mxc-boundary = { path = "../openshell-mxc-boundary" }
3838
openshell-isolation-interface = { path = "../openshell-isolation-interface" }
3939
openshell-sandbox-backend = { path = "../openshell-sandbox-backend" }
40-
windows = { workspace = true, features = ["Win32_System_Kernel", "Win32_System_Performance", "Win32_System_SystemInformation"] }
40+
windows = { workspace = true, features = ["Win32_Storage_FileSystem", "Win32_System_Console", "Win32_System_Diagnostics_ToolHelp", "Win32_System_JobObjects", "Win32_System_Kernel", "Win32_System_Performance", "Win32_System_Pipes", "Win32_System_SystemInformation", "Win32_UI_Shell"] }
4141

4242
[dev-dependencies]
4343
anyhow = { workspace = true }

‎crates/openshell-driver-mxc/README.md‎

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ not required; driver-owned guest TLS fields are rejected.
222222
| Exec, signals, retained output | Authenticated Sandbox Protocol; ConPTY resize is not yet supported |
223223
| Dynamic forwarding | Standard supervisor `ForwardTcp` path through sandbox loopback connect |
224224
| ETW/OCSF audit | Optional Windows Sandboxing ETW consumer |
225-
| Gateway restart recovery | Not yet supported; live MXC generations remain in-memory |
225+
| Gateway exit | Ends the sandbox processes, workloads included ([details](#gateway-exit-and-restart)) |
226+
| Gateway restart recovery | Not supported; live MXC generations remain in-memory and are not recovered |
226227

227228
Workloads receive the proxy CA in `NODE_EXTRA_CA_CERTS` and `DENO_CERT`, and a
228229
combined bundle in `SSL_CERT_FILE`, `REQUESTS_CA_BUNDLE`, `CURL_CA_BUNDLE`, and
@@ -254,6 +255,44 @@ explicit UI policy (including `{}`) for drivers missing this capability; those
254255
drivers need no UI-specific handling. UI policy itself does not require the
255256
`allow_driver_config` opt-in. Recreate the sandbox to change these settings.
256257

258+
## Gateway exit and restart
259+
260+
The driver runs inside the gateway. Each sandbox generation runs in its own
261+
Windows job object with kill-on-close: the host supervisor and `wxc-exec` are
262+
created inside it (the job is named in the `CreateProcessW` call, so no process
263+
of a generation ever exists outside its job, even if the gateway is killed
264+
mid-spawn), and the boundary and workload processes below them inherit it. When a generation stops, the job is terminated, and when the gateway process
265+
ends for any reason Windows closes the job and ends everything in it. In
266+
practice:
267+
268+
- **Stop and delete** end the whole generation: supervisor, `wxc-exec`, boundary
269+
and workload, not only the two direct children.
270+
- **Graceful gateway stop** (Ctrl-C) ends every sandbox process, workloads
271+
included, and frees the gateway port.
272+
- **Gateway crash or hard kill** ends every sandbox process through the job, and
273+
the listening socket is not inherited by any child, so a new gateway can bind
274+
the port at once.
275+
276+
MXC does not recover sandboxes across a gateway restart. The Docker, Podman and
277+
VM drivers stop their sandboxes on a graceful gateway stop and recover them when
278+
the gateway starts again; MXC reports `gateway_manages_lifecycle: false`, so the
279+
gateway skips that shutdown sweep and startup recovery for it, and live
280+
generations exist only in the driver's memory. After a restart on the same
281+
database:
282+
283+
- each sandbox record is still listed, with the phase it had when the gateway
284+
went away (for example `Provisioning` after a graceful stop, `Ready` after a
285+
hard kill); nothing updates it to show that the workload ended;
286+
- no workload is running, and nothing restarts it;
287+
- `openshell sandbox delete <name>` removes the record, and the name can then be
288+
created again.
289+
290+
Treat a sandbox that was running when the gateway exited as lost, delete its
291+
record, and create it again. The `gateway-kill` and `gateway-restart` E2E
292+
scenarios (see [Validation](#validation)) check this behavior. Behavior for a
293+
driver that runs as its own process, separate from the gateway, is not defined
294+
yet.
295+
257296
## Validation
258297

259298
Windows build tasks embed the CRT in all four executables and Z3 in the
@@ -351,7 +390,7 @@ explicitly loads the boundary-injected CA bundle and records the peer certificat
351390
success requires a nonempty response and the OpenShell proxy CA issuer. It does
352391
not install a host trust root or disable CA/hostname verification. The fixture
353392
uses best-effort Schannel revocation because the ephemeral private CA has no CRL
354-
distribution point; it does not qualify revocation enforcement. The default seven E2E
393+
distribution point; it does not qualify revocation enforcement. The default E2E
355394
scenarios remain independent of Internet access.
356395

357396
The `forwarding` scenario starts a TCP listener inside MXC, then verifies two
@@ -375,12 +414,33 @@ host service is checked before launch and stopped after testing. Select it with
375414
`-Scenario host-service`; no Internet access, LAN address, or firewall changes
376415
are required. This verifies direct localhost connectivity.
377416

417+
The default `gateway-kill` scenario checks sandbox cleanup when the gateway dies
418+
without warning. It creates a sandbox with a long-running workload, records the
419+
sandbox process tree under that gateway, hard-kills the gateway, and requires
420+
every recorded process to end and the gateway port to be bindable again (a
421+
replacement gateway must start on it). Only processes under the scenario's own
422+
gateway are tracked, so other sandboxes on the host are left alone. It relies on
423+
each sandbox generation's kill-on-close job object; no workload outlives the
424+
gateway. Select it with `-Scenario gateway-kill`.
425+
426+
The default `gateway-restart` scenario covers a graceful gateway stop with
427+
persisted state. It runs the gateway on a SQLite file, creates a sandbox with a
428+
long-running workload, sends a real Ctrl-C, and requires the gateway to log a
429+
graceful shutdown and exit, every recorded sandbox process to end, and a restart
430+
on the same database to start. After the restart the sandbox record must still be
431+
listed (the observed phase is `Provisioning` and does not change), its workload
432+
must not be running (MXC has no restart recovery), and the record must be
433+
deletable with its name reusable. The scenario pins today's no-recovery behavior,
434+
so it needs updating when recovery is added. A graceful stop ends the workloads
435+
with or without the per-generation job; the job is what covers a hard kill.
436+
Select it with `-Scenario gateway-restart`.
437+
378438
The `ws-agent.yaml` and `openclaw-gateway.yaml` policies preserve the Windows
379439
branch's workload grants. `inference.yaml` is a template: replace its filesystem,
380440
curl executable, inference host, and port placeholders before use. Authorize
381441
curl, which owns the network socket, not its cmd launcher. These policies have
382442
parser/mapper regression coverage; they do not add live WebSocket, OpenClaw,
383-
or provider-backed inference scenarios to the seven-scenario E2E runner.
443+
or provider-backed inference scenarios to the E2E runner.
384444

385445
With `-KeepRunning`, the runner restores the caller's environment but retains
386446
the disposable CLI/runtime directory for the live gateway and prints its path.

0 commit comments

Comments
 (0)