Skip to content

fix(hal/windows): fall back to PowerShell CIM when wmic is unavailable#84

Closed
rjckkkkk wants to merge 1 commit into
developfrom
feat/windows-hal-cim-fallback
Closed

fix(hal/windows): fall back to PowerShell CIM when wmic is unavailable#84
rjckkkkk wants to merge 1 commit into
developfrom
feat/windows-hal-cim-fallback

Conversation

@rjckkkkk

@rjckkkkk rjckkkkk commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

internal/hal/detect_windows.go detects CPU model, RAM, swap, and CPU load by shelling out to wmic. Recent Windows 11 builds no longer ship wmic, so every probe fails:

WARN wmic cpu detection failed: exec: "wmic": executable file not found in %PATH%
WARN wmic RAM detection failed:  exec: "wmic": ...
"cpu": { "model": "", "cores": 32 }     "ram": { "total_mib": 0 }

Result on a Ryzen AI Max+ 395 box: hardware detection (and the onboarding wizard's hardware step) shows no CPU name / no RAM / no VRAM.

Fix

Keep wmic as the primary probe (zero change on machines that have it); when it errors, fall back to powershell Get-CimInstance. Each CIM command emits the same unquoted header\ndata CSV the existing wmic parsers already consume, so the parsing code is unchanged:

Probe CIM source
CPU Win32_Processor → Name / NumberOfCores / NumberOfLogicalProcessors / MaxClockSpeed
RAM Win32_OperatingSystem → TotalVisibleMemorySize / FreePhysicalMemory
Swap Win32_PageFileUsage → AllocatedBaseSize
CPU load Win32_Processor.LoadPercentage

Also trims a possible UTF-8 BOM from PowerShell output before parsing, and trims fields defensively.

Tests

detect_windows_test.go (build-tagged windows): with the wmic command absent from the mock runner (→ ErrNotFound), detectCPU/detectRAM fall back to the CIM commands and populate model/cores/threads/freq and total/available/swap. Existing parseWMIC* CSV tests unchanged.

Verified on real Windows 11 hardware (cross-compiled go test -c, run on the box): all hal tests pass, and aima hal detect now reports the CPU model + 128 GiB RAM where it previously returned empty/zero.

Note: these tests can't run on non-Windows CI (//go:build windows); they were executed on a Windows 11 host.

Recent Windows 11 builds ship without wmic, so CPU model, RAM, swap and CPU load
all silently fell back to empty/zero (CPU model "", RAM 0) — e.g. on a Ryzen AI
Max+ 395 box, hardware detection and the onboarding wizard showed no hardware
info.

wmic stays the primary probe (no change where it exists); when it errors, fall
back to `powershell Get-CimInstance`, emitting the same unquoted header/data CSV
the existing parsers already consume:

- Win32_Processor       -> Name/NumberOfCores/NumberOfLogicalProcessors/MaxClockSpeed
- Win32_OperatingSystem -> TotalVisibleMemorySize/FreePhysicalMemory
- Win32_PageFileUsage   -> AllocatedBaseSize
- Win32_Processor.LoadPercentage

Also trims a possible UTF-8 BOM from PowerShell output before parsing.

Tests (run on real Windows): CPU and RAM fall back to CIM when the wmic command
is absent; existing wmic CSV parser tests unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rjckkkkk

rjckkkkk commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as a duplicate of #78, which already replaces wmic with PowerShell CIM for CPU/RAM/pagefile/load AND adds AMD GPU (Win32_VideoController) detection — a strict superset of this PR. I reimplemented the CIM CPU/RAM fix here without spotting #78 first; #78 is the more complete fix and should land instead.

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.

1 participant