Skip to content

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 into
devfrom
agents/issue-1910-run-vmm-lifetime
Nov 24, 2026
Merged

Pedro Henrique Penna (ppenna) merged 3 commits into
devfrom
agents/issue-1910-run-vmm-lifetime

Conversation

@ppenna

@ppenna Pedro Henrique Penna (ppenna) commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 the openvmm gitlink of dev, so it has no OpenVMM pull request.

What does this pull request change?

On Windows, the one-shot runs, nvx sandbox run and a cold nvx run, now own their OpenVMM: the VM ends with the run, whatever ends nvx.exe. A sandbox run whose workload outlives --timeout forces its VM down as sandbox stop does, 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.

# Commit Change
1 nvx: end a one-shot run's OpenVMM with the run on Windows A foreground spawn, which only the CLI's one-shot runs make, also starts OpenVMM in an unnamed job object with JOB_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 of nvx that keep their processes' children. Windows closes the handle when nvx ends, 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.
2 sandbox: force a timed-out run's VM down as stop does After a workload that outlives --timeout, the run terminates OpenVMM in force_down, through force_exit, which sandbox stop now 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 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 says cannot confirm exit of VM process N: it is stuck exiting after its forced termination when its termination reached the process, which runs no code of its own any longer, so the run removes its VM directory then.
3 sandbox: remove the VM directories that terminated runs left On Windows, a run first removes the user's nvx-sandbox-run-* (or, for nvx run, nvx-run-*) directories that are private, hold only NVX's files, and whose openvmm.log no 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_job and spawn_listed in nvx/src/host/platform/windows/spawn.rs, then the stop phase of run and force_down in nvx/src/host/cli/sandbox/lifecycle/start.rs, and force_exit in stop.rs.

What it leaves out:

  • The cause of case 3 in Windows. Windows keeps a terminated process until its pending I/O completes or is canceled, as TerminateProcess documents, and the stuck processes of the issue are in that state: exit code set, no handles, not signaled, one thread in an Executive wait. OpenVMM's virtio-fs issues ordinary synchronous NT file I/O through lxutil (handles opened with FILE_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, nvx now 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.
  • Linux keeps its behavior: OpenVMM stays in the session and process group of nvx, which a terminal's signals reach, but a SIGKILL of nvx alone leaves it running, and no run removes its directory then. The issue concerns Windows.
  • A run terminated in the instant between creating its directory and its log leaves an empty directory, which a later run cannot tell from one that is being set up, so it leaves it.

Why is this change needed?

  • Case 1: the foreground OpenVMM of a one-shot run was in the jobs of nvx and 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 once nvx was 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 after nvx ended.
  • Case 2: after a timed-out workload, the run terminated OpenVMM, gave it a fixed 10 s, then failed with only 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.
  • The leftover directories: a terminated run cannot remove its own, so the next run must, and only once it knows that no run or OpenVMM still uses it. The check is the log's sharing, which needs no record; on Linux no such check tells a live run of an earlier version from an abandoned one, so the removal is Windows-only.

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, and nvx-msrv passed. nvx-cli ran 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.
  • After the rebase onto openvmm: pin the clearing of paravirtual kicks when a VP's activity is set #2098: 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-features with -D warnings, cargo +1.89 check --locked --all-targets --all-features, the unit tests of host::platform, host::vm, host::cli::sandbox, host::spawn, and host::process (181 passed), cargo test --locked --all-features --test cli (118 passed), check_test_layout.py, check_markdown_links.py, and check_test_changes.py: passed.
  • After the review fixes (Ctrl-C during the run's stop, and the report of a failed workload and of an unconfirmed exit after Ctrl-C): cargo fmt --all --check, the six Clippy invocations of check-nvx and the one for the Linux target, cargo doc with -D warnings, cargo +1.89 check, cargo test --locked --lib --no-default-features --no-run, the unit tests of host::cli::sandbox, host::vm, and host::platform (157 passed), cargo test --locked --all-features --test cli (119 passed), check_test_layout.py, check_markdown_links.py, and check_test_changes.py (no change to an existing test; 35 added): passed. The Linux CI run of an intermediate head failed interrupts::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 before Interrupted. 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.
  • The new tests fail at the base revision with the issue's symptoms and pass with the 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, and a_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_same raises a real Ctrl-C in a helper that runs in a console of its own, while force_down waits 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_openvmm runs sandbox run in 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, and Interrupted, with status 130. Without the fixes, the stuck-exiting error was missing, as at the base revision, where an interrupted run printed only Interrupted, 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.efe086d96205 over a RAM upper.

Case Command dev at 6681c2e This change
1 Kill nvx.exe 10 s into sandbox run --entrypoint /bin/sleep --arg 300 OpenVMM still runs 10 s later; its directory stays OpenVMM is gone; the next run removes the directory
2 sandbox run --timeout 15 of a busy loop, with a debugger holding the exit of the real OpenVMM Exit 1 after 30 s, with only error[still-running]: cannot confirm exit of VM process 14648; the directory stays Exit 1 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; the directory is removed
2 sandbox run --timeout 5 of a busy loop Exit 1 with timed-out; nothing stays Same

Left to CI: the Linux builds and tests of nvx and 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

  • Tests cover the new or fixed behavior, in the layout that
    python3 scripts/check_test_layout.py checks.
  • python3 scripts/check_test_changes.py --base origin/dev lists no change
    to an existing test, or a Changes to existing tests section below
    explains each one.
  • The documentation that the change affects is updated, including
    .github/copilot-instructions.md and the skills when a convention or
    workflow changes.
  • A change to the public API of nvx updates nvx/public-api/ with
    python3 scripts/public_api.py --update.
  • Snapshots, protocols, and on-disk formats stay compatible, or the
    description says how the change versions or migrates them.

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>

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.

🟡 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

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.

🟡 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

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.

🟡 Changes recommended

Ctrl-C during the guest-shutdown grace wait can still overwrite an existing workload failure with Exit::Interrupted, losing the original error.

1 open issue
1 resolved since last review

Review effort: Balanced

Base automatically changed from agents/issue-1386-kvm-pv-kick to dev November 24, 2026 15:34
@ppenna
Pedro Henrique Penna (ppenna) force-pushed the agents/issue-1910-run-vmm-lifetime branch from b726fae to a1ada00 Compare November 24, 2026 15:44
Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:44

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.

🟢 Approval recommended

No active review issues are reported for the Windows process-lifecycle and abandoned-directory cleanup changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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>
@ppenna
Pedro Henrique Penna (ppenna) force-pushed the agents/issue-1910-run-vmm-lifetime branch from a1ada00 to b3c31a9 Compare November 24, 2026 16:06
Copilot AI balanced review requested due to automatic review settings November 24, 2026 16:06

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.

🟢 Approval recommended

No active review issues require further changes.

No open issues 🎉

Review effort: Balanced

@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 24, 2026
Merged via the queue into dev with commit fa6d154 Nov 24, 2026
58 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/issue-1910-run-vmm-lifetime branch November 24, 2026 16:41
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.

nvx: on Windows/WHP, a killed or timed-out sandbox run leaves OpenVMM running, and an OpenVMM killed during virtio-fs I/O can stay stuck until reboot

2 participants