Skip to content

tests: never reuse an adapter sandbox's name within a test process - #1462

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/check-related-issues-prs-nvx-ci
Nov 10, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/check-related-issues-prs-nvx-ci

Conversation

@ppenna

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

Copy link
Copy Markdown
Contributor

What and why

On Windows, Sandbox::new, which creates the directory of each VM test of the
runtime adapter, can panic with Access is denied. (os error 5) before its
test launches anything. It names each sandbox runtime-adapter-NAME-PID-N
after the first N that no directory takes, so tests that share a scenario
name reuse the names that the others free: vm_clone shares 15 names among
its 37 tests, such as cl-r, which 6 of them use. Windows keeps the name of a
directory that remove_dir_all is deleting until the deletion completes, and
until then refuses to create a directory under it with ERROR_ACCESS_DENIED,
not ERROR_ALREADY_EXISTS, which Sandbox::new takes for a failure.

On feature/nvx-refactor, whose sandbox names leave out the scenario's name
since 07d16d0 (#1432), every test of a binary shares them, and the race
failed the Windows/WHP runtime adapter job of run 42896649941. CI
hasn't hit it on dev: of the 9 Windows/WHP runtime adapter jobs that failed
in the last 14 days, only that one failed this way.
#1463 fixes feature/nvx-refactor the same way.

Each sandbox of a test process now takes N from a process-wide counter, so a
process never takes the name of a sandbox that it created, while a name that
another process left still counts as taken. The directory's format stays as
it is.

  • tests/runtime-adapter/tests/common/mod.rs: Sandbox::new takes N from
    NEXT_SANDBOX.
  • tests/runtime-adapter/tests/sandbox_names.rs: a new host-only test, which
    boots nothing, drops a sandbox and checks that the next one of the same name
    takes another name. Before the fix, both took
    runtime-adapter-names-16820-0.
  • tests/runtime-adapter/README.md: describes the new test.

On Linux, the absolute path of a template store must stay within 55 bytes for
its clones' sockets, generations/1/LAUNCH.sock, and within 56 for a
capture's. A test binary creates a few hundred sandboxes at most, so the
counter adds at most two digits: with a seven-digit PID below /tmp, the
longest template store grows from 48 to 49 bytes.

Validation

On Windows 11 (NTFS), without a hypervisor:

  • Reproduction, with a temporary test that this pull request doesn't add: 8
    threads that create and drop sandboxes named cl-r through common::Sandbox
    for 20 s. Before the fix, 55 of 12,470 creations failed with cannot create ...\runtime-adapter-cl-r-9668-1: Access is denied. (os error 5); after it,
    0 of 13,068.
  • cargo test --locked --features host --test sandbox_names, in
    tests/runtime-adapter: failed before the fix, passed after it.
  • python scripts/local_gates.py --base origin/dev --run --keep-going --only test-changes markdown-links test-layout nvx-rs-adapter-protocol nvx-rs-adapter-host: all 5 passed.
  • In tests/runtime-adapter, with Rust 1.95.0: cargo fmt --all --check;
    cargo clippy --locked --all-targets -- -D warnings, cargo build --locked, cargo test --locked, and RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps, each also with --features host; and cargo clippy
    and cargo doc with --features guest --target x86_64-unknown-linux-musl.
    With Rust 1.89, cargo check --locked --all-targets, also with --features host. All passed.
  • python -m unittest scripts.test_nvx_tools.RuntimeAdapterSuiteTests -v: 13
    passed.

Left to CI: the runtime adapter's VM scenarios on Windows/WHP, Linux/KVM, and
Linux/MSHV, which create their sandboxes through Sandbox::new; the
guest-only build, tests, and MSRV check on Linux; and the rest of the
nvx-rs and NVX CLI gates that local_gates.py selects, though this changes
neither nvx-rs/ nor scripts/.

python scripts/check_test_changes.py --base origin/dev lists one change to
an existing test: the Sandbox::new helper in
tests/runtime-adapter/tests/common/mod.rs. It still creates a directory of
its own for each sandbox, skips a name that exists, and panics on any other
error; only its choice of N changed, from the first number that no
directory takes to the next of the process's counter. No assertion, timeout,
or ignored test changed.

Sandbox::new names each sandbox runtime-adapter-NAME-PID-N after the
first N that no directory takes, so tests that share a scenario name,
such as the six of vm_clone that start clones named cl-r, take the
names that the others free. Windows keeps the name of a directory
that remove_dir_all deletes until the deletion completes, and until
then refuses to create a directory under it with ERROR_ACCESS_DENIED,
not ERROR_ALREADY_EXISTS, which Sandbox::new took for a failure: a
test that took a name while another was removing the sandbox of that
name panicked. On Windows, eight threads that create and remove
sandboxes of one name failed 55 of 12,470 creations so. On
feature/nvx-refactor, whose sandbox names leave out the scenario's
name, the race failed the Windows/WHP runtime adapter job of run
42896649941.

Number the sandboxes of a process from a counter instead, so that a
process never takes the name of a sandbox that it created, and skips
only the names that another process left. On Linux, the counter adds
at most two digits, and with a seven-digit PID the longest template
store below /tmp stays 6 bytes short of the 55 that its sockets
allow, one byte less than before.

The new sandbox_names test, which boots nothing, failed before the
change, with the second sandbox at the name of the first.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ppenna Pedro Henrique Penna (ppenna) added the tests-modified Changes existing tests, test data, or test wiring label Nov 10, 2026
Copilot AI balanced review requested due to automatic review settings November 10, 2026 22:26
@github-actions

Copy link
Copy Markdown
Contributor

This pull request changes existing tests

It modifies or removes 1 existing test asset(s), listed below. Review each with care: a change to a test can hide a regression that the test caught. See doc/contribute.md#changes-to-existing-tests.

Test code

Change What Before After
modified helper fn new in common/mod (tests), impl Sandbox`` tests/runtime-adapter/tests/common/mod.rs:152 tests/runtime-adapter/tests/common/mod.rs:157

Relocated unchanged: 0; added: 5. Compared the merge base 1c25bb4837d2 with d5abc5f9d3c2.

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 recorded for the change to prevent sandbox-name reuse within a test process.

No open issues 🎉

What changed in this PR

This PR prevents runtime-adapter tests from reusing sandbox directory names within a test process, avoiding Windows access-denied failures while a previously used directory is still being deleted.

Changes:

  • Allocate sandbox names using a process-wide atomic counter while preserving the name format and handling of existing directories.
  • Add a host-only regression test that verifies a dropped sandbox’s name is not reused.
  • Document the new regression test.
File Description
tests/​runtime-adapter/​tests/​sandbox_names.rs Adds a name-reuse regression test that requires no hypervisor.
tests/​runtime-adapter/​tests/​common/​mod.rs Uses an atomic counter to assign distinct sandbox names within each process.
tests/​runtime-adapter/​README.md Describes the new test and the Windows deletion race it guards against.

Review effort: Balanced

@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 10, 2026
Merged via the queue into dev with commit c3ff9d6 Nov 10, 2026
87 of 89 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/check-related-issues-prs-nvx-ci branch November 10, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests-modified Changes existing tests, test data, or test wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants