Skip to content

fix(auth): specify UTF-8 encoding for auth.json read_text() calls - #69789

Closed
JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/auth-gbk-encoding
Closed

fix(auth): specify UTF-8 encoding for auth.json read_text() calls#69789
JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/auth-gbk-encoding

Conversation

@JonthanaHanh

Copy link
Copy Markdown
Contributor

Summary

On Windows with CJK usernames, locale.getpreferredencoding() returns GBK (or a similar multi-byte encoding). Path.read_text() without an explicit encoding argument uses the system default, so reading a UTF-8 encoded auth.json under a GBK locale raises UnicodeDecodeError, making auth completely broken for those users.

Root Cause

Three read_text() calls in hermes_cli/auth.py parse JSON files without specifying encoding="utf-8":

  • _load_auth_store() (line 1115) — the main auth.json loader
  • OAuth token reading (line 3704)
  • Nous auth store reading (line 5139)

Meanwhile, write_text() calls and lock file operations already correctly specify encoding="utf-8".

Fix

Add encoding="utf-8" to all three read_text() calls, matching the pattern already used elsewhere in the same file.

Fixes

Fixes #69706

On Windows with CJK usernames, locale.getpreferredencoding() returns
GBK (or similar). Path.read_text() without an explicit encoding uses
the system default, so reading a UTF-8 JSON file under a GBK locale
raises UnicodeDecodeError.

Add encoding="utf-8" to all three read_text() calls that parse
auth.json files, matching the pattern already used for write_text()
and lock file operations.

Fixes NousResearch#69706
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard area/auth Authentication, OAuth, credential pools platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows labels Jul 23, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing as redundant: the auth.json read sites this PR targets are already guarded on current main (hermes_cli/auth.py reads pass encoding="utf-8"), and the repo-wide bare read_text/write_text class was retired in PR #71078 (139 sites + CI linter rule). Verified per-site against main before closing. Thanks for the fix — the volume of independent PRs on this class is what escalated it to the campaign.

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

Labels

area/auth Authentication, OAuth, credential pools comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] auth: GBK codec fails to parse auth.json path when Windows username contains CJK characters

3 participants