Skip to content

nvx: name the timing bounds of the run command's foreground - #2233

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-2232-run-foreground-timing
Nov 27, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-2232-run-foreground-timing

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Fixes #2232

What does this pull request change?

It replaces the inline timing literals and buffer sizes in the foreground of a cold nvx run (nvx/src/host/cli/run.rs) with named private constants. Each constant's doc comment states the limit it sets:

  • FOREGROUND_POLL (10 ms) and CONSOLE_ATTEMPT_TIMEOUT (250 ms, used everywhere except Linux)
  • CONSOLE_TIMEOUT (60 s) and PEER_EXIT_WAIT (250 ms)
  • ATTACH_TIMEOUT (60 s, applied to each attachment phase) and ATTACH_CLOSED_GRACE (60 s)
  • ATTACH_FAILURE_DRAIN (250 ms) and STOP_GRACE (250 ms)
  • TRANSFER_BUFFER_LEN (8192)

The stop deadline now uses the existing KILL_TIMEOUT (10 s), which every other vm::stop caller already passes.

Each constant keeps its literal's value and type, so behavior does not change. The managed attachment's 60.0 is now ATTACH_TIMEOUT.as_secs_f64(), which is exactly 60.0. Review can start at the constant block after RUN_DIRECTORY.

This change leaves out Session::connect_launched_cancellable and Session::stop, which still take f64 seconds instead of a Duration. Changing them is a possible follow-up.

Why is this change needed?

Several bounds share a value: 250 ms is used for four different bounds and 60 s for three. A reader could not tell which bound a literal set, and a change to one could miss its siblings or change an unrelated bound that happened to share the value.

How was this change validated?

Checks and results:

  • Baseline at 2e302197d90 and at the head: cargo test --locked --all-features --lib -- host::cli::run host::cli::session in nvx/: 56 passed, 2 ignored, at both.
  • Windows: python scripts/local_gates.py --base origin/dev --run passed: test-changes, markdown-links, test-layout, nvx-format, nvx-lint, nvx-test, nvx-doc, nvx-msrv, nvx-cli.
  • Windows, with NVX set to a release build (cargo build --release --locked --features cli --manifest-path nvx/Cargo.toml): python -m unittest scripts.test_nvx_wrapper passed, 21 tests run and none skipped. The nvx-cli gate had skipped these tests because NVX was unset.
  • Linux (WSL): python3 scripts/local_gates.py --base origin/dev --run passed: test-changes, markdown-links, test-layout, nvx-format, nvx-lint, nvx-test, nvx-doc, nvx-public-api, nvx-msrv, nvx-macos, nvx-guest-binaries-lint, nvx-guest-binaries-build. nvx-cli passed on a rerun with --only nvx-cli, in a virtual environment and with NVX set. The first attempt failed only because PEP 668 blocked pip from installing into the system Python.
  • WHP: python scripts/nvx.py test-microvm --backend whp --scenario console-exit, lifecycle, and managed-lifecycle passed, using the release artifacts from nvx download, since the OpenVMM pin is unchanged.
  • python3 scripts/check_test_changes.py --base origin/dev: 0 changes to existing tests.

Backend, host OS, host type, and guest:

  • WHP: Windows local workstation, with the default guest.
  • Linux gates: WSL. It stood in for the configured KVM hosts, none of which were reachable.

Left to CI:

  • The KVM microVM scenarios. WSL's nested KVM rejects the built-in intel.alderlake.v1 CPU profile (E_PROFILE_UNSUPPORTED).
  • The MSHV scenarios, since no MSHV host was available.
  • The remaining selected scenarios on every backend, and the benchmarks.

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.

The foreground of a cold `nvx run` timed its waits with inline
literals whose purpose its code did not state: a 10 ms idle poll five
times, 250 ms for four different bounds, 60 s for three, a 10 s stop
deadline, and an 8192-byte read buffer twice. A reader could not tell
which bound a value set, and a change to one could miss its siblings
or change an unrelated bound of the same value.

Name each bound once, with a private constant in `run.rs` whose doc
comment states the limit it bounds, and pass the existing
`KILL_TIMEOUT`, which every other `vm::stop` caller already passes,
for the stop deadline. Every constant keeps its literal's value and
type; the managed attachment's `60.0` seconds is now
`ATTACH_TIMEOUT.as_secs_f64()`, which is exactly 60.0.

Tests: the `host::cli::run` and `host::cli::session` unit tests pass
unchanged, as at the base revision 2e30219 (56 passed, 2 ignored
on Windows).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 00:39

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 remain for the refactor that makes foreground run timing limits and buffer sizes explicit.

No open issues 🎉

What changed in this PR

This refactors the cold nvx run foreground path to make timing limits and buffer sizes explicit, addressing #2232 while preserving existing values and behavior.

Changes:

  • Adds documented private constants for polling, console connections, managed attachment, shutdown grace periods, and transfer buffers.
  • Reuses the existing KILL_TIMEOUT for the stop deadline, leaving session timeout APIs unchanged.
File Description
nvx/​src/​host/​cli/​run.rs Replaces inline timing and buffer literals with named constants and the shared stop timeout.

Review effort: Balanced

@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 27, 2026
Merged via the queue into dev with commit 3fe14b7 Nov 27, 2026
56 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/issue-2232-run-foreground-timing branch November 27, 2026 06:18
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: name the timing bounds of the run command's foreground

2 participants