Skip to content

1.8: fix(ohcldiag-dev): treat GUID-shaped VM args as names, not IDs (#4042) - #4061

Merged
moor-coding merged 1 commit into
microsoft:release/1.8.2607from
moor-coding:backport/1.8.2607/ohcldiag-dev-vm-name-parsing
Jul 30, 2026
Merged

1.8: fix(ohcldiag-dev): treat GUID-shaped VM args as names, not IDs (#4042)#4061
moor-coding merged 1 commit into
microsoft:release/1.8.2607from
moor-coding:backport/1.8.2607/ohcldiag-dev-vm-name-parsing

Conversation

@moor-coding

Copy link
Copy Markdown
Contributor

Backport of #4042 to release/1.8.2607.

Why this is needed for 1.8

This regression (introduced by #3753, which is present on release/1.8.2607) breaks all ohcldiag-dev interactions against fleet VMs — it is currently blocking Underhill 1.8 memory validation on TiP.

Problem

#3753 changed VmId::from_str to try parse::<guid::Guid>() first for bare and hyperv:-prefixed arguments, treating any successful parse as a VM ID. In the fleet, Hyper-V VM names are themselves GUID-shaped, so a name is misinterpreted as a VM ID and used directly as the AF_HYPERV connect address — instead of being resolved to the real VM ID via hvc.exe id <name>. The bogus address produces:

Error: failed to connect
Caused by:
    0: failed to connect
    1: The requested address is not valid in its context. (os error 10049)   // WSAEADDRNOTAVAIL

Fix

Make ID-vs-name resolution deterministic instead of inferring intent from the string's shape:

  • hyperv-id:GUID → VM ID (new, explicit prefix — the only way to look up by ID)
  • hyperv:NAMEname (even if GUID-shaped)
  • bare value → name (unless it is a unix socket path → hybrid vsock)
  • vsock:PATH → hybrid vsock (unchanged)

Also change FromStr::Err from Infallible to ParseVmIdError so an explicit hyperv-id: with an invalid GUID reports a clear parse error.

Behavior change

Callers relying on a bare GUID being interpreted as a VM ID (introduced in #3753) must now use the hyperv-id: prefix.

Testing

  • Clean cherry-pick of the main fix (no conflicts).
  • Added Windows-gated unit tests for VmId::from_str covering each parse path.
  • cargo check (Linux) + cargo clippy --all-targets / cargo doc --no-deps (x86_64-pc-windows-msvc) clean against the 1.8 toolchain (1.95.0).

Depends on #4042 (original merge to main).

Commit b4ad915 made `VmId::from_str` try to parse bare and
`hyperv:`-prefixed arguments as a GUID first, treating a successful
parse as a VM ID. In the fleet, Hyper-V VM names are themselves
GUID-shaped, so a name was misinterpreted as a VM ID and used directly
as the AF_HYPERV connect address instead of being resolved via
`hvc.exe id <name>`. The bogus address produced `WSAEADDRNOTAVAIL`
(os error 10049), breaking all ohcldiag-dev interactions on TiP.

Make ID-vs-name resolution deterministic instead of shape-based:

- `hyperv-id:GUID` -> VM ID (new, explicit; the only way to look up by ID)
- `hyperv:NAME`    -> name (even if GUID-shaped)
- bare value      -> name (unless it is a unix socket path -> vsock)

Also change `FromStr::Err` from `Infallible` to `ParseVmIdError` so an
explicit `hyperv-id:` with an invalid GUID reports a clear parse error
rather than silently falling through to a name lookup.

Behavior change: callers relying on a bare GUID being interpreted as a
VM ID (introduced in microsoft#3753) must now use the `hyperv-id:` prefix.
Copilot AI review requested due to automatic review settings July 28, 2026 18:52
@moor-coding
moor-coding requested a review from a team as a code owner July 28, 2026 18:52
@github-actions github-actions Bot added the release_1.8.2607 Targets the release/1.8.2607 branch. label Jul 28, 2026

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.

Pull request overview

This PR backports the ohcldiag-dev VM-argument parsing fix to release/1.8.2607, making Hyper-V VM lookup deterministic so GUID-shaped fleet VM names are no longer misinterpreted as VM IDs (the regression introduced by attempting GUID parsing first).

Changes:

  • Introduces an explicit hyperv-id:GUID prefix to opt into direct Hyper-V VM-ID addressing; hyperv: and bare values are treated as VM names (even if GUID-shaped).
  • Updates VmId::FromStr to emit a concrete parse error (ParseVmIdError) for invalid hyperv-id: GUIDs.
  • Adds Windows-gated unit tests covering the intended parse behaviors.
Comments suppressed due to low confidence (1)

openhcl/ohcldiag-dev/src/main.rs:390

  • ParseVmIdError currently has all variants gated with #[cfg(windows)], so on non-Windows it becomes an empty enum while still deriving thiserror::Error. Gating the whole type to Windows (and removing the per-variant cfg) avoids the empty-enum edge case and makes the cfg intent explicit.
/// Error parsing a [`VmId`].
#[derive(Debug, Error)]
enum ParseVmIdError {
    #[cfg(windows)]
    #[error("invalid VM ID GUID '{0}' (expected a GUID, with or without braces)")]


impl FromStr for VmId {
type Err = Infallible;
type Err = ParseVmIdError;
Comment on lines +1171 to +1174
#[test]
fn hyperv_id_prefix_with_invalid_guid_errors() {
assert!("hyperv-id:not-a-guid".parse::<VmId>().is_err());
}
@moor-coding
moor-coding merged commit 2800f1f into microsoft:release/1.8.2607 Jul 30, 2026
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_1.8.2607 Targets the release/1.8.2607 branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants