Skip to content

fix(gateway): add explicit encoding to read_text/write_text calls - #51119

Closed
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix-gateway-encoding
Closed

fix(gateway): add explicit encoding to read_text/write_text calls#51119
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix-gateway-encoding

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Summary

Add explicit encoding='utf-8' to all read_text() and write_text() calls in gateway/.

Path.read_text() defaults to system locale (cp1252 on Windows), causing UnicodeDecodeError for UTF-8 JSON configs and user data.

Files changed (5 files, 25 calls)

File Calls
gateway/run.py 20
gateway/status.py 1
gateway/delivery.py 2
gateway/slash_commands.py 1
gateway/platforms/qqbot/adapter.py 1

Test plan

  • py_compile all 5 files - syntax OK
  • grep verification - only comment remaining

Ruff rule PLW1514.

Add encoding='utf-8' to all read_text() and write_text() calls in gateway/.
Path.read_text() defaults to system locale (cp1252 on Windows), causing
UnicodeDecodeError for UTF-8 JSON configs and user data.

Files changed:
- gateway/run.py (20 calls)
- gateway/status.py (1 call)
- gateway/delivery.py (2 calls)
- gateway/slash_commands.py (1 call)
- gateway/platforms/qqbot/adapter.py (1 call)

Ruff rule PLW1514.
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #50679 — byte-identical scope: adds encoding='utf-8' to the same 5 gateway/ files (run.py, status.py, delivery.py, slash_commands.py, qqbot adapter). #50679 is the earlier open PR. Part of the systemic encoding-guard rollout (#50655, #50660, #36828).

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for addressing the Windows-sensitive default-encoding behavior. The exact calls changed by this PR are still bare read_text()/write_text() calls on current main—for example gateway/run.py:3227 and gateway/delivery.py:360—so the underlying fix remains relevant.

Problems

  • The stated gateway-wide scope is incomplete: gateway/dead_targets.py:70 reads dead_targets.json without an encoding and gateway/dead_targets.py:85 writes it without one. Neither call is in this PR's diff.

Suggested changes

  • Include the two gateway/dead_targets.py persistence calls in the UTF-8 pass, or narrow the summary to the five-file slice.
  • Add a focused non-ASCII persistence regression test for an affected gateway state path.

The PR base predates substantial movement in these files, but the target calls remain present on current main. This is an automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing as resolved by PR #71078 (merged, commit d372fda): the class-wide close-out salvaged your #50655/#54241/#56385/#66856/#65440 series as the backbone (authorship preserved in git log) and swept the remaining sites, so every read_text/write_text call this PR touches is now guarded on current main — verified per-site. A CI linter rule in check-windows-footguns.py plus the AST guard test now prevent regressions. Your overlapping/split variants of the same series are being closed together; the credit for the class rests on your commits.

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

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades 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.

4 participants