Skip to content

[BUG]: UnicodeDecodeError: 'gbk' codec can't decode byte on Windows during 'apm install' #3056

Description

Description
On Windows environments (PowerShell / Command Prompt), running apm install fails with a UnicodeDecodeError in the underlying subprocess reader thread when resolving dependencies. This happens because Python defaults to the system code page (gbk / CP936 on Simplified Chinese Windows) rather than UTF-8 when reading standard output/error from spawned child processes (e.g., git or sub-commands with UTF-8 characters).

Steps to Reproduce
Run PowerShell on a Windows system using standard Chinese locale (chcp 936).

Add dependencies containing UTF-8 characters (e.g., non-ASCII commit logs, quotes, or descriptions) in apm.yml.

Run:

PowerShell
apm install ; apm compile
Observe the exception during package resolution.

Expected Behavior
apm should handle process I/O using UTF-8 explicitly (e.g., setting encoding="utf-8", errors="replace" or errors="backslashreplace" in subprocess.Popen / stream readers), allowing dependency resolution to finish without crashing regardless of the OS system locale.

Actual Behavior / Stack Trace
Plaintext
PS D:\2-gerrit\Jenkins\jenkins-platform.worktrees\workflow> apm install ; apm compile
[>] Installing dependencies from apm.yml...
[>] Resolving lsp-infra-hub-jenkins-cli...
[>] Resolving awesome-copilot-multi-stage-dockerfile...
[>] Resolving lsp-infra-hub-apm-skill-creator...
Exception in thread Thread-64 (_readerthread):
Traceback (most recent call last):
File "threading.py", line 1075, in _bootstrap_inner
File "threading.py", line 1012, in run
File "subprocess.py", line 1599, in _readerthread
UnicodeDecodeError: 'gbk' codec can't decode byte 0x94 in position 711: illegal multibyte sequence
Environment
OS: Windows (Simplified Chinese, default codepage 936 / GBK)

Shell: PowerShell

Tool: APM (Agent Package Manager)

Python Version: 3.x

Activity

  1. added
    area/cliCLI command surface, flags, help text (cross-cutting).
    triage/recommendedAutomated advice completed; not human scope approval.
    on Sep 22, 2026
  2. github-actions commented on Sep 22, 2026

    @github-actions

    Triage recommendation: accept (advisory only -- a responsible human maintainer must still approve scope, priority, and review contact per GOVERNANCE.md).

    Thanks for isolating this to the Simplified Chinese (cp936/gbk) locale on Windows. The root cause is well-identified: the subprocess stdout/stderr reader thread relies on the platform default encoding instead of forcing UTF-8, so any non-ASCII byte sequence APM itself writes (or a child process emits) that isn't valid gbk raises an uncaught UnicodeDecodeError and crashes the install.

    Proposed scope: Force UTF-8 (with an explicit error-handling strategy, e.g. errors="replace") for the subprocess output reader thread(s) used during apm install, rather than relying on the OS default codepage.

    Proposed done-when: A test simulates non-UTF-8-decodable bytes on the subprocess stdout/stderr stream and confirms apm install completes without raising UnicodeDecodeError; ideally a Windows/cp936-locale CI case or a decode-focused unit test is added.

    Exclusions: No broader change to encoding handling outside the subprocess reader path.

    Review needs: A maintainer familiar with the install subprocess/streaming-output code, ideally with Windows testing capability.

    Generated by Triage Panel · copilot · auto · 165.1 AIC · ⌖ 5.28 AIC · ⊞ 12K · ◷

  3. danielmeppiel commented on Oct 1, 2026

    @danielmeppiel
    Collaborator

    Decision: approve
    Area: project
    Scope: Fix the failing Windows subprocess decoding boundary during installation so non-English locales do not crash a valid install, while preserving machine-readable output semantics.
    Done when: A regression covers the reported Windows/locale failure; valid output is decoded deterministically, malformed machine output is surfaced rather than silently corrupted, and existing command failure behavior remains intact.
    Out of scope: Blanket silent replacement or dropping of malformed machine output, unrelated encoding rewrites, or masking subprocess failures.
    Review contact: Daniel Meppiel (@danielmeppiel)

    Installation should not depend on the developer's Windows locale.

    Recorded by Copilot on behalf of Daniel Meppiel (@danielmeppiel) following the direct product decisions confirmed on 2026-09-30 and explicit authorization to update the issues on 2026-10-01. Daniel separately confirmed that he is the review contact for accepted scopes. This records a human decision, not an autonomous triage recommendation. It does not promise a release, assign implementation, approve a merge, or bypass review.

  4. Bortlesboat commented on Oct 10, 2026

    @Bortlesboat

    I'd like to work on this. Reproduced the reader-thread crash locally with a child that writes UTF-8 + a non-UTF-8 byte under encoding="gbk". Worth noting that run() then returns stdout='' and stderr=None, so on top of the traceback the output is silently lost.

    Plan within the approved scope: a small helper that runs the install-path git subprocesses with bytes output and decodes stdout/stderr as UTF-8 in the calling thread. Malformed output raises a subprocess.SubprocessError subclass naming the command, so existing failure handling still applies and nothing gets replaced or dropped. I'll switch the text=True git calls under deps/, cache/git_cache.py and utils/git_sparse.py / git_env.py to it, and add a regression test that runs a real child process under a forced cp936 default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cliCLI command surface, flags, help text (cross-cutting).status/acceptedHuman scope approval; verify the issue's approval record and review contact before work.triage/recommendedAutomated advice completed; not human scope approval.type/bugSomething does not work as documented.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions