[GH-ISSUE #4675] [Engine] First-run install and strata launch die in a subprocess reader thread on non-UTF-8 Windows (GBK device name vs PYTHONUTF8=1) #2128

Closed
opened 2026-11-04 01:56:55 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kongh9 on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4675

Version: Strata desktop 0.2.7 (Control 0.1.52, bundled CPython 3.12.15) and Strata Terminal 0.1.54 — both reproduce, in different files.
OS: Windows 10 22H2 (10.0.19045), Simplified Chinese: ACP and OEM code page 936 (GBK). GPU path is unrelated — this fails before any GPU/CUDA decision is reached.


Symptom

Desktop 0.2.7 — the first-run wizard fails every time with the last install failed (12 identical attempts here). Its own diagnostics show:

2026-10-28T14:50:09.175Z control: Exception in thread
2026-10-28T14:50:09.175Z control: Thread-6 (_readerthread):
...
  File ".../Lib/subprocess.py", line 1599, in _readerthread
    buffer.append(fh.read())
  File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 290: invalid start byte

and install/.strata-mcp/setup.log:

=== Step 1: checking your PC ===
Exception in thread Thread-3 (_readerthread):
...
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 290: invalid start byte
Traceback (most recent call last):
  File "...\control\setup.py", line 9003, in main
    amd = amd_gpus()
  File "...\control\setup.py", line 4223, in amd_gpus_windows
    adapters = _win_display_adapters() if adapters is None else adapters
  File "...\control\setup.py", line 4165, in _win_display_adapters
    for line in text.splitlines():
AttributeError: 'NoneType' object has no attribute 'splitlines'
strata-mcp: setup ended with exit code 1

Nothing is downloaded and no GPU decision is made — it dies inside Step 1.

Strata Terminal 0.1.54 — strata launch prints the same shape, at a different offset (the offset only depends on which row of the WMI table comes first, see below):

Exception in thread Thread-5 (_readerthread):
...
  File "...\python\Lib\subprocess.py", line 1599, in _readerthread
    buffer.append(fh.read())
  File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 10: invalid start byte

Root cause

Three facts that only break when combined:

  1. Strata forces UTF-8 mode on the installer process.

    • Desktop: host/server/control-runtime.mjs, controlEnvironment() puts PYTHONUTF8: '1' after the { ...env } spread, so a user- or system-level PYTHONUTF8 can never win. Same in installerEnvironment() / native-control.mjs.
    • Terminal: bin/strata.cmd:10 → set "PYTHONUTF8=1", and bin/strata.ps1:54 → $env:PYTHONUTF8 = '1'.
      In UTF-8 mode locale.getpreferredencoding(False) returns utf-8 (measured: utf8_mode: 1).
  2. The subprocess readers decode that output with no error policy. setup.py's helper (0.1.52 line 935, 0.1.54 line 938):

    def out(cmd):
        try:
            return subprocess.run(cmd, capture_output=True, text=True, timeout=60).stdout
        except (OSError, subprocess.TimeoutExpired):
            return ""
    

    text=True with no errors= → strict UTF-8 decoding. The same pattern is in tools/strata_mcp.py:348 (run_quiet()) and, new in 0.1.54, in strata_control/engine_component.py:632.

  3. PowerShell 5.1 writes that pipe in the OEM code page (936), not UTF-8. _win_display_adapters() asks for Win32_VideoController, and the child has no console, so Microsoft 基本显示适配器 ("Microsoft Basic Display Adapter", i.e. any GPU Windows has no vendor driver for — which is the normal state on a headless/datacentre PC) arrives as GBK bytes:

    b'Microsoft Remote Display Adapter|SWD\\REMOTEDISPLAYENUM\\RDPIDD_INDIRECTDISPLAY&SESSIONID_0002|\r\n'
    b'NVIDIA Tesla V100-SXM2-16GB|PCI\\VEN_10DE&DEV_1DB1&...|\r\n'
    b'NVIDIA Tesla V100-SXM2-16GB|PCI\\VEN_10DE&DEV_1DB1&...|\r\n'
    b'Microsoft \xbb\xf9\xb1\xbe\xcf\xd4\xca\xbe\xca\xca\xc5\xe4\xc6\xf7|PCI\\VEN_10DE&DEV_0A60&...|0\r\n'
    

    BB F9 is 基. A reader thread raises, communicate() hands back stdout = None, and .splitlines() on None kills setup with exit code 1. out() cannot catch it: the exception happens in the reader thread, not in the caller.

Why the offset differs. setup.py's query is Name|PNPDeviceID|AdapterRAM, so the ASCII "Microsoft " prefix is 10 bytes and the first bad byte lands at position 10 — unless an earlier ASCII row precedes it, which is exactly how the desktop log got 290. Same defect, two offsets.

The pattern is already known in this repo, which is why this looks like a gap rather than a decision: setup.py:8193 (0.1.52) / :8260 (0.1.54) already use encoding="utf-8", errors="replace", strata_cli/launch/runner.py:667 likewise, and the GBK class of bugs was fixed for the benchmark tools (#2499, #2648, #2792, #3092, #3235, #4011) and for the Russian-locale GUI paths (#3202). The subprocess readers in Step 1 were left out.

Checked against main before filing: out() (line 934) and _win_display_adapters() (line 4167) are still byte-for-byte as above, and no existing issue covers this — searched UnicodeDecodeError (19 results, all strata_bench/CMakeLists.txt), "invalid start byte" (0), "can't decode byte" (0), _win_display_adapters (0), PYTHONUTF8 (24, none about Step 1's adapter probe), splitlines (5, unrelated), "Win32_VideoController" (4, unrelated), "the last install failed" (2, unrelated).


Minimal repro (60 s, no install, nothing written)

Run with the app's own interpreter, twice, and compare:

# A) as Strata launches it: UTF-8 mode -> stdout is None
$env:PYTHONUTF8 = '1'
& "$env:LOCALAPPDATA\Programs\Strata\control\python\python.exe" -c @'
import subprocess, locale, sys
ps = "Get-CimInstance Win32_VideoController | ForEach-Object { $_.Name + '|' + $_.PNPDeviceID + '|' + $_.AdapterRAM }"
print("utf8_mode", sys.flags.utf8_mode, "| preferred", locale.getpreferredencoding(False))
r = subprocess.run(["powershell","-NoProfile","-NonInteractive","-Command",ps], capture_output=True, text=True, timeout=60)
print("rc", r.returncode, "| stdout is None ->", r.stdout is None)
'@

# B) same command without UTF-8 mode -> all rows come back fine
Remove-Item Env:PYTHONUTF8
& "$env:LOCALAPPDATA\Programs\Strata\control\python\python.exe" -c @'
...(same as above)...
'@

A prints utf8_mode 1 | preferred utf-8 then stdout is None -> True; B prints the rows. Alternatively setup.py --check (which downloads nothing) dies at Step 1 under A's environment and reaches the GPU verdict under B's.

Affected machine shape: any Windows whose display language makes one adapter name non-ASCII (zh/ja/ru/...), or any PC where a GPU is running on the Microsoft basic display driver. English-only setups never see it, which probably explains why it stayed hidden.


Suggested fix

Two independent points, either alone stops the crash; both together stop the whole class:

  1. Never let a child's code page kill a reader thread. Add an error policy to the text=True reads — errors="replace" in setup.py out() (already the house pattern) and tools/strata_mcp.py run_quiet(), strata_control/engine_component.py _windows_adapters_cim(); and guard the parse with (done.stdout or "") / text or "" so a None can never reach .splitlines().

  2. Don't identify hardware by a localizable string. errors="replace" mangles the name, which then breaks amd_gpus_windows(): it pairs a WMI row with a display-class registry entry by comparing DriverDesc with ad["name"] before reading HardwareInformation.qwMemorySize. A localized AMD adapter name would no longer match, and its VRAM would come back 0 (the same report as #3798). Matching on the PCI id it already parses (VEN_1002&DEV_xxxx) instead of the name makes that step locale-independent. Reading only the registry, as serve/telemetry.py windows_display_adapters() already does, avoids the subprocess entirely.

Two more call sites of the same shape, seen while reading but not yet observed to fail here, worth sweeping at the same time:

  • strata_control/engine_component.py:482 — if done.returncode == 0 and done.stdout.strip(): with no None guard, and its probe is nvidia-smi --query-gpu=name (a name field). Not triggered today because NVIDIA's own device names come back in English.
  • strata_control/engine_component.py:779 (_smi_query) — same missing guard, but it only ever queries compute_cap / driver_version, so pure ASCII; low risk.

Local workarounds people on zh-CN/ja/ru Windows can use today

  • Patch the three readers with errors="replace" (+ the or "" guards). Caveat: current is a version symlink and a Control/Terminal component update reverts it silently, so it has to be re-applied.
  • Or remove the non-ASCII adapter from Win32_VideoController (disable the driverless card, or bind a vendor driver so its name becomes English).
  • Do not try to override the mode from the outside: controlEnvironment() writes PYTHONUTF8:'1' after the env spread, and bin/strata.cmd / bin/strata.ps1 set it themselves, so a user- or system-level PYTHONUTF8=0 never reaches the installer.

Happy to test a patch on this machine and re-run setup.py --check plus strata launch against it.

Originally created by @kongh9 on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4675 **Version:** Strata desktop 0.2.7 (Control 0.1.52, bundled CPython 3.12.15) and Strata Terminal 0.1.54 — both reproduce, in different files. **OS:** Windows 10 22H2 (10.0.19045), Simplified Chinese: ACP and OEM code page 936 (GBK). GPU path is unrelated — this fails before any GPU/CUDA decision is reached. --- ## Symptom **Desktop 0.2.7** — the first-run wizard fails every time with `the last install failed` (12 identical attempts here). Its own diagnostics show: ``` 2026-10-28T14:50:09.175Z control: Exception in thread 2026-10-28T14:50:09.175Z control: Thread-6 (_readerthread): ... File ".../Lib/subprocess.py", line 1599, in _readerthread buffer.append(fh.read()) File "<frozen codecs>", line 322, in decode UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 290: invalid start byte ``` and `install/.strata-mcp/setup.log`: ``` === Step 1: checking your PC === Exception in thread Thread-3 (_readerthread): ... UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 290: invalid start byte Traceback (most recent call last): File "...\control\setup.py", line 9003, in main amd = amd_gpus() File "...\control\setup.py", line 4223, in amd_gpus_windows adapters = _win_display_adapters() if adapters is None else adapters File "...\control\setup.py", line 4165, in _win_display_adapters for line in text.splitlines(): AttributeError: 'NoneType' object has no attribute 'splitlines' strata-mcp: setup ended with exit code 1 ``` Nothing is downloaded and no GPU decision is made — it dies inside Step 1. **Strata Terminal 0.1.54** — `strata launch` prints the same shape, at a different offset (the offset only depends on which row of the WMI table comes first, see below): ``` Exception in thread Thread-5 (_readerthread): ... File "...\python\Lib\subprocess.py", line 1599, in _readerthread buffer.append(fh.read()) File "<frozen codecs>", line 322, in decode UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 10: invalid start byte ``` --- ## Root cause Three facts that only break when combined: 1. **Strata forces UTF-8 mode on the installer process.** - Desktop: `host/server/control-runtime.mjs`, `controlEnvironment()` puts `PYTHONUTF8: '1'` **after** the `{ ...env }` spread, so a user- or system-level `PYTHONUTF8` can never win. Same in `installerEnvironment()` / `native-control.mjs`. - Terminal: `bin/strata.cmd:10` → `set "PYTHONUTF8=1"`, and `bin/strata.ps1:54` → `$env:PYTHONUTF8 = '1'`. In UTF-8 mode `locale.getpreferredencoding(False)` returns `utf-8` (measured: `utf8_mode: 1`). 2. **The subprocess readers decode that output with no error policy.** `setup.py`'s helper (0.1.52 line 935, 0.1.54 line 938): ```python def out(cmd): try: return subprocess.run(cmd, capture_output=True, text=True, timeout=60).stdout except (OSError, subprocess.TimeoutExpired): return "" ``` `text=True` with no `errors=` → strict UTF-8 decoding. The same pattern is in `tools/strata_mcp.py:348` (`run_quiet()`) and, new in 0.1.54, in `strata_control/engine_component.py:632`. 3. **PowerShell 5.1 writes that pipe in the OEM code page (936), not UTF-8.** `_win_display_adapters()` asks for `Win32_VideoController`, and the child has no console, so `Microsoft 基本显示适配器` ("Microsoft Basic Display Adapter", i.e. any GPU Windows has no vendor driver for — which is the normal state on a headless/datacentre PC) arrives as GBK bytes: ``` b'Microsoft Remote Display Adapter|SWD\\REMOTEDISPLAYENUM\\RDPIDD_INDIRECTDISPLAY&SESSIONID_0002|\r\n' b'NVIDIA Tesla V100-SXM2-16GB|PCI\\VEN_10DE&DEV_1DB1&...|\r\n' b'NVIDIA Tesla V100-SXM2-16GB|PCI\\VEN_10DE&DEV_1DB1&...|\r\n' b'Microsoft \xbb\xf9\xb1\xbe\xcf\xd4\xca\xbe\xca\xca\xc5\xe4\xc6\xf7|PCI\\VEN_10DE&DEV_0A60&...|0\r\n' ``` `BB F9` is `基`. A reader thread raises, `communicate()` hands back `stdout = None`, and `.splitlines()` on `None` kills setup with exit code 1. `out()` cannot catch it: the exception happens in the reader thread, not in the caller. **Why the offset differs.** `setup.py`'s query is `Name|PNPDeviceID|AdapterRAM`, so the ASCII `"Microsoft "` prefix is 10 bytes and the first bad byte lands at **position 10** — unless an earlier ASCII row precedes it, which is exactly how the desktop log got **290**. Same defect, two offsets. **The pattern is already known in this repo**, which is why this looks like a gap rather than a decision: `setup.py:8193` (0.1.52) / `:8260` (0.1.54) already use `encoding="utf-8", errors="replace"`, `strata_cli/launch/runner.py:667` likewise, and the GBK class of bugs was fixed for the benchmark tools (#2499, #2648, #2792, #3092, #3235, #4011) and for the Russian-locale GUI paths (#3202). The subprocess readers in Step 1 were left out. Checked against `main` before filing: `out()` (line 934) and `_win_display_adapters()` (line 4167) are still byte-for-byte as above, and no existing issue covers this — searched `UnicodeDecodeError` (19 results, all `strata_bench`/`CMakeLists.txt`), `"invalid start byte"` (0), `"can't decode byte"` (0), `_win_display_adapters` (0), `PYTHONUTF8` (24, none about Step 1's adapter probe), `splitlines` (5, unrelated), `"Win32_VideoController"` (4, unrelated), `"the last install failed"` (2, unrelated). --- ## Minimal repro (60 s, no install, nothing written) Run with the app's own interpreter, twice, and compare: ```powershell # A) as Strata launches it: UTF-8 mode -> stdout is None $env:PYTHONUTF8 = '1' & "$env:LOCALAPPDATA\Programs\Strata\control\python\python.exe" -c @' import subprocess, locale, sys ps = "Get-CimInstance Win32_VideoController | ForEach-Object { $_.Name + '|' + $_.PNPDeviceID + '|' + $_.AdapterRAM }" print("utf8_mode", sys.flags.utf8_mode, "| preferred", locale.getpreferredencoding(False)) r = subprocess.run(["powershell","-NoProfile","-NonInteractive","-Command",ps], capture_output=True, text=True, timeout=60) print("rc", r.returncode, "| stdout is None ->", r.stdout is None) '@ # B) same command without UTF-8 mode -> all rows come back fine Remove-Item Env:PYTHONUTF8 & "$env:LOCALAPPDATA\Programs\Strata\control\python\python.exe" -c @' ...(same as above)... '@ ``` A prints `utf8_mode 1 | preferred utf-8` then `stdout is None -> True`; B prints the rows. Alternatively `setup.py --check` (which downloads nothing) dies at Step 1 under A's environment and reaches the GPU verdict under B's. Affected machine shape: any Windows whose display language makes one adapter name non-ASCII (zh/ja/ru/...), or any PC where a GPU is running on the Microsoft basic display driver. English-only setups never see it, which probably explains why it stayed hidden. --- ## Suggested fix Two independent points, either alone stops the crash; both together stop the whole class: 1. **Never let a child's code page kill a reader thread.** Add an error policy to the `text=True` reads — `errors="replace"` in `setup.py out()` (already the house pattern) and `tools/strata_mcp.py run_quiet()`, `strata_control/engine_component.py _windows_adapters_cim()`; and guard the parse with `(done.stdout or "")` / `text or ""` so a `None` can never reach `.splitlines()`. 2. **Don't identify hardware by a localizable string.** `errors="replace"` mangles the name, which then breaks `amd_gpus_windows()`: it pairs a WMI row with a display-class registry entry by comparing `DriverDesc` with `ad["name"]` before reading `HardwareInformation.qwMemorySize`. A localized AMD adapter name would no longer match, and its VRAM would come back 0 (the same report as #3798). Matching on the PCI id it already parses (`VEN_1002&DEV_xxxx`) instead of the name makes that step locale-independent. Reading only the registry, as `serve/telemetry.py windows_display_adapters()` already does, avoids the subprocess entirely. Two more call sites of the same shape, seen while reading but not yet observed to fail here, worth sweeping at the same time: - `strata_control/engine_component.py:482` — `if done.returncode == 0 and done.stdout.strip():` with no `None` guard, and its probe is `nvidia-smi --query-gpu=name` (a name field). Not triggered today because NVIDIA's own device names come back in English. - `strata_control/engine_component.py:779` (`_smi_query`) — same missing guard, but it only ever queries `compute_cap` / `driver_version`, so pure ASCII; low risk. --- ## Local workarounds people on zh-CN/ja/ru Windows can use today - Patch the three readers with `errors="replace"` (+ the `or ""` guards). Caveat: `current` is a version symlink and a Control/Terminal component update reverts it silently, so it has to be re-applied. - Or remove the non-ASCII adapter from `Win32_VideoController` (disable the driverless card, or bind a vendor driver so its name becomes English). - Do **not** try to override the mode from the outside: `controlEnvironment()` writes `PYTHONUTF8:'1'` after the env spread, and `bin/strata.cmd` / `bin/strata.ps1` set it themselves, so a user- or system-level `PYTHONUTF8=0` never reaches the installer. Happy to test a patch on this machine and re-run `setup.py --check` plus `strata launch` against it.
bsakaguchi 2026-11-04 01:56:55 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 30, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6515422729 --> @github-actions[bot] commented on GitHub (Oct 30, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@Niko1221 commented on GitHub (Oct 31, 2026):

Fixed in 0.2.9: setup and the Terminal now read what other programs print without stopping when the text isn't UTF-8, and the graphics card list is asked for in UTF-8 too. We tested this without a Chinese Windows PC, so if the first start still fails, comment here and we'll reopen. Your write-up made this quick, thank you.

<!-- gh-comment-id:6541133535 --> @Niko1221 commented on GitHub (Oct 31, 2026): Fixed in [0.2.9](https://github.com/Niko1221/Strata/releases/tag/v0.2.9): setup and the Terminal now read what other programs print without stopping when the text isn't UTF-8, and the graphics card list is asked for in UTF-8 too. We tested this without a Chinese Windows PC, so if the first start still fails, comment here and we'll reopen. Your write-up made this quick, thank you.
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#2128
No description provided.