Skip to content

fix(loader): close model task JSON file and read it as UTF-8#1422

Open
genisis0x wants to merge 1 commit into
microsoft:mainfrom
genisis0x:fix/model-task-loader-utf8
Open

fix(loader): close model task JSON file and read it as UTF-8#1422
genisis0x wants to merge 1 commit into
microsoft:mainfrom
genisis0x:fix/model-task-loader-utf8

Conversation

@genisis0x
Copy link
Copy Markdown

@genisis0x genisis0x commented May 29, 2026

Description

ModelTaskLoaderJson.load (rdagent/components/loader/task_loader.py) read the model JSON via json.load(open(self.json_uri, "r")). That has two problems:

  1. The file handle is never closed (leaked until GC).
  2. No explicit encoding, so the read falls back to the platform default — cp1252 / gbk on Windows.

Model definition JSON can carry non-ASCII content, and JSON is UTF-8 by default per RFC 8259 §8.1, so on a non-UTF-8 locale the load raises UnicodeDecodeError.

Change

Wrap the read in a with context manager and pin encoding="utf-8". Closes the handle deterministically and makes the read locale-independent. No behavior change on UTF-8 locales.

Testing

json.load of a model JSON containing non-ASCII content now succeeds independent of locale.getpreferredencoding(); the file handle is released on block exit.


📚 Documentation preview 📚: https://RDAgent--1422.org.readthedocs.build/en/1422/

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant