Fix/windows subprocess encoding - #52859
Conversation
lowercase 'any' is Python's builtin function, not a type. Adds Any to the typing import and corrects the annotation. Fixes NousResearch#2139
On Windows with non-UTF-8 locales (e.g. Chinese GBK/CP936), subprocess calls using text=True default to the system encoding. When a subprocess outputs UTF-8 characters, the internal _readerthread crashes, causing output pipe stalls, event loop blocks, and gateway restarts. Add explicit encoding="utf-8", errors="replace" to all text-mode subprocess calls in tui_gateway to prevent this. Fixes NousResearch#52846 Co-Authored-By: Ulaganathan K.B <<EMAIL>>
|
teknium1
left a comment
There was a problem hiding this comment.
Thanks for identifying the Windows text-decoding failure class. The five text=True subprocess paths in current tui_gateway/server.py still omit explicit decoding: _SlashWorker at tui_gateway/server.py:314-325, PDF attach at :9723-9726, cli.exec at :11796-11806, quick-command exec at :11865-11873, and shell.exec at :14416-14419.
Problems
tui_gateway/git_probe.py:52-61already hasencoding="utf-8"anderrors="replace"on current main, so that PR hunk is stale.toolset_distributions.py:214is an unrelated type-hint cleanup and should not be bundled with this Windows fix.- The PR contains no regression tests.
tests/tui_gateway/test_slash_worker_profile_home.py:16-35already mockssubprocess.Popenand is a suitable place to assert the decoding kwargs; analogous RPC-path assertions should cover thesubprocess.runcall sites.
Suggested changes
- During salvage, retain only the five still-needed
tui_gateway/server.pyedits, omit the already-landedgit_probe.pyhunk, and split out the annotation cleanup. - Add focused mock assertions for
encoding="utf-8"anderrors="replace".
Automated hermes-sweeper review.
| @@ -214,7 +214,7 @@ | |||
| } | |||
There was a problem hiding this comment.
This annotation correction is unrelated to the Windows subprocess-encoding fix. Please keep it in a separate focused change so this PR can be salvaged narrowly.
|
Closing as resolved by PR #70875 (merged, commit 0f732cb), which closed out this bug class codebase-wide: every |
On Windows with non-UTF-8 locales (e.g. Chinese GBK/CP936), subprocess.Popen/subprocess.run(text=True) defaults to the system encoding. When a subprocess outputs UTF-8 characters (e.g. Chinese text), the internal _readerthread crashes, causing output pipe stalls, event loop blocks, WebSocket write timeouts, and gateway restarts. Error logs showed 1,830 identical crash entries.
This PR adds explicit encoding="utf-8", errors="replace" to all text-mode subprocess calls in tui_gateway/ so the output is decoded as UTF-8 regardless of the system locale. Invalid bytes are replaced with the Unicode replacement character instead of crashing.
Related Issue
Fixes #52846
Type of Change
Changes Made
How to Test
Checklist
Code
Documentation & Housekeeping