From 0bfc6cd37abf95464465a7b3a3cf74d8e72aa618 Mon Sep 17 00:00:00 2001 From: genisis0x Date: Fri, 29 May 2026 15:11:41 +0530 Subject: [PATCH] fix(loader): close model task JSON file and read it as UTF-8 ModelTaskLoaderJson.load read the model JSON via json.load(open(...)), which both leaked the file handle (never closed) and used the platform default encoding (cp1252/gbk on Windows). Model JSON can carry non-ASCII content and JSON is UTF-8 by default per RFC 8259 section 8.1, so the load could raise UnicodeDecodeError on non-UTF-8 locales. Use a context manager with encoding pinned to utf-8. --- rdagent/components/loader/task_loader.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rdagent/components/loader/task_loader.py b/rdagent/components/loader/task_loader.py index 9fbb0ec67..388528047 100644 --- a/rdagent/components/loader/task_loader.py +++ b/rdagent/components/loader/task_loader.py @@ -47,7 +47,8 @@ def __init__(self, json_uri: str) -> None: def load(self, *argT, **kwargs) -> Sequence[ModelTask]: # json is supposed to be in the format of {model_name: dict{model_data}} - model_dict = json.load(open(self.json_uri, "r")) + with open(self.json_uri, "r", encoding="utf-8") as f: + model_dict = json.load(f) # FIXME: the model in the json file is not right due to extraction error # We should fix them case by case in the future #