Skip to content

nvx: name the NVXC frame header layout - #2327

Merged
Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-2326-nvxc-header-layout
Nov 28, 2026
Merged

Pedro Henrique Penna (ppenna) merged 1 commit into
devfrom
agents/issue-2326-nvxc-header-layout

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Fixes #2326

What does this pull request change?

Frame::encode in nvx/src/protocol/app/v2.rs laid out the 24-byte NVXC frame header by the order of its extend_from_slice calls, and Frame::decode read the fields back at raw offsets (header[..4], [4], [5], [6..8], [8..16], [16..20], [20..24]).

This change names the fields in a private field module, as protocol/outer.rs does for the outer record header: MAGIC, VERSION, KIND, FLAGS, REQUEST_ID, STATUS and LENGTH, the last ending at APP_HEADER_LEN. Compile-time assertions check that the fields tile the header in order and that each range is as wide as its field's type. The encoder sizes the header, then writes each field at its range; the decoder reads each field from it.

Start at the field module in v2.rs. Left out: the fake OpenVMM and the tests still index frames by raw offsets (frame[5], frame[24..]). The issue records that as a follow-up.

Why is this change needed?

Before this change, only the module documentation described the layout, and nothing tied the decoder's offsets to the encoder's order or to APP_HEADER_LEN. Now the layout is stated once and checked at compile time. The positions and widths are unchanged, so every frame encodes to the same bytes, and the decoder accepts and refuses the same inputs with the same messages, in the same order.

How was this change validated?

Checks and results:

  • Baseline at ebaffcb22a8: cargo test --locked --all-features --lib protocol:: (Windows) passed, 109 tests; with the change it also passed, 109 tests.
  • python scripts\local_gates.py --base origin/dev --run on Windows 11 passed every gate: test-changes, markdown-links, test-layout, nvx-format, nvx-lint, nvx-test, nvx-doc, nvx-msrv, nvx-cli.
  • python3 scripts/local_gates.py --base origin/dev --run in a WSL (Linux) clone of the commit 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 and nvx-guest-binaries-build.
    • Its nvx-cli gate first failed in the gate's own pip install, because Debian's system Python refuses it (PEP 668).
    • --only nvx-cli --run from a virtual environment then passed.
  • python3 scripts/check_test_changes.py --base origin/dev: 0 changes to existing tests.

Backend, host OS, host type, and guest: none. The change is a pure codec refactor that preserves the bytes on the wire, so I ran no microVM. Every configured KVM and WHP host was unreachable.

Left to CI: the microVM scenarios on KVM, MSHV and WHP, 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.

Frame::encode laid out the 24-byte NVXC header by the order of its
extend_from_slice calls, and Frame::decode read the same fields back
at raw offsets: header[..4], [4], [5], [6..8], [8..16], [16..20] and
[20..24]. Only the module documentation gave the layout, and nothing
tied the decoder's offsets to the encoder's order or to
APP_HEADER_LEN.

Name the fields in a private field module, as the outer record header
does: MAGIC, VERSION, KIND, FLAGS, REQUEST_ID, STATUS and LENGTH, the
last ending at APP_HEADER_LEN. Compile-time assertions check that the
fields tile the header in order and that each range is as wide as its
field's type. The encoder writes each field at its range, and the
decoder reads each one from it.

The positions and widths are the ones that the code used, so every
frame encodes to the same bytes, and the decoder accepts and refuses
the same inputs with the same messages. The tests of
protocol::app::v2, whose wire helper builds the header independently,
pass unchanged: cargo test --locked --all-features --lib protocol::
gave 109 passed at ebaffcb and with the change, on Windows.

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

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 NVXC v2 frame-header layout refactor.

No open issues 🎉

What changed in this PR

This PR centralizes the NVXC version 2 frame-header layout, following the existing outer-record header pattern while preserving wire bytes and decoding behavior.

Changes:

  • Adds private field definitions and compile-time checks for field widths and complete header coverage.
  • Updates encoding and decoding to use the shared layout instead of implicit write order and raw offsets.
File Description
nvx/​src/​protocol/​app/​v2.rs Defines and validates the header layout, then uses it in the frame codec.

Review effort: Balanced

@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 28, 2026
Merged via the queue into dev with commit eb80a71 Nov 28, 2026
56 checks passed
@ppenna
Pedro Henrique Penna (ppenna) deleted the agents/issue-2326-nvxc-header-layout branch November 28, 2026 17:22
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 NVXC frame header layout

2 participants