Skip to content

Fix GBK decode crashes on Windows by forcing UTF-8 everywhere - #453

Closed
Holmescalvin wants to merge 1 commit into
shareAI-lab:mainfrom
Holmescalvin:fix/gbk-utf8-encoding-crash
Closed

Fix GBK decode crashes on Windows by forcing UTF-8 everywhere#453
Holmescalvin wants to merge 1 commit into
shareAI-lab:mainfrom
Holmescalvin:fix/gbk-utf8-encoding-crash

Conversation

@Holmescalvin

Copy link
Copy Markdown

Summary

  • subprocess.run(text=True) and Path.read_text()/write_text() without an explicit encoding fall back to the OS default codec, which is GBK on Chinese Windows.
  • Reading/writing this project's UTF-8 source/data files (or capturing subprocess output containing non-ASCII bytes) then crashes with UnicodeDecodeError — e.g. running s10_system_prompt/code.py and reading README.md fails immediately.
  • Forces encoding="utf-8" on every read_text/write_text call, and adds encoding="utf-8", errors="replace" to every subprocess.run(..., text=True, ...) call across the tutorial code.py files, agents/*.py, and the agent-builder skill scripts, so output stays readable instead of crashing the process even if a command emits unexpected bytes.

Test plan

  • python -m py_compile on every changed file — all compile cleanly
  • Ran s10_system_prompt/code.py end-to-end on Windows (Chinese locale/GBK) after the fix — starts and reads README.md/memory files without crashing
  • Reproduced the original crash before the fix (UnicodeDecodeError / TypeError: unsupported operand type(s) for +: 'NoneType' and 'str') to confirm root cause

🤖 Generated with Claude Code

subprocess.run(text=True) and Path.read_text()/write_text() without an
explicit encoding fall back to the OS default, which is GBK on Chinese
Windows. Reading/writing the project's UTF-8 files (or subprocess output
containing non-ASCII bytes) then crashes with UnicodeDecodeError. Force
encoding="utf-8" everywhere, with errors="replace" on subprocess capture
so unexpected bytes degrade gracefully instead of killing the process.
@Bill-Billion
Bill-Billion force-pushed the main branch 2 times, most recently from 934b526 to 581241c Compare July 28, 2026 12:24
@Bill-Billion

Copy link
Copy Markdown
Collaborator

Thanks for the detailed report and the Windows testing.
We fixed the file I/O part in #546. The current code now uses explicit UTF-8 encoding for course files, Agent Builder files, task state, skill manifests, transcripts, and inboxes, with regression tests covering those paths.
The course has also moved from the old s01-s20 layout to s01-s17, so this branch no longer matches main.
The subprocess output case needs separate handling because Windows commands may use the active code page rather than UTF-8. We should address that in a smaller change with focused Windows tests instead of applying encoding="utf-8" to every subprocess call.
Closing this PR since the file I/O changes have been superseded by #546 and the remaining subprocess work needs a different scope. Thanks for the contribution.

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.

2 participants