fix(core,cli,gateway,plugins): add encoding='utf-8' to read_text() calls - #54241
fix(core,cli,gateway,plugins): add encoding='utf-8' to read_text() calls#54241AlexFucuson9 wants to merge 1 commit into
Conversation
Path.read_text() without an explicit encoding uses the platform's
default encoding. On Windows this is typically cp1252 or mbcs, which
causes UnicodeDecodeError or silent data corruption when reading
UTF-8 content (JSON files, user text, config with non-ASCII chars).
This is the read-side companion to the write_text() encoding fix.
Fixed the most critical locations that read JSON data, user content,
and config files across 14 files with 31 call sites.
Pattern: .read_text() → .read_text(encoding='utf-8')
json.loads(path.read_text()) → json.loads(path.read_text(encoding='utf-8'))
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Mechanical fix adding explicit encoding='utf-8' to read_text() calls across core modules (7+ files). This is a correct cross-platform fix -- on Windows, read_text() without explicit encoding uses the system default (often cp1252), which can corrupt non-ASCII content.
Strengths:
- Consistent application across all identified call sites
- No behavioral change on Unix (UTF-8 is already the default)
- Prevents UnicodeDecodeError on Windows with non-ASCII config/session files
- Well-scoped to
read_text()calls that parse JSON
No concerns.
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: LGTM
Mechanical change adding encoding='utf-8' to read_text() calls across 14 files. All changes are identical pattern: .read_text() -> .read_text(encoding='utf-8'). This ensures consistent encoding behavior across platforms (Windows in particular). No logic changes.
Reviewed by Hermes Agent
|
Thanks for the focused Windows-compatibility cleanup. The underlying issue is still present on current main, but the current patch is incomplete against HEAD. Problems
Suggested changes
Automated hermes-sweeper review. |
|
Merged via PR #71078 — your commit was cherry-picked onto current main with your authorship preserved in git log (rebase merge). Your 5-PR series (#50655 was authored under your earlier account, #54241, #56385, #66856, #65440) formed the backbone of the class-wide close-out: 68 of the 139 bare sites came from your commits, and the campaign's structure followed your directory-by-directory split. The remaining 71 sites were swept on top and a CI linter rule now prevents regressions. Thanks for the sustained, methodical work on this class. |
Problem
Path.read_text()without an explicitencodingparameter uses the platform's default encoding. On Windows this is typicallycp1252ormbcs, which causesUnicodeDecodeErroror silent data corruption when reading UTF-8 content.This is the read-side companion to PR #54240 (write_text encoding fix). Files written with
encoding="utf-8"must also be read withencoding="utf-8"to be cross-platform safe.Scope
31
read_text()call sites across 14 files, covering:tools/skills_hub.pyensure_ascii=False)hermes_cli/auth.pyhermes_cli/profiles.pyhermes_cli/uninstall.pyhermes_cli/main.pyhermes_cli/doctor.pygateway/run.pyagent/auxiliary_client.pyagent/copilot_acp_client.pyagent/shell_hooks.pyplugins/memory/mem0/__init__.pyplugins/memory/hindsight/__init__.pyplugins/memory/honcho/__init__.pyplugins/platforms/google_chat/oauth.pyFix
Impact