Summary
On Windows systems configured with non-UTF-8 console encodings (CP950, CP936, CP932, etc.), several APM commands fail with an unhandled exception in a background thread:
Exception in thread Thread-N (_readerthread):
Traceback (most recent call last):
File "threading.py", line 1043, in _bootstrap_inner
File "subprocess.py", line 1615, in _readerthread
UnicodeDecodeError: 'cp950' codec can't decode byte 0x85 in position 4: illegal multibyte sequence
Steps to reproduce
- Use Windows with a Traditional Chinese (CP950) or Simplified Chinese (CP936) locale
- Run
apm init <project-name>
The error appears in the terminal and the command may abort or produce incomplete output.
Root cause
subprocess.run(..., text=True) without an explicit encoding argument uses the system locale encoding to decode subprocess output. On CP950 systems, when git emits UTF-8 byte sequences (e.g. \xc2\x85), the CP950 codec raises UnicodeDecodeError in the _readerthread that reads the subprocess pipe.
The existing _configure_encoding() sets PYTHONIOENCODING=utf-8 and reconfigures sys.stdout/sys.stderr, but this does not affect how the calling Python process decodes output read back from subprocess pipes -- that path uses the locale default independently.
Affected call sites include _auto_detect_author(), _auto_detect_description(), git ls-remote validation in install.py, token_manager.py, github_downloader.py, policy/discovery.py, version.py, and all runtime adapters (codex_runtime.py, copilot_runtime.py, llm_runtime.py, manager.py).
Expected behavior
Commands complete normally. Non-ASCII output from git (e.g. a username in Chinese characters) is handled correctly.
Environment
- Windows 11 with Traditional Chinese locale (CP950)
- APM 0.8.10
- Python 3.13
Summary
On Windows systems configured with non-UTF-8 console encodings (CP950, CP936, CP932, etc.), several APM commands fail with an unhandled exception in a background thread:
Steps to reproduce
apm init <project-name>The error appears in the terminal and the command may abort or produce incomplete output.
Root cause
subprocess.run(..., text=True)without an explicitencodingargument uses the system locale encoding to decode subprocess output. On CP950 systems, when git emits UTF-8 byte sequences (e.g.\xc2\x85), the CP950 codec raisesUnicodeDecodeErrorin the_readerthreadthat reads the subprocess pipe.The existing
_configure_encoding()setsPYTHONIOENCODING=utf-8and reconfiguressys.stdout/sys.stderr, but this does not affect how the calling Python process decodes output read back from subprocess pipes -- that path uses the locale default independently.Affected call sites include
_auto_detect_author(),_auto_detect_description(), git ls-remote validation ininstall.py,token_manager.py,github_downloader.py,policy/discovery.py,version.py, and all runtime adapters (codex_runtime.py,copilot_runtime.py,llm_runtime.py,manager.py).Expected behavior
Commands complete normally. Non-ASCII output from git (e.g. a username in Chinese characters) is handled correctly.
Environment