Skip to content

fix(s07): resolve Windows subprocess UnicodeDecodeError with UTF-8/GBK fallback - #510

Open
xiarimr wants to merge 1 commit into
shareAI-lab:mainfrom
xiarimr:fix-windows-encoding-crash
Open

fix(s07): resolve Windows subprocess UnicodeDecodeError with UTF-8/GBK fallback#510
xiarimr wants to merge 1 commit into
shareAI-lab:mainfrom
xiarimr:fix-windows-encoding-crash

Conversation

@xiarimr

@xiarimr xiarimr commented Aug 11, 2026

Copy link
Copy Markdown

Bug Description

On Windows, when executing commands via run_bash (such as inspecting or loading skill.md), a UnicodeDecodeError occurs in subprocess's background reader thread (_readerthread).

Trigger Scenario:
skill.md contains UTF-8 encoded text/characters. When run_bash executes CLI commands that output its content, Windows defaults to GBK (CP936) for stream decoding when text=True is enabled.

Chain of Failure:

  1. UTF-8 byte sequences from skill.md fail to decode under Windows default GBK codec in _readerthread.
  2. The reader thread crashes silently before returning output.
  3. r.stdout evaluates to None, which triggers a secondary TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' in run_bash.

Solution

  1. Remove text=True from subprocess.run to keep output as raw bytes.
  2. Implement a safe_decode helper function that attempts UTF-8 decoding first, with a clean fallback to GBK.

Tested Environments

  • OS: Windows 10/11 (ANSI CP936 / GBK default)
  • Module: s07_skill_loading

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant