Repository navigation
[DO NOT REVIEW] state_unit: handle a unit in a terminal state instead of panicking - #5012
Merged
Pedro Henrique Penna (ppenna) merged 2 commits intoNov 10, 2026
Conversation
A unit whose task does not answer its start request is left in the terminal StartUncertain state, which only a later start refused. Any other state change that reached such a unit panicked the VM worker on run_op's state assertion: a stop of a running set, as after a failed hot-add, with "unit ... in StartUncertain state, should be Running or Stopped", and a reset, save, restore, or time advance after a failed start with "should be Stopped or Stopped". So a lifecycle request that followed a failed start, such as a reset after a failed resume or after a failed rollback of a microVM snapshot capture, took the process down (microsoft/nvx#1148). Those requests now handle the terminal state, as the later revisions of #4872, which proposes this chain's start rollback, do: - A reset, save, restore, or time advance fails, naming each unit in a terminal state, before it sends any unit a request. It checks this before it checks that the units are stopped, so that it fails rather than panics even while such a unit keeps the units running. - A stop also stops the units whose start is uncertain, since they may be running, in the same reverse dependency order as the others, and leaves them in their terminal state, so that a later start still fails. A unit whose task has exited still panics the stop that it does not answer, as any unit's does; microsoft/nvx#1363 tracks that. Tests: a stop of a running set stops a unit whose start is uncertain before the unit that it depends on, and the unit stays terminal; after a start that leaves a unit terminal, and while such a unit keeps the units running, a reset, save, restore, and time advance each fail, naming only that unit, without sending any unit a request. Without the change, the stop and the first reset panic on the state assertion, and the reset of a running set on its running assertion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A worker restart stops the state units of a running VM before it saves the VM, and starts them again when the save fails. When that start failed too, the worker reported the failure and kept serving the VM, which it still marked running although its state units were stopped, or left in a terminal state by the failed start. The next pause, reset, or pulse save and restore then stopped units that did not run, and so did the worker's teardown, and each panicked on the running assertion of StateUnits::stop (microsoft/nvx#1148). The worker now tears the VM down after such a restart, as the later revisions of #4872 do, since the VM cannot resume. Its teardown stops the state units when they run, rather than when the VM is marked running, so that it does not stop them again. The microVM profile refuses worker restarts, so no NVX microVM reaches this path. No test covers it: no harness of the worker can fail a unit's start after a failed save in a running worker. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
requested a review
from a team
as a code owner
November 10, 2026 10:29
Pedro Henrique Penna (ppenna)
merged commit Nov 10, 2026
6ddd6ca
into
feature/microvm/dev
73 of 74 checks passed
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 11, 2026
A state unit whose task does not answer its start request is left in a terminal state, which only a later start refused. A later stop, reset, save, restore, or time advance that reached such a unit panicked the VM worker on a state assertion, and a worker restart whose recovery start failed left the VM marked running over stopped units, so that the next pause, or the worker's teardown, panicked (microsoft#1148). Pin 6ddd6ca505a7212d92e2a8e561a19635f7185d4a, the head of microsoft/openvmm#5012, two commits on 4c2697aef, the head of feature/microvm/dev: - 78e752de1 state_unit: handle a unit in a terminal state instead of panicking - 6ddd6ca50 openvmm_core: tear the VM down when a restart cannot resume it A reset, save, restore, or time advance now fails, naming each unit in a terminal state, before it sends a request or checks that the units are stopped, and a stop also stops such a unit, which may be running, and leaves it terminal, as microsoft/openvmm#4872's later revisions do. A restart whose recovery start fails tears the VM down, and the teardown stops the state units when they run. Evidence: with the revision's three new state_unit tests alone on 4c2697aef, 3 of the 20 state_unit tests fail on nvx-kvm-test and nvx-mshv-test (Linux virtual machines), as they did on 46bfe02ed there and on Windows: a stop and a reset panic on the state assertion, and a reset of a running set on the running assertion. At the pinned revision, the state_unit and openvmm_core tests pass, 148 on Windows and on both Linux hosts, with clippy and rustdoc clean. No NVX microVM reaches these panics: a unit's task cannot end without aborting OpenVMM, and the microVM profile refuses worker restarts and has no hot-add. NVX's lifecycle, managed-lifecycle, sandbox-lifecycle, snapshot-core, and snapshot-rollback scenarios pass with OpenVMM built from the revision on nvx-kvm-test (KVM), nvx-mshv-test (MSHV), and nvx-whp-test (WHP). NVX needs no coordinated change: the control-session vectors, the source excerpts, the contract versions, and the CPU profiles that nvx-rs copies from OpenVMM match the revision's, as the openvmm_vectors and openvmm_cpu_profiles comparisons show. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 11, 2026
Map positions 241 and 242, 78e752de1 and 6ddd6ca50, which microsoft/openvmm#5012 proposes for feature/microvm/dev on its head, position 240, 4c2697aef, which microsoft/openvmm#5010 merged, and move NVX's pin to position 242, 111 commits past the mapped tip. Position 241 has a stop of the state units also stop a unit in the terminal state in which PR09's position 015 leaves a unit whose task does not answer its start, and has a reset, save, restore, or time advance fail while a unit is in that state, which only a later start refused. Position 242 has the VM worker tear the VM down when the start again of a failed restart, which position 015 adds, fails, and has its teardown stop the state units when they run. Both are therefore PR09 fixups, recorded as the PR12 fixup at v5.1 position 221 was: the DAG gives them a fixup step, PR09's summary row, graph node, and mapping count them, and the fold sentence after the DAG sends them into position 015, and position 241's check of a time advance, with its test, into PR10's position 019, which adds the time advance. Replaying them on upstream main, ba105dd7f, conflicts in four of their five files, all but the new test file, since upstream main lacks the start rollback of position 015 and the time advance of position 019, so they follow PR09 upstream; microsoft/openvmm#4872's head makes the same changes in its form of position 015. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
syeedali
pushed a commit
to syeedali/nvx
that referenced
this pull request
Nov 11, 2026
Map positions 243-245, 2fcd1573d, 5a750a862, and a8a0e3517, which microsoft/openvmm#5013 proposes for feature/microvm/dev on its head, position 242, 6ddd6ca50, which microsoft/openvmm#5012 merged with position 241, and move NVX's pin to position 245, 114 commits past the mapped tip. Position 243 has the rollback of a partial start, which PR09's position 015 adds, stop the units that started again in reverse dependency order, without panicking on a unit whose task does not answer, as microsoft/openvmm#4872's head does. It is therefore a PR09 fixup, recorded as positions 241 and 242 are: the DAG's PR09 fixup step, PR09's summary row, graph node, and mapping count it, and the fold sentence after the DAG sends it into position 015, and its description of the snapshot rollback into PR17's position 072. Positions 244 and 245 have a stop, and a reset, save, restore, or time advance, fail instead of panicking when a unit does not answer, which no mapped commit adds, so they stay unassigned, with remarks on the chain commits whose callers they change. microsoft/openvmm#4937 proposes position 244's change for upstream's code, so the paragraph on it no longer says that it proposes no chain commit. Replaying them on upstream main, ba105dd7f, conflicts in all three files of position 243, 12 of the 20 of position 244, and two of the three of position 245, since upstream main lacks the start rollback of position 015 and the other chain commits that they build on. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Keeps a later lifecycle request from panicking on a state unit in a terminal state, for microsoft/nvx#1148. A unit whose task does not answer its start request is left in the terminal
StartUncertainstate, which only a later start refused: a later stop, reset, save, restore, or time advance that reached such a unit panicked the VM worker onrun_op's state assertion, and a worker restart whose recovery start failed kept serving a VM that it marked running over stopped units, so that its next pause, or its teardown, panicked onStateUnits::stop's running assertion.Two commits on
4c2697aef, the head offeature/microvm/dev. microsoft/nvx#1435 pins this head.Handle a unit in a terminal state instead of panicking (
78e752de1)StartUncertainstate, andStateUnits::startrefuses a set that holds one. The other state changes still assumed that every unit wasStoppedorRunning:run_opasserts that a unit that is not in the operation's old state is already in its new state. So a stop of a running set that holds such a unit, as after a hot-add whose start is uncertain, panicked with "unit ... in StartUncertain state, should be Running or Stopped", and a reset, save, restore, or time advance after a failed start with "should be Stopped or Stopped".reset,save,restore, andadvance_timefail with aStateTransitionErrorthat names each unit in a terminal state, before they send any unit a request (check_no_terminal_units). Unlike state_unit: roll back a partial start instead of panicking #4872, they check this before they check that the units are stopped, so that they fail rather than panic even while such a unit keeps the units running, as a later partial-start rollback that keeps a possibly running unit's dependencies running would.stopalso stops the units whose start is uncertain, since they may be running, in the same reverse dependency order as the others, and leaves them inStartUncertain, so that a later start still fails.run_op'sUnitRecvError), as any unit's does; openvmm: stop, save, reset or restore panics if a state unit's task has exited nvx#1363 makes that an error. state_unit: roll back a partial start instead of panicking #4872's other later changes, which keep the units running after an uncertain start, block the rollback's stop of a dependency of a unit that was not stopped, and addstop_for_teardown, are not part of this pull request.vmm_core/state_unit/src/tests/terminal.rs,a_stop_stops_a_unit_whose_start_is_uncertainadds a unit to a running set, as a hot-add does, that depends on a running unit and whose task starts it but drops its start request unanswered, and requires a stop to stop it before its dependency and to leave it terminal.requests_fail_after_a_start_leaves_a_terminal_unitandrequests_fail_while_a_terminal_unit_keeps_the_set_runningrequire a reset, a save, a restore, and a time advance each to fail, naming only that unit, without sending any unit a request, after a start that leaves a unit terminal, and while such a unit keeps the units running. Without the change, the stop and the first reset panic on the state assertion, and the reset of a running set on its running assertion.Tear the VM down when a restart cannot resume it (
6ddd6ca50)StateUnits::stop.StateUnits::is_running), rather than when the VM is marked running.Validation
At this head,
6ddd6ca50, with Rust 1.97.1. It is46545c262on46bfe02ed, which NVX's first validation tested, rebased onto4c2697aef;git range-diffshows both patches identical, and the commits from46bfe02edto4c2697aefchange none of their files.cargo clippy --all-targets -p state_unit -p openvmm_core -- -D warningsandcargo doc --no-depsfor both withRUSTDOCFLAGS=-D warnings, without warnings;cargo nextest run --profile agent -p state_unit -p openvmm_core, 148 passed;cargo xtask fmt --fix, clean.4c2697aeffail, as described above, on both Linux VMs, as they did on46bfe02edthere and on Windows.46545c262. No NVX microVM reaches the panics that this fixes.Land by fast-forwarding
feature/microvm/devto this head,6ddd6ca505a7212d92e2a8e561a19635f7185d4a, since this repository's merge button squashes and would leave NVX's pin off the branch.