fix: add explicit encoding="utf-8" to text-mode file opens - #51925
Closed
AlexFucuson9 wants to merge 1 commit into
Closed
AlexFucuson9 wants to merge 1 commit into
AlexFucuson9 wants to merge 1 commit into
Conversation
Three file-write call-sites used open()/os.fdopen() in text mode without specifying encoding. On systems where the locale default is not UTF-8 (e.g. C/POSIX on Linux servers, some Docker base images), non-ASCII characters in JSON payloads or env values would either raise UnicodeEncodeError or silently produce mojibake. - agent/nous_rate_guard.py: os.fdopen(fd, 'w') for JSON state dump - agent/shell_hooks.py: os.fdopen(fd, 'w') for JSON data write - gateway/slash_commands.py: open(exit_code_path, 'w') for exit code All sibling call-sites in the repo already pass encoding='utf-8' (hermes_cli/config.py via write_kw, utils.py atomic helpers, etc.), so these three are the only remaining gaps.
Contributor
Duplicate of #51406 — same three text-mode opens ( |
tonydwb
approved these changes
Jun 24, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Hermes Agent Review
Verdict: Approved — Clean, well-scoped change with appropriate tests.
Reviewed as part of batch review session 2026-06-24d.
Reviewed by Hermes Agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three file-write call-sites use
open()/os.fdopen()in text mode without specifyingencoding=. On systems where the locale default is not UTF-8 (e.g.C/POSIXlocale on Linux servers, minimal Docker base images, some CI environments), non-ASCII characters in JSON payloads or values would either raiseUnicodeEncodeErroror silently produce mojibake.Changes
agent/nous_rate_guard.pyos.fdopen(fd, "w")— writes JSON state withjson.dump()agent/shell_hooks.pyos.fdopen(fd, "w")— writes JSON data withjson.dumps()gateway/slash_commands.pyopen(exit_code_path, "w")— writes exit code integerFix: Add
encoding="utf-8"to each call-site.Context
All sibling call-sites in the repo already pass
encoding="utf-8":hermes_cli/config.pyuseswrite_kw = {"encoding": "utf-8"}for allos.fdopencallsutils.pyatomic helpers useencoding="utf-8"These three are the only remaining gaps.
Testing
python -c "import ast; ast.parse(open(\"f\").read())"on each modified file