Repository navigation
nvx: end a one-shot run's OpenVMM with the run, and say when it is stuck exiting - #2099
Merged
Pedro Henrique Penna (ppenna) merged 3 commits intoNov 24, 2026
Merged
Conversation
On Windows, terminating `nvx.exe` during `nvx sandbox run` left its `openvmm.exe` running without a parent, as when a supervisor ends a run (#1910, case 1). The one-shot runs, `nvx run` and `nvx sandbox run`, start OpenVMM in the foreground: in the caller's console and jobs, and in the job named after its log. Nothing ended it once `nvx` was gone, since the log's job does not kill its processes when it closes, and the spawn closes its handle at once. A foreground spawn now also starts OpenVMM in an owning job: an unnamed job object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, whose only handle, which is never inheritable, the returned launch holds. The job list names it after the log's job, in which it nests, and both nest in the jobs of `nvx` that keep their processes' children. Windows closes the handle when `nvx` ends, however it ends, which ends OpenVMM; releasing the launch does too. Detached spawns, those of managed sandboxes and of the library, are unchanged. This is the second option of #780. Evidence on Windows 11 with WHP and the v0.1.0-dev.efe086d96205 artifacts: killing `nvx.exe` 10 s into `sandbox run --hypervisor whp --upper ram --entrypoint /bin/sleep --arg 300` left OpenVMM running 10 s later at 6681c2e; with this change OpenVMM is gone. Tests: a foreground child ends once its spawn is dropped, while a detached one keeps running, and a `sandbox run` whose CLI is killed ends its fake OpenVMM. Both fail at the base revision. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5 tasks done
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Ctrl-C during force_exit can bypass the bounded shutdown wait, allowing cleanup and return without confirming OpenVMM has exited.
1 open issue
What changed in this PR
This PR addresses #1910 by tying one-shot Windows VMs to their NVX run and improving forced-stop diagnostics and cleanup. It changes NVX’s host lifecycle handling without changing OpenVMM code or its pin.
Changes:
- Adds a Windows kill-on-close job for foreground OpenVMM launches.
- Shares forced-stop handling between sandbox runs and stops, preserving workload errors and identifying stuck exits.
- Removes abandoned Windows run directories and adds regression tests and documentation.
| File | Description |
|---|---|
nvx/tests/cli.rs |
Tests killed runs, stuck exits, and directory cleanup. |
nvx/src/host/vm/tests.rs |
Tests diagnostics for a forced termination with an unconfirmed exit. |
nvx/src/host/vm.rs |
Reports stuck exits and documents foreground ownership. |
nvx/src/host/spawn.rs |
Documents Windows foreground launch lifetime. |
nvx/src/host/platform/windows/tests.rs |
Tests job ownership and adds a held-exit helper. |
nvx/src/host/platform/windows/spawn.rs |
Adds kill-on-close jobs to foreground launches. |
nvx/src/host/platform/windows/mod.rs |
Exposes the log-release check. |
nvx/src/host/platform/windows/log_claim.rs |
Checks whether a log has no open holders. |
nvx/src/host/platform/tests.rs |
Re-exports the held-exit test helper. |
nvx/src/host/cli/sandbox/mod.rs |
Exposes abandoned-directory cleanup to cold runs. |
nvx/src/host/cli/sandbox/lifecycle/stop.rs |
Extracts shared forced-stop handling. |
nvx/src/host/cli/sandbox/lifecycle/start/tests.rs |
Tests selective removal of abandoned directories. |
nvx/src/host/cli/sandbox/lifecycle/start.rs |
Updates run teardown, error reporting, and cleanup. |
nvx/src/host/cli/sandbox/lifecycle/mod.rs |
Re-exports abandoned-directory cleanup. |
nvx/src/host/cli/run.rs |
Cleans abandoned cold-run directories on Windows. |
nvx/README.md |
Documents ownership, cleanup, and stuck-exit errors. |
nvx/Cargo.toml |
Enables Windows debugger APIs for tests. |
doc/usage.md |
Updates run behavior and error-code guidance. |
doc/run.md |
Explains forced stops, Windows ownership, and cleanup. |
Review effort: Balanced
Pedro Henrique Penna (ppenna)
force-pushed
the
agents/issue-1910-run-vmm-lifetime
branch
from
November 24, 2026 14:35
17f99c2 to
e67fc75
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
On Ctrl-C, the CLI suppresses the unconfirmed-exit error and prints only “Interrupted,” hiding the stuck-exiting diagnostic; this path needs explicit error reporting and an end-to-end assertion.
1 open issue
1 resolved since last review
Review effort: Balanced
Pedro Henrique Penna (ppenna)
force-pushed
the
agents/issue-1910-run-vmm-lifetime
branch
from
November 24, 2026 15:09
e67fc75 to
b726fae
Compare
Pedro Henrique Penna (ppenna)
force-pushed
the
agents/issue-1910-run-vmm-lifetime
branch
from
November 24, 2026 15:44
b726fae to
a1ada00
Compare
When `--timeout` expired while the workload of `nvx sandbox run` was busy, the run terminated OpenVMM, waited a fixed 10 s for its exit, and then failed with `error[still-running]: cannot confirm exit of VM process <pid>`, dropping the workload's own `timed-out` error and keeping the VM directory, while `openvmm.exe` stayed listed (#1910, case 2). Windows keeps a terminated process until its pending I/O completes or is canceled, and an OpenVMM that was terminated during heavy virtio-fs I/O stayed so until the host restarted (case 3), in the same state as a process whose debugger holds its exit: exit code set, no handles, and not signaled. The run now forces its VM down as `sandbox stop` does once its grace has passed: through `force_exit`, which `stop` shares, it terminates OpenVMM and waits up to `--timeout` seconds, and at least the 10 s that it waited before, for the exit, in a wait that Ctrl-C ends. After Ctrl-C, whenever it comes, the run terminates OpenVMM at once and waits 10 s for it without heeding Ctrl-C, as it did before, and then ends as interrupted. It takes whether OpenVMM exited on its own from the outcome of that stop, since a stop that finds the VM exited after the termination reports it as exited. It reports the workload's error, and then, when it cannot confirm the exit, the stop's, also after Ctrl-C, after which `nvx` would otherwise print only `Interrupted`, but not a failure that came after Ctrl-C, as when the terminal's Ctrl-C also ends OpenVMM. `vm::stop` now says that a process that its termination reached, but that has not exited, is stuck exiting; such a process runs no code of its own any longer, so the run removes its VM directory, as a second termination that succeeds shows, and keeps it only for a VM that no termination reached. Evidence on Windows 11 with WHP and the v0.1.0-dev.efe086d96205 artifacts, with a debugger that holds the exit of the real OpenVMM of `sandbox run --timeout 15` and a busy workload: at 6681c2e the run failed after 30 s with only `error[still-running]: cannot confirm exit of VM process 14648` and kept its directory; with this change it fails after 34 s with `error[timed-out]: managed control response timed out` and `error[still-running]: cannot confirm exit of VM process 5112: it is stuck exiting after its forced termination`, and removes its directory. A busy workload without the debugger still fails with `timed-out` alone and leaves nothing. Tests: `vm::stop` says that a terminated process whose debugger holds its exit is stuck exiting, and a `sandbox run` whose fake OpenVMM is held so reports both errors and removes its VM directory. Both fail at the base revision; the debuggers need the Win32 debugging API of windows-sys in the development dependencies. With Ctrl-C raised in a console of their own, the run's forced stop still waits for the exit that a debugger holds and then says that it is stuck, and a `sandbox run` that Ctrl-C interrupts while its workload runs, while its VM stops after the guest refused the workload, or while it forces its VM down after the workload outlived `--timeout`, reports the workload's error, the held OpenVMM as stuck exiting, and `Interrupted`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A `sandbox run` or a cold `nvx run` that is terminated, as when a supervisor ends `nvx.exe`, cannot remove its temporary VM directory, `nvx-sandbox-run-` or `nvx-run-` and 32 hexadecimal digits in the temporary directory, which then stays behind with OpenVMM's log (#1910, case 1). Only another process can remove it, and only once it is sure that no run or OpenVMM still uses it. On Windows, where a run's OpenVMM now ends with the run, a run first removes the directories of the user's earlier runs that hold nothing but NVX's files and whose log no process holds open any longer: an open of the log that shares nothing succeeds only once both the run, which now keeps a handle of its log until it returns, and its OpenVMM, which holds the log as its standard output until it exits, are gone. It leaves any other directory, such as one without a log, one that holds another file, or one that is not private. A run whose directory another run removed first, in the moment after it released its log, takes the directory for removed. Other hosts keep their behavior, since a terminated run leaves its OpenVMM running there. Evidence on Windows 11 with WHP: after `nvx.exe` was killed during `sandbox run`, `%TEMP%\nvx-sandbox-run-805fa5be...` held its log; the next run removes such a directory. Tests: the removal takes only the directories that runs abandoned, and a `sandbox run` removes the directory that a killed run left. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
force-pushed
the
agents/issue-1910-run-vmm-lifetime
branch
from
November 24, 2026 16:06
a1ada00 to
b3c31a9
Compare
Pedro Henrique Penna (ppenna)
deleted the
agents/issue-1910-run-vmm-lifetime
branch
November 24, 2026 16:41
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.

Fixes #1910
Its stack, #2092, #2095, #2096, #2097, and #2098, has landed, so it now targets
dev, whose history holds its base: only its three commits belong to it. It changes no OpenVMM code and keeps theopenvmmgitlink ofdev, so it has no OpenVMM pull request.What does this pull request change?
On Windows, the one-shot runs,
nvx sandbox runand a coldnvx run, now own their OpenVMM: the VM ends with the run, whatever endsnvx.exe. Asandbox runwhose workload outlives--timeoutforces its VM down assandbox stopdoes, and every forced stop says when OpenVMM is stuck exiting, rather than only that it cannot confirm its exit. A run also removes the VM directories that terminated runs left in the temporary directory.nvx: end a one-shot run's OpenVMM with the run on WindowsJOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE, whose only handle, which is never inheritable, the launch holds. The job list names it after the job of the log, in which it nests; OpenVMM also stays in the jobs ofnvxthat keep their processes' children. Windows closes the handle whennvxends, however it ends, and the job then ends OpenVMM; releasing the launch does too. Detached spawns, those of managed sandboxes and of the library, are unchanged.sandbox: force a timed-out run's VM down as stop does--timeout, the run terminates OpenVMM inforce_down, throughforce_exit, whichsandbox stopnow shares, and waits up to--timeout, and at least the 10 s that it waited before, in a wait that Ctrl-C ends. After Ctrl-C, whenever it comes, the run terminates OpenVMM at once and waits 10 s for its exit without heeding Ctrl-C, as it did before, and then ends as interrupted. It reports the workload's error, then, when it cannot confirm the exit, the stop's, also after Ctrl-C, after whichnvxwould otherwise print onlyInterrupted, but not a failure that came after Ctrl-C, as when the terminal's Ctrl-C also ends OpenVMM.vm::stopsayscannot confirm exit of VM process N: it is stuck exiting after its forced terminationwhen its termination reached the process, which runs no code of its own any longer, so the run removes its VM directory then.sandbox: remove the VM directories that terminated runs leftnvx-sandbox-run-*(or, fornvx run,nvx-run-*) directories that are private, hold only NVX's files, and whoseopenvmm.logno process holds open any longer: a run now keeps its log open until it returns, and its OpenVMM holds it until it exits.Start with
owning_jobandspawn_listedinnvx/src/host/platform/windows/spawn.rs, then the stop phase ofrunandforce_downinnvx/src/host/cli/sandbox/lifecycle/start.rs, andforce_exitinstop.rs.What it leaves out:
TerminateProcessdocuments, and the stuck processes of the issue are in that state: exit code set, no handles, not signaled, one thread in anExecutivewait. OpenVMM's virtio-fs issues ordinary synchronous NT file I/O throughlxutil(handles opened withFILE_SYNCHRONOUS_IO_NONALERT; the microVM device has no DAX window, and it uses no oplocks, change notifications, or byte-range locks), so no change of OpenVMM makes that I/O cancellable: a driver that neither completes nor cancels it holds the process. As the issue's expectation allows,nvxnow tells such a process apart from one that still runs and says so; the process still holds its memory until the driver lets it go or the host restarts, and a managed sandbox whose OpenVMM is stuck keeps its runtime record, as for any exit that cannot be confirmed.nvx, which a terminal's signals reach, but aSIGKILLofnvxalone leaves it running, and no run removes its directory then. The issue concerns Windows.Why is this change needed?
nvxand in the job named after its log, which does not end its processes when it closes and whose handle the spawn closes at once, so nothing ended OpenVMM oncenvxwas gone. nvx-rs: keep a Windows launch's checked images guarded when its launcher ends before OpenVMM opens them #780 proposed a kill-on-close job for Windows launches as its second option; nvx-rs: keep a Windows launch's images guarded when its launcher ends before OpenVMM opens them #987 implemented the first. Making the log's job kill-on-close instead was rejected: it is named, its handle is inheritable during the spawn's window, and claim checks open it by name, so another process could keep it open afternvxended.cannot confirm exit of VM process N, dropping the workload's own error, and kept the VM directory. A longer wait alone would not have told a stuck process from a running one.How was this change validated?
Checks and results, locally on Windows 11, before the rebase onto #2098 unless noted:
python scripts\local_gates.py --base origin/dev --run:test-changes(no change to an existing test; 21 added),markdown-links,test-layout,nvx-format,nvx-lint,nvx-test,nvx-doc, andnvx-msrvpassed.nvx-cliran 2314 Python tests, 2 of which hit the 10-second timeout of the Git Bash guest-script harness while concurrent builds held the host's CPU at 100%; this change touches no script.cargo fmt --all --check, the six Clippy invocations of check-nvx,cargo clippy --locked --all-targets --all-features --target x86_64-unknown-linux-gnu -- -D warnings,cargo doc --locked --no-deps --all-featureswith-D warnings,cargo +1.89 check --locked --all-targets --all-features, the unit tests ofhost::platform,host::vm,host::cli::sandbox,host::spawn, andhost::process(181 passed),cargo test --locked --all-features --test cli(118 passed),check_test_layout.py,check_markdown_links.py, andcheck_test_changes.py: passed.cargo fmt --all --check, the six Clippy invocations of check-nvx and the one for the Linux target,cargo docwith-D warnings,cargo +1.89 check,cargo test --locked --lib --no-default-features --no-run, the unit tests ofhost::cli::sandbox,host::vm, andhost::platform(157 passed),cargo test --locked --all-features --test cli(119 passed),check_test_layout.py,check_markdown_links.py, andcheck_test_changes.py(no change to an existing test; 35 added): passed. The Linux CI run of an intermediate head failedinterrupts::interrupting_a_run_ends_it_as_interrupted_even_if_openvmm_exits_first: Ctrl-C to the whole process group also ended the fake OpenVMM, and the run reported the closed endpoint that this caused beforeInterrupted. The run now reports only a failure that the workload met before Ctrl-C; that test covers it on Linux, where the hosts that could run it here were unreachable.python scripts\public_api.py: passed; the public API does not change.a_foreground_child_ends_with_its_spawn_and_a_detached_one_outlives_it,stop_says_that_a_process_that_its_forced_termination_reached_is_stuck_exiting,a_killed_run_ends_its_openvmm_and_the_next_run_removes_its_vm_directory,a_run_whose_openvmm_is_stuck_exiting_says_so_and_removes_its_vm_directory, anda_run_removes_only_the_vm_directories_that_runs_abandoned. A stuck exit is emulated with a debugger that holds the exit of the process: Windows does not signal it until the debugger continues the exit's event, which leaves it in the state of the issue's stuck processes.a_run_that_ctrl_c_interrupts_while_it_forces_its_vm_down_waits_for_the_vm_all_the_sameraises a real Ctrl-C in a helper that runs in a console of its own, whileforce_downwaits for a held exit; it fails when Ctrl-C ends the stop at once, as the first revision of this pull request did, and passes with the fix.an_interrupted_run_reports_a_failed_workload_and_a_stuck_openvmmrunssandbox runin such a console, holds its fake OpenVMM's exit, and raises Ctrl-C there while the workload runs, while the run waits for its VM to stop after the guest refused the workload (--cwd /missing), and while it forces its VM down after the workload outlived--timeout: each run prints the workload's error, if any,error[still-running]: … it is stuck exiting after its forced termination, andInterrupted, with status 130. Without the fixes, the stuck-exiting error was missing, as at the base revision, where an interrupted run printed onlyInterrupted, and Ctrl-C during the grace wait dropped the workload's error.python scripts\nvx.py test-microvm --backend whp --scenario sandbox-ram-upper --scenario sandbox-lifecycle --scenario guest-boot: passed.Backend, host OS, host type, and guest: WHP, Windows 11 Enterprise 10.0.26300, bare metal (a Lenovo 21DD workstation), with the Ubuntu layer and kernel of release
v0.1.0-dev.efe086d96205over a RAM upper.devat 6681c2envx.exe10 s intosandbox run --entrypoint /bin/sleep --arg 300sandbox run --timeout 15of a busy loop, with a debugger holding the exit of the real OpenVMMerror[still-running]: cannot confirm exit of VM process 14648; the directory stayserror[timed-out]: managed control response timed outanderror[still-running]: cannot confirm exit of VM process 5112: it is stuck exiting after its forced termination; the directory is removedsandbox run --timeout 5of a busy looptimed-out; nothing staysLeft to CI: the Linux builds and tests of
nvxand the KVM and MSHV microVM scenarios; the Linux and Windows test hosts were unreachable, as their SSH connections timed out, so Linux was checked here only by Clippy for the Linux target.Checklist
python3 scripts/check_test_layout.pychecks.python3 scripts/check_test_changes.py --base origin/devlists no changeto an existing test, or a Changes to existing tests section below
explains each one.
.github/copilot-instructions.mdand the skills when a convention orworkflow changes.
nvxupdatesnvx/public-api/withpython3 scripts/public_api.py --update.description says how the change versions or migrates them.