From fb1341b629c208912deef19ec09a6b9fbb5d7ef2 Mon Sep 17 00:00:00 2001 From: Wes Huber Date: Tue, 2 Jun 2026 16:37:11 -0700 Subject: [PATCH] fix(cookbook): set UTF-8 encoding for detached download/serve subprocesses (#1599) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Windows, Python defaults to the active code page (cp1252) for subprocess I/O. HuggingFace CLI outputs U+2713 (✓) when validating tokens, which cp1252 cannot encode, crashing the download process. Set PYTHONUTF8=1 and PYTHONIOENCODING=utf-8 in the subprocess environment so Unicode output from hf/pip/llama-server is handled correctly. Fixes #1543 Co-authored-by: Claude Opus 4.6 (1M context) --- routes/cookbook_routes.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routes/cookbook_routes.py b/routes/cookbook_routes.py index cc245f0..e1e4972 100644 --- a/routes/cookbook_routes.py +++ b/routes/cookbook_routes.py @@ -383,11 +383,15 @@ def setup_cookbook_routes() -> APIRouter: encoding="utf-8", ) argv = [os.environ.get("ComSpec", "cmd.exe"), "/c", str(script_path)] + env = os.environ.copy() + env["PYTHONUTF8"] = "1" + env["PYTHONIOENCODING"] = "utf-8" proc = subprocess.Popen( argv, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL, + env=env, **detached_popen_kwargs(), ) pid_path.write_text(str(proc.pid), encoding="utf-8")