From f65c89e02e088a99667622b5db0661086a28a97b Mon Sep 17 00:00:00 2001 From: Rolly Calma <115199279+Ghraven@users.noreply.github.com> Date: Tue, 2 Jun 2026 10:12:13 +0800 Subject: [PATCH] chore: use explicit utf-8 for shell job files (#820) --- routes/shell_routes.py | 7 ++++--- src/bg_jobs.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/routes/shell_routes.py b/routes/shell_routes.py index c791b12..da8c9a3 100644 --- a/routes/shell_routes.py +++ b/routes/shell_routes.py @@ -469,7 +469,8 @@ async def _generate_tmux(cmd: str, request: Request): f"EC=${{PIPESTATUS[0]}}\n" f"echo ':::EXIT_CODE:::'$EC >> '{log_path}'\n" f"rm -f '{script_path}'\n" - f"exit $EC\n" + f"exit $EC\n", + encoding="utf-8", ) script_path.chmod(0o755) logger.info("tmux wrapper script created: session=%s path=%s", session_id, script_path) @@ -504,7 +505,7 @@ async def _generate_tmux(cmd: str, request: Request): # Read new lines from log try: if log_path.exists(): - lines = log_path.read_text(errors="replace").splitlines() + lines = log_path.read_text(encoding="utf-8", errors="replace").splitlines() new_lines = lines[lines_sent:] for line in new_lines: if line.startswith(":::EXIT_CODE:::"): @@ -532,7 +533,7 @@ async def _generate_tmux(cmd: str, request: Request): # Session ended — do one final read await asyncio.sleep(0.5) if log_path.exists(): - lines = log_path.read_text(errors="replace").splitlines() + lines = log_path.read_text(encoding="utf-8", errors="replace").splitlines() for line in lines[lines_sent:]: if line.startswith(":::EXIT_CODE:::"): try: diff --git a/src/bg_jobs.py b/src/bg_jobs.py index a770f11..7605d5b 100644 --- a/src/bg_jobs.py +++ b/src/bg_jobs.py @@ -195,7 +195,7 @@ def refresh() -> Dict[str, Dict[str, Any]]: exit_path = Path(rec.get("exit_path", "")) if exit_path.exists(): try: - code = int(exit_path.read_text().strip() or "1") + code = int(exit_path.read_text(encoding="utf-8", errors="replace").strip() or "1") except Exception: code = 1 rec["exit_code"] = code