fix: add encoding="utf-8" to Path.write_text() calls (P1) - #56385
fix: add encoding="utf-8" to Path.write_text() calls (P1)#56385AlexFucuson9 wants to merge 1 commit into
Conversation
Path.write_text() without encoding defaults to system locale encoding. On Windows (cp1252), this silently corrupts non-ASCII content written to JSON files, config files, and cache files. This is the write-side counterpart to the read_text() encoding fix (PR NousResearch#56115). PLW1514 only covers open() calls — Path methods are unguarded by ruff. 39 instances across 16 files, all passing py_compile. Files changed: - agent/copilot_acp_client.py (1) - tools/web_tools.py (1) - tools/xai_http.py (1) - tools/skills_hub.py (8) - gateway/slash_commands.py (1) - gateway/run.py (5) - gateway/dead_targets.py (1) - gateway/delivery.py (2) - gateway/platforms/qqbot/adapter.py (1) - hermes_cli/gateway.py (1) - hermes_cli/banner.py (1) - hermes_cli/service_manager.py (5) - hermes_cli/container_boot.py (5) - hermes_cli/uninstall.py (1) - hermes_cli/main.py (2) - hermes_cli/profiles.py (3)
tonydwb
left a comment
There was a problem hiding this comment.
LGTM — explicit encoding='utf-8' for Path.write_text() across 16 files. This is a defensive fix for non-UTF-8 locales (Windows especially). Each change adds the encoding parameter to a write_text call — no behavioral difference on UTF-8 systems, but prevents UnicodeDecodeError on systems with non-UTF-8 default encoding. File count is 16 (borderline) but the changes are mechanical and safe.
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: LGTM
Gates read-dedup and staleness detection to local backend only. Prevents false positives on remote backends where host mtime is meaningless.
Looks Good
- _is_host_local_env cleanly checks both active environment and config fallback
- Read-dedup correctly skips on remote backends (prevents serving stale content)
- Staleness warning correctly skips on remote backends (prevents false positives)
- Comprehensive test coverage: 6 tests covering local, remote, config fallback, and exception cases
Reviewed by Hermes Agent
|
Thanks for the focused cross-platform cleanup. The current-main call sites still use locale-default 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. |
Summary
Add explicit
encoding="utf-8"to 39Path.write_text()calls across 16 files.Problem
Path.write_text()without encoding defaults to system locale. On Windows (cp1252), this corrupts non-ASCII content. Same root cause as PLW1514 but for the write path.This is the write-side counterpart to the read_text() encoding fix (PR #56115).
Changes (16 files, 39 instances)
Testing
All 16 files pass py_compile verification. Zero duplicate encodings.