From a8785a6f5354ce3f0a6c9f2b3e36b7d94c42e99c Mon Sep 17 00:00:00 2001 From: adv0r <> Date: Wed, 20 May 2026 12:11:39 +0200 Subject: [PATCH] magentic-one-cli: pin utf-8 encoding when loading YAML config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #5566. The original report (#5566) was that `m1` crashed with `UnicodeDecodeError: 'cp950' codec can't decode byte ...` when loading `page_script.js` on a non-UTF-8 default locale (Traditional Chinese Windows, cp950). That specific call site was fixed in #6094. The reporter noted at the time: *"there will be some similar issues in the codebase while using open function"*, and the issue stayed open explicitly to track that follow-up. This PR fixes the next call sites on the same code path the user actually hits when they type `m1 ...` on Windows. `magentic_one_cli/_m1.py` opens the YAML config file in two places: - the default `~/.magentic_one_config.yaml` (line 100) - the user-supplied `--config ` (line 105) Both used `open(..., "r")` with no `encoding=`, so on a non-UTF-8 locale (cp950, cp1252, etc.) a config containing any non-ASCII byte (comments in CJK, accented paths, …) would raise `UnicodeDecodeError` before the CLI even got to construct an agent. This change adds `encoding="utf-8"` to both `open()` calls. YAML 1.2 mandates UTF-8 as the default encoding for YAML streams, so pinning UTF-8 on the reader matches what users are already writing. Why only two call sites, and not a repo-wide sweep: - Keeps the diff reviewable. - Same package as the original crash (`magentic-one-cli`), same code path the bug report hits. - A blanket sweep across `python/packages/` would touch >40 files (incl. test fixtures and benchmark scenario scripts that read JSONL produced by the agents themselves, where forcing UTF-8 could in theory mask issues). Better to land focused, then iterate. No behaviour change for already-UTF-8-locale users. AI-assisted via Cursor (Claude Opus 4.7). Personal token-burn initiative by @adv0r to use up an expiring Cursor subscription budget on small, useful upstream contributions. Co-authored-by: Cursor --- python/packages/magentic-one-cli/src/magentic_one_cli/_m1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/packages/magentic-one-cli/src/magentic_one_cli/_m1.py b/python/packages/magentic-one-cli/src/magentic_one_cli/_m1.py index 1b159da4e91d..0a45711334d4 100644 --- a/python/packages/magentic-one-cli/src/magentic_one_cli/_m1.py +++ b/python/packages/magentic-one-cli/src/magentic_one_cli/_m1.py @@ -97,12 +97,12 @@ def main() -> None: if args.config is None: if os.path.isfile(DEFAULT_CONFIG_FILE): - with open(DEFAULT_CONFIG_FILE, "r") as f: + with open(DEFAULT_CONFIG_FILE, "r", encoding="utf-8") as f: config = yaml.safe_load(f) else: config = yaml.safe_load(DEFAULT_CONFIG_CONTENTS) else: - with open(args.config if isinstance(args.config, str) else args.config[0], "r") as f: + with open(args.config if isinstance(args.config, str) else args.config[0], "r", encoding="utf-8") as f: config = yaml.safe_load(f) # Run the task