Skip to content

fix(windows): force utf8 for detached gateway - #60832

Closed
embwl0x wants to merge 1 commit into
NousResearch:mainfrom
embwl0x:agent/fix-windows-detached-gateway-utf8
Closed

fix(windows): force utf8 for detached gateway#60832
embwl0x wants to merge 1 commit into
NousResearch:mainfrom
embwl0x:agent/fix-windows-detached-gateway-utf8

Conversation

@embwl0x

@embwl0x embwl0x commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #60760.

Summary

  • force PYTHONUTF8=1 alongside PYTHONIOENCODING=utf-8 for detached Windows gateway child environments
  • cover Scheduled Task .cmd and .vbs launchers, direct detached gateway argv, and post-update windowless restart specs
  • make _ensure_utf8() set UTF-8 child env defaults on Windows even when pythonw has no stdio streams to repair

Root Cause

Detached Windows gateways can run under pythonw with sys.stdout and sys.stderr set to None, so _ensure_utf8() had no stream to repair and never exported UTF-8 defaults for child processes. When a spawned child emitted UTF-8 text under a legacy ANSI locale such as GBK, Python's subprocess pipe reader could decode with the preferred locale and raise UnicodeDecodeError.

Tests

  • uv run --extra dev pytest tests/hermes_cli/test_ensure_utf8_locale.py tests/hermes_cli/test_gateway_windows.py tests/tools/test_windows_native_support.py::TestWindowlessGatewayRestartSpec -q
  • uv run --extra dev pytest tests/tools/test_windows_native_support.py -q

Safety

  • new commit range scanned with gitleaks git --log-opts='origin/main..HEAD' --redact .: no leaks found

@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows P2 Medium — degraded but workaround exists labels Jul 8, 2026

@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.

Code Review Summary

Verdict: Approved (LGTM)

Forces PYTHONUTF8=1 alongside PYTHONIOENCODING=utf-8 for detached Windows gateway child environments. Covers Scheduled Task .cmd/.vbs launchers, direct detached argv, and post-update windowless restart specs.

Changes

  • hermes_cli/init.py: _ensure_utf8() sets UTF-8 child env defaults on Windows even when pythonw has no stdio streams
  • hermes_cli/gateway_windows.py: export PYTHONUTF8=1
  • Tests: test_ensure_utf8_locale.py, test_gateway_windows.py, test_windows_native_support.py

Quality

  • 5 files, 37 additions / 5 deletions
  • Tests: all specified test suites pass
  • Gitleaks clean

Reviewed by Hermes Agent

@embwl0x
embwl0x force-pushed the agent/fix-windows-detached-gateway-utf8 branch from f64fb57 to b5faebc Compare July 10, 2026 09:19
@embwl0x
embwl0x marked this pull request as ready for review July 10, 2026 09:19
@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 10, 2026
@embwl0x
embwl0x force-pushed the agent/fix-windows-detached-gateway-utf8 branch from b5faebc to c35d202 Compare July 23, 2026 22:33
@teknium1

Copy link
Copy Markdown
Contributor

Closing as superseded: the detached-gateway decode crash class was fixed on main by PRs #70850/#70875 (subprocess text-mode decode, incl. gateway_windows.py) and #71014 (bootstrap-level PYTHONUTF8 + platform._syscmd_ver stub in every entry point, desktop spawn env). The specific sites this PR touches are guarded on current main. Verified before closing. Thanks!

@teknium1 teknium1 closed this Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/windows Native Windows-specific behavior or breakage 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.

[Windows] Detached gateway crashes with UnicodeDecodeError: 'gbk' when a spawned child process emits UTF-8 output

4 participants