fix: add encoding="utf-8" to prompt file open() calls in script_runner (Windows CP950)#607
Open
edenfunf wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: add encoding="utf-8" to prompt file open() calls in script_runner (Windows CP950)#607edenfunf wants to merge 1 commit intomicrosoft:mainfrom
edenfunf wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…r (Windows CP950) PromptCompiler.compile() and _resolve_prompt_file() open .prompt.md files with plain open() which defaults to the system locale encoding. On Windows systems set to CP950/CP936/CP932 (Chinese/Japanese/Korean), a UTF-8 encoded prompt file containing any multibyte character causes: UnicodeDecodeError: 'cp950' codec can't decode byte 0x8b in position 12 Three open() calls were missing explicit encoding: - compiled_path read in ScriptRunner._execute_script - prompt_path read in PromptCompiler.compile - output_path write in PromptCompiler.compile Adding encoding="utf-8" to all three matches the behaviour of the rest of the codebase and fixes the crash for any non-UTF-8 Windows locale.
danielmeppiel
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a
UnicodeDecodeErrorcrash when reading or writing.prompt.mdfiles on Windows systems with a non-UTF-8 locale encoding.Closes #604.
Root Cause
Three
open()calls inscript_runner.pyrely on the platform default encoding. On Windows with CP950/CP936/CP932, Python cannot decode UTF-8 multi-byte sequences (any CJK character, emoji, or non-ASCII content in a prompt file triggers the error).Changes
src/apm_cli/core/script_runner.py— 3 lines changedScriptRunner._execute_script— read compiled fileopen(compiled_path, "r")open(compiled_path, "r", encoding="utf-8")PromptCompiler.compile— read source promptopen(prompt_path, "r")open(prompt_path, "r", encoding="utf-8")PromptCompiler.compile— write compiled outputopen(output_path, "w")open(output_path, "w", encoding="utf-8")All other
open()andread_text()calls in the codebase already carry an explicitencodingparameter; this brings the remaining three into line.Test Plan
uv run pytest tests/unit/test_script_runner.py -x -v— all tests pass.prompt.mdcontaining CJK characters, runapm run start— noUnicodeDecodeError