[PR #5185] [Other] Control: host_platform() asks no WMI on Windows, so a stuck winmgmt cannot hang it (Fix #4975) #5337

Open
opened 2026-11-07 16:34:27 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5185
Author: @XiaoBinGan
Created: 11/4/2026
Status: 🔄 Open

Base: main ← Head: reserve/fix-host-platform-wmi


📝 Commits (1)

  • aa14ef9 [Other] Control: host_platform() asks no WMI on Windows, so a stuck winmgmt cannot hang it (#4975)

📊 Changes

3 files changed (+90 additions, -4 deletions)

View changed files

📝 strata_control/targets.py (+25 -3)
➕ tests/terminal/test_host_platform.py (+58 -0)
📝 tests/terminal/test_linux_aarch64.py (+7 -1)

📄 Description

Problem and result

On Windows, strata_control/targets.py:host_platform() asked the OS through platform.system() and
platform.machine(). Both are platform.uname() on Windows, and on the bundled Python 3.12 uname() calls
win32_ver() → platform._wmi_query(): a WMI query with no timeout. When the Windows Management
Instrumentation service (winmgmt) is stuck, every Control command that resolves an engine component hangs for as
long as WMI does — the report shows the app's «Strata Control did not answer within 60 s (models list)», no supported
GPU and nothing loadable, while nvidia-smi answers in 0.08 s.

After the change the OS and architecture are answered without WMI:

return "Windows" if sys.platform.startswith("win") else platform.system()
...
if sys.platform.startswith("win"):
    return os.environ.get("PROCESSOR_ARCHITEW6432") or os.environ.get("PROCESSOR_ARCHITECTURE") or ""
return platform.machine()

sys.platform is set by the interpreter, and PROCESSOR_ARCHITEW6432 / PROCESSOR_ARCHITECTURE are exactly the
variables platform.uname() itself reads on Windows (platform._get_machine_win32()), so the answers are unchanged:
windows-x86_64 (AMD64), windows-arm64 (ARM64).

#4975 — the report, with the faulthandler stack inside platform._wmi_query and the note that the same code is on
main (strata_control/targets.py:33, :36). No separate scope agreement was asked for: a stuck WMI taking the app
down is the bug, and the reporter suggests the same fix (use sys.platform / the PROCESSOR_* variables instead of
platform.uname()).

Approach

  • _system_name(): on Windows the name is "Windows" without asking platform; every other system keeps
    platform.system() (that asks the kernel there, not a service).
  • _machine_name(): on Windows it reads PROCESSOR_ARCHITEW6432 then PROCESSOR_ARCHITECTURE (the same two
    variables CPython's platform.uname() reads on Windows, PROCESSOR_ARCHITEW6432 first because a 32-bit process
    masks the native architecture); every other system keeps platform.machine().
  • host_platform() maps the two names exactly as before, so no returned os-arch key changes.
  • The one existing test that simulated another OS by patching platform.system/platform.machine
    (tests/terminal/test_linux_aarch64.py::host()) now also stubs sys.platform and the architecture variable for its
    Windows row, because that is the source the Windows path reads.

Validation

Passed: the regression test — new file tests/terminal/test_host_platform.py (4 tests, 12 subtests). It makes
every platform call the old Windows path made fail with AssertionError("WMI is stuck") (a real hang cannot be
produced from a test) and asserts the answers still come back:

$ python -m pytest tests/terminal/test_host_platform.py tests/terminal/test_linux_aarch64.py -q
19 passed

Passed: the surrounding Control tests, on this checkout (Windows 11, Python 3.11.16):

$ python -m pytest tests/terminal/test_host_platform.py tests/terminal/test_linux_aarch64.py \
    tests/terminal/test_engine_component.py tests/terminal/test_archive_gaps.py tests/terminal/test_feed_aarch64.py -q
82 passed, 3 skipped, 4 subtests passed

Passed: the A/B — with strata_control/targets.py reverted to main, the new test fails with the WMI calls:

$ python -m pytest tests/terminal/test_host_platform.py -q        # targets.py from main
2 failed, 2 passed
FAILED ...::test_windows_is_known_while_wmi_is_stuck
FAILED ...::test_windows_arm64_comes_from_the_same_source
AssertionError: WMI is stuck

With the fix the same file is 4 passed, and the real host still answers windows-x86_64 (the
test_the_answer_is_a_key_of_the_backend_matrix case).

Failed: none.

Not run: a real WMI stall — the service cannot be stuck on demand, and this box is Python 3.11, whose
win32_ver() does not use WMI (the 3.12 _wmi_query path is the reporter's stack in #4975). The evidence that the
old code makes that call is the CPython source: platform.system()/platform.machine() → platform.uname() →
win32_ver(), which in 3.12 calls _wmi_query(); the test pins that neither call is made on Windows. A real
Windows-3.12 run against a stuck winmgmt remains for the maintainers.

Limits

  • The Windows architecture now depends on the two PROCESSOR_* variables, the same source CPython uses; if an
    environment stripped both, the answer would be windows- as it would be empty in platform.uname() too (not
    observed).
  • platform.system() is still used on macOS and Linux, where it is a syscall. If a future platform's platform
    module starts calling a service, this function would need the same treatment there.
  • platform is still imported for the other systems; no other caller of host_platform() changes.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5185 **Author:** [@XiaoBinGan](https://github.com/XiaoBinGan) **Created:** 11/4/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `reserve/fix-host-platform-wmi` --- ### 📝 Commits (1) - [`aa14ef9`](https://github.com/Niko1221/Strata/commit/aa14ef955c6c9108a10c2881299d1f3c660c3ee2) [Other] Control: host_platform() asks no WMI on Windows, so a stuck winmgmt cannot hang it (#4975) ### 📊 Changes **3 files changed** (+90 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `strata_control/targets.py` (+25 -3) ➕ `tests/terminal/test_host_platform.py` (+58 -0) 📝 `tests/terminal/test_linux_aarch64.py` (+7 -1) </details> ### 📄 Description ## Problem and result On Windows, `strata_control/targets.py:host_platform()` asked the OS through `platform.system()` and `platform.machine()`. Both are `platform.uname()` on Windows, and on the bundled Python 3.12 `uname()` calls `win32_ver()` → `platform._wmi_query()`: a WMI query **with no timeout**. When the Windows Management Instrumentation service (`winmgmt`) is stuck, every Control command that resolves an engine component hangs for as long as WMI does — the report shows the app's «Strata Control did not answer within 60 s (models list)», no supported GPU and nothing loadable, while `nvidia-smi` answers in 0.08 s. After the change the OS and architecture are answered without WMI: ```python return "Windows" if sys.platform.startswith("win") else platform.system() ... if sys.platform.startswith("win"): return os.environ.get("PROCESSOR_ARCHITEW6432") or os.environ.get("PROCESSOR_ARCHITECTURE") or "" return platform.machine() ``` `sys.platform` is set by the interpreter, and `PROCESSOR_ARCHITEW6432` / `PROCESSOR_ARCHITECTURE` are exactly the variables `platform.uname()` itself reads on Windows (`platform._get_machine_win32()`), so the answers are unchanged: `windows-x86_64` (`AMD64`), `windows-arm64` (`ARM64`). ## Related discussion #4975 — the report, with the `faulthandler` stack inside `platform._wmi_query` and the note that the same code is on `main` (`strata_control/targets.py:33`, `:36`). No separate scope agreement was asked for: a stuck WMI taking the app down is the bug, and the reporter suggests the same fix (use `sys.platform` / the `PROCESSOR_*` variables instead of `platform.uname()`). ## Approach - `_system_name()`: on Windows the name is `"Windows"` without asking `platform`; every other system keeps `platform.system()` (that asks the kernel there, not a service). - `_machine_name()`: on Windows it reads `PROCESSOR_ARCHITEW6432` then `PROCESSOR_ARCHITECTURE` (the same two variables CPython's `platform.uname()` reads on Windows, `PROCESSOR_ARCHITEW6432` first because a 32-bit process masks the native architecture); every other system keeps `platform.machine()`. - `host_platform()` maps the two names exactly as before, so no returned `os-arch` key changes. - The one existing test that simulated another OS by patching `platform.system`/`platform.machine` (`tests/terminal/test_linux_aarch64.py::host()`) now also stubs `sys.platform` and the architecture variable for its Windows row, because that is the source the Windows path reads. ## Validation **Passed:** the regression test — new file `tests/terminal/test_host_platform.py` (4 tests, 12 subtests). It makes every `platform` call the old Windows path made fail with `AssertionError("WMI is stuck")` (a real hang cannot be produced from a test) and asserts the answers still come back: ```text $ python -m pytest tests/terminal/test_host_platform.py tests/terminal/test_linux_aarch64.py -q 19 passed ``` **Passed:** the surrounding Control tests, on this checkout (Windows 11, Python 3.11.16): ```text $ python -m pytest tests/terminal/test_host_platform.py tests/terminal/test_linux_aarch64.py \ tests/terminal/test_engine_component.py tests/terminal/test_archive_gaps.py tests/terminal/test_feed_aarch64.py -q 82 passed, 3 skipped, 4 subtests passed ``` **Passed:** the A/B — with `strata_control/targets.py` reverted to `main`, the new test fails with the WMI calls: ```text $ python -m pytest tests/terminal/test_host_platform.py -q # targets.py from main 2 failed, 2 passed FAILED ...::test_windows_is_known_while_wmi_is_stuck FAILED ...::test_windows_arm64_comes_from_the_same_source AssertionError: WMI is stuck ``` With the fix the same file is 4 passed, and the real host still answers `windows-x86_64` (the `test_the_answer_is_a_key_of_the_backend_matrix` case). **Failed:** none. **Not run:** a real WMI stall — the service cannot be stuck on demand, and this box is Python 3.11, whose `win32_ver()` does not use WMI (the 3.12 `_wmi_query` path is the reporter's stack in #4975). The evidence that the old code makes that call is the CPython source: `platform.system()`/`platform.machine()` → `platform.uname()` → `win32_ver()`, which in 3.12 calls `_wmi_query()`; the test pins that neither call is made on Windows. A real Windows-3.12 run against a stuck `winmgmt` remains for the maintainers. ## Limits - The Windows architecture now depends on the two `PROCESSOR_*` variables, the same source CPython uses; if an environment stripped both, the answer would be `windows-` as it would be empty in `platform.uname()` too (not observed). - `platform.system()` is still used on macOS and Linux, where it is a syscall. If a future platform's `platform` module starts calling a service, this function would need the same treatment there. - `platform` is still imported for the other systems; no other caller of `host_platform()` changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5337
No description provided.