Skip to content

fix: add explicit encoding="utf-8" to text-mode file opens - #51925

Closed
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/encoding-missing-utf8
Closed

AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/encoding-missing-utf8

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Summary

Three file-write call-sites use open() / os.fdopen() in text mode without specifying encoding=. On systems where the locale default is not UTF-8 (e.g. C/POSIX locale on Linux servers, minimal Docker base images, some CI environments), non-ASCII characters in JSON payloads or values would either raise UnicodeEncodeError or silently produce mojibake.

Changes

File Line Issue
agent/nous_rate_guard.py L120 os.fdopen(fd, "w") — writes JSON state with json.dump()
agent/shell_hooks.py L630 os.fdopen(fd, "w") — writes JSON data with json.dumps()
gateway/slash_commands.py L4037 open(exit_code_path, "w") — writes exit code integer

Fix: Add encoding="utf-8" to each call-site.

Context

All sibling call-sites in the repo already pass encoding="utf-8":

  • hermes_cli/config.py uses write_kw = {"encoding": "utf-8"} for all os.fdopen calls
  • utils.py atomic helpers use encoding="utf-8"
  • Various other modules follow the same pattern

These three are the only remaining gaps.

Testing

  • Verified with python -c "import ast; ast.parse(open(\"f\").read())" on each modified file
  • No new lint/type errors introduced

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.
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have duplicate This issue or pull request already exists labels Jun 24, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Duplicate of #51406 — same three text-mode opens (agent/nous_rate_guard.py, agent/shell_hooks.py, gateway/slash_commands.py) get the identical encoding="utf-8" fix. #51406 is the earlier open PR with the same scope; #51766 is a broader superset (adds the hermes_cli/config.py sites).

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants