Skip to content

[BUG] UnicodeDecodeError on Windows non-UTF-8 consoles (CP950/CP936) when running apm init and other commands #590

@edenfunf

Description

@edenfunf

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

  1. Use Windows with a Traditional Chinese (CP950) or Simplified Chinese (CP936) locale
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions