Skip to content

nvx: build the EXEC payload's truncation error and length-prefixed strings with one helper each - #2347

Queued
Pedro Henrique Penna (ppenna) wants to merge 1 commit into
devfrom
agents/issue-2346-exec-shared-helpers
Queued

Pedro Henrique Penna (ppenna) wants to merge 1 commit into
devfrom
agents/issue-2346-exec-shared-helpers

Conversation

@ppenna

Copy link
Copy Markdown
Contributor

Fixes #2346

What does this pull request change?

A behavior-preserving cleanup of the EXEC payload codec in nvx/src/protocol/exec.rs. Start reading at encode_exec_payload.

  • The encoder writes each length-prefixed string (arguments and environment entries) through a new push_prefixed helper. Before, it repeated the same three lines in both loops. The helper keeps the u32::try_from(..).unwrap_or(u32::MAX) saturation, so the encoded bytes are identical.
  • decode_exec_header drops its local truncated closure and calls the module's truncated() function. All six truncation sites now build one error, with the same message as before (the pattern protocol/maps.rs already uses).
  • New unit tests in nvx/src/protocol/exec/tests.rs check that push_prefixed round-trips through prefixed_string, and that a string cut short reports the truncation error.

Error messages, wire format, and public API are unchanged. Validating arguments before writing them is left out on purpose, because it would change behavior; the issue records it as a follow-up.

Why is this change needed?

The truncation error was built in two ways, and the prefixed-string write was duplicated. Any future change to either could drift between copies. One helper each keeps the encoder and decoder consistent. I rejected moving the decoder to a separate module: it would touch far more lines for little gain.

How was this change validated?

Checks and results:

  • Baseline at 895d8f9: cargo test --locked --all-features --lib protocol:: (in nvx/): 109 passed. After the change: 111 passed (109 plus the 2 new tests).
  • Windows 11 (native): python scripts\local_gates.py --base origin/dev --run. All selected gates passed: test-changes, markdown-links, test-layout, nvx-format, nvx-lint, nvx-test, nvx-doc, nvx-msrv, nvx-cli (with NVX set to a release build).
    • A first run failed nvx-test, nvx-doc, and nvx-msrv with LNK1318 and "not enough space on the disk". After cargo clean freed space, those gates were rerun with --only and passed.
  • Linux, WSL2 Ubuntu (local fallback, since no configured KVM host was reachable): python3 scripts/local_gates.py --base origin/dev --run. All gates 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.
    • The Linux lint gate builds the guest decoder, which compiles only on Linux x86_64 with guest.
    • The first nvx-cli run failed at its pip install (PEP 668, externally managed Python). In a venv with NVX set to a release build, it passed: 2326 tests OK (41 skipped) and 84 OK.

Backend, host OS, host type, and guest: none. This is a host-side codec refactor, and I ran no microVM.
Left to CI: the microVM scenarios on KVM, MSHV, and WHP, and 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.

…rings with one helper each

The EXEC codec spelled the error of a payload that ends early,
"the exec request is truncated", at six sites: a local closure in
decode_exec_header and inline literals in decode_exec,
prefixed_string, and bytes_at. Its encoder also wrote each argument
and environment entry with the same three lines, a u32 length and the
bytes, which the decoder already reads through one prefixed_string.

Name the error once in a module-level truncated(), as the MAPS codec
does, and write the length-prefixed strings with push_prefixed(), the
encoder's counterpart of prefixed_string. The message, its
ProtocolError, the encoded bytes (including the saturating u32
conversion that the MAX_ARGUMENT_BYTES checks before it never reach),
the order of the checks, and every cfg stay the same; no public item
changes.

The protocol tests pass unchanged at the base revision, 895d8f9
(109 passed, cargo test --all-features --lib protocol:: on Windows).
New unit tests in protocol/exec/tests.rs read pushed strings back
through prefixed_string, the longest included, and check that every
shorter cut of one reads as the shared truncation error.

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

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 EXEC payload codec refactor.

No open issues 🎉

What changed in this PR

This PR addresses #2346 by consolidating repeated logic in the EXEC payload codec without changing the wire format, error messages, or public API.

Changes:

  • Adds push_prefixed to encode arguments and environment entries through one helper.
  • Uses a shared truncated() function for decoder truncation errors.
  • Adds unit tests for length-prefixed string round-trips and truncated payloads.
File Description
nvx/​src/​protocol/​exec/​tests.rs Adds round-trip and truncation tests for the string helpers.
nvx/​src/​protocol/​exec.rs Extracts the string-writing helper and centralizes truncation-error construction.

Review effort: Balanced

@ppenna
Pedro Henrique Penna (ppenna) added this pull request to the merge queue Nov 28, 2026
Any commits made after this event will not be merged.

This branch has not been deployed

No deployments
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: build the EXEC payload's truncation error and length-prefixed strings with one helper each

2 participants