Skip to content

fix(gateway): handle wmic encoding errors on Windows non-English locales#17252

Closed
Kailigithub wants to merge 1 commit into
NousResearch:mainfrom
Kailigithub:fix/windows-wmic-encoding-gateway-pids
Closed

fix(gateway): handle wmic encoding errors on Windows non-English locales#17252
Kailigithub wants to merge 1 commit into
NousResearch:mainfrom
Kailigithub:fix/windows-wmic-encoding-gateway-pids

Conversation

@Kailigithub

Copy link
Copy Markdown
Contributor

Summary

Fix UnicodeDecodeError and cascading AttributeError in Windows gateway process scanning on non-English locales.

Problem

On Windows systems with non-English locales, wmic outputs text in the system code page (e.g. cp936 for Chinese, cp1252 for Western European) rather than UTF-8. When Python's subprocess.run decodes the output as UTF-8, a UnicodeDecodeError is raised in the reader thread, causing result.stdout to become None. This produces two cascading failures:

  1. UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 8177 in the subprocess reader thread
  2. AttributeError: 'NoneType' object has no attribute 'split' in _scan_gateway_pids

Fix

  • Pass encoding='utf-8' and errors='ignore' explicitly to subprocess.run so undecodable bytes are silently skipped rather than raising
  • Add a None guard on result.stdout before calling .split() so the function returns an empty list cleanly instead of crashing

Testing

  • Syntax validation: python3 -m py_compile hermes_cli/gateway.py passes
  • No existing test coverage for Windows wmic path — the fix is defensive and non-breaking (adding encoding/errors to subprocess.run with non-Windows platforms has no effect; the None guard is a safe idempotent check)

Closes #17049.

On Windows systems with non-English locales, wmic outputs text in the
system code page (e.g. cp936 for Chinese) rather than UTF-8. When
Python decodes the output as UTF-8, a UnicodeDecodeError is raised in
the subprocess reader thread, leaving result.stdout as None. This
causes two cascading failures:
- UnicodeDecodeError in the reader thread
- AttributeError: 'NoneType' object has no attribute 'split'

Fix by explicitly passing encoding='utf-8' and errors='ignore' to
subprocess.run, and adding a None guard on result.stdout before
splitting. Closes NousResearch#17049.
@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 labels Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix for #17049 alongside #17074 and #17123. Note #17073 (also competing) was already closed. Maintainer should pick one. This PR only patches hermes_cli/gateway.py; #17123 patches the second call site in hermes_cli/main.py.

@teknium1

Copy link
Copy Markdown
Contributor

Merged via #17435 (#17435) alongside @briandevans's companion fix for the same bug in hermes_cli/main.py. Your commit was cherry-picked with your authorship preserved (rebase-merge). Thanks for the fix!

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 P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: UnicodeDecodeError and AttributeError in Windows gateway process scanning

4 participants