fix: add explicit UTF-8 encoding to all subprocess text=True calls (#53428) - #55339
fix: add explicit UTF-8 encoding to all subprocess text=True calls (#53428)#55339Stoltemberg wants to merge 1 commit into
Conversation
Related: #53428 (master tracker) and #52249 (the focused open sibling fixing the same GBK/CP936 subprocess-encoding crash). This PR is the broadest rollout in that family. Heads-up for reviewers: the diff is not subprocess-encoding-only. Beyond the |
|
@christian-byrne Tagging you on this ComfyUI item.
|
tonydwb
left a comment
There was a problem hiding this comment.
COMMENT: High surface area (147 files, +670/-472). The encoding fix (adding encoding=utf-8, errors=replace to subprocess calls) is well-motivated and consistent. However, the credential_pool.py addition (sanitize_credential_input on add_entry) is a separate security concern bundled into the same PR. Recommend splitting: (1) the encoding fix across 146 files is mechanical and safe, (2) the credential sanitization in credential_pool.py should be its own PR for focused review. The two changes address different failure modes and have different risk profiles.
…ousResearch#53428) On Windows with Chinese locale (GBK), subprocess.run(text=True) without explicit encoding causes UnicodeDecodeError crashes. This fix adds encoding='utf-8', errors='replace' to all subprocess.run() and subprocess.Popen() calls that use text=True across 76 non-test Python files. Fixes NousResearch#53428 (master tracker for Windows GBK locale crash). Note: credential_pool.py and electron changes excluded per reviewer request — those will be submitted as separate focused PRs.
5f97c1e to
3e75bd9
Compare
|
Thanks for the review! I've addressed your feedback: Changes Made
VerificationAll changes are mechanical |
Code Review SummaryVerdict: Comment — high surface area, human review recommended This is a large mechanical change across 76 files adding explicit UTF-8 encoding to subprocess text=True calls. While each individual change is simple and correct, the sheer number of files warrants human review to ensure no unintended behavioral changes.
|
…esearch#53428) PR NousResearch#55339 adds encoding='utf-8', errors='replace' to 26 subprocess.run(text=True) call sites across the codebase. The triage review (thanks @alt-glitch) diffed this PR against NousResearch#55339 and found that 5 of the 6 originally-touched call sites are already covered there byte-identically: - hermes_cli/main.py::_probe_container - hermes_cli/setup.py SSH probe - tools/tts_tool.py::_generate_neutts - tools/transcription_tools.py::_prepare_local_audio - tools/transcription_tools.py::_transcribe_local_command (both branches) The one genuinely net-new site — hermes_cli/onepassword_secrets_cli.py::_op_whoami (the 1Password op CLI whoami probe) — is NOT in NousResearch#55339 and is fixed here. Without explicit encoding=, text=True decodes child output with locale.getpreferredencoding(False) — cp936 on Chinese Windows — which crashes _readerthread on non-GBK bytes, cascading into pipe buffer fills, event loop stalls, and TUI freezes (issues NousResearch#47939, NousResearch#53428, NousResearch#57238). Scope narrowed per triage feedback: the other 5 sites should land via NousResearch#55339. Refs NousResearch#53428 (together with NousResearch#55339).
|
Merged via PR #70875 — your commit was cherry-picked onto current main with your authorship preserved in git log (rebase merge). Thanks for the original codebase-wide sweep; it was the base of the class-closing PR. Your 61-site commit was de-conflicted against three weeks of main drift, and the salvage PR extended it with the remaining ~136 sites that had landed since, plus @jinglun010-cpu's linter rule (#60751) so the bug class can't regress. Credit noted in the PR body. |
…esearch#53428) PR NousResearch#55339 adds encoding='utf-8', errors='replace' to 26 subprocess.run(text=True) call sites across the codebase. The triage review (thanks @alt-glitch) diffed this PR against NousResearch#55339 and found that 5 of the 6 originally-touched call sites are already covered there byte-identically: - hermes_cli/main.py::_probe_container - hermes_cli/setup.py SSH probe - tools/tts_tool.py::_generate_neutts - tools/transcription_tools.py::_prepare_local_audio - tools/transcription_tools.py::_transcribe_local_command (both branches) The one genuinely net-new site — hermes_cli/onepassword_secrets_cli.py::_op_whoami (the 1Password op CLI whoami probe) — is NOT in NousResearch#55339 and is fixed here. Without explicit encoding=, text=True decodes child output with locale.getpreferredencoding(False) — cp936 on Chinese Windows — which crashes _readerthread on non-GBK bytes, cascading into pipe buffer fills, event loop stalls, and TUI freezes (issues NousResearch#47939, NousResearch#53428, NousResearch#57238). Scope narrowed per triage feedback: the other 5 sites should land via NousResearch#55339. Refs NousResearch#53428 (together with NousResearch#55339).
…debase-wide AST-driven pass over every subprocess.run/Popen/check_output/check_call/call with text=True (or universal_newlines=True) and no explicit encoding=: append encoding='utf-8', errors='replace' at the kwarg site. 136 call sites across 28 files (cli.py, hermes_cli/main.py, tools_config.py, environments, computer_use, gateway, scripts, skills helpers, agent/*). Together with the salvaged NousResearch#55339/NousResearch#60741 commits this closes out issue NousResearch#53428's bug class; the salvaged NousResearch#60751 linter rule in check-windows-footguns.py now enforces it repo-wide (verified: 807 files scanned, zero findings).
… call sites, kwarg-snapshot tests - Strip the salvaged commit's inline encoding kwargs where main had since gained its own (process_registry, local env, cua doctor, gateway, commands, gateway_windows — the latter keeps its locale-aware _schtasks_encoding() from NousResearch#38186) - Revert encoding kwargs mistakenly applied to non-subprocess APIs (exa get_contents, tempfile.mkstemp in webhook.py) - Guard the ddgs worker Popen (new on main since NousResearch#55339) - Update two kwarg-snapshot test assertions for the new kwargs
…esearch#53428) PR NousResearch#55339 adds encoding='utf-8', errors='replace' to 26 subprocess.run(text=True) call sites across the codebase. The triage review (thanks @alt-glitch) diffed this PR against NousResearch#55339 and found that 5 of the 6 originally-touched call sites are already covered there byte-identically: - hermes_cli/main.py::_probe_container - hermes_cli/setup.py SSH probe - tools/tts_tool.py::_generate_neutts - tools/transcription_tools.py::_prepare_local_audio - tools/transcription_tools.py::_transcribe_local_command (both branches) The one genuinely net-new site — hermes_cli/onepassword_secrets_cli.py::_op_whoami (the 1Password op CLI whoami probe) — is NOT in NousResearch#55339 and is fixed here. Without explicit encoding=, text=True decodes child output with locale.getpreferredencoding(False) — cp936 on Chinese Windows — which crashes _readerthread on non-GBK bytes, cascading into pipe buffer fills, event loop stalls, and TUI freezes (issues NousResearch#47939, NousResearch#53428, NousResearch#57238). Scope narrowed per triage feedback: the other 5 sites should land via NousResearch#55339. Refs NousResearch#53428 (together with NousResearch#55339).
…debase-wide AST-driven pass over every subprocess.run/Popen/check_output/check_call/call with text=True (or universal_newlines=True) and no explicit encoding=: append encoding='utf-8', errors='replace' at the kwarg site. 136 call sites across 28 files (cli.py, hermes_cli/main.py, tools_config.py, environments, computer_use, gateway, scripts, skills helpers, agent/*). Together with the salvaged NousResearch#55339/NousResearch#60741 commits this closes out issue NousResearch#53428's bug class; the salvaged NousResearch#60751 linter rule in check-windows-footguns.py now enforces it repo-wide (verified: 807 files scanned, zero findings).
… call sites, kwarg-snapshot tests - Strip the salvaged commit's inline encoding kwargs where main had since gained its own (process_registry, local env, cua doctor, gateway, commands, gateway_windows — the latter keeps its locale-aware _schtasks_encoding() from NousResearch#38186) - Revert encoding kwargs mistakenly applied to non-subprocess APIs (exa get_contents, tempfile.mkstemp in webhook.py) - Guard the ddgs worker Popen (new on main since NousResearch#55339) - Update two kwarg-snapshot test assertions for the new kwargs
…esearch#53428) PR NousResearch#55339 adds encoding='utf-8', errors='replace' to 26 subprocess.run(text=True) call sites across the codebase. The triage review (thanks @alt-glitch) diffed this PR against NousResearch#55339 and found that 5 of the 6 originally-touched call sites are already covered there byte-identically: - hermes_cli/main.py::_probe_container - hermes_cli/setup.py SSH probe - tools/tts_tool.py::_generate_neutts - tools/transcription_tools.py::_prepare_local_audio - tools/transcription_tools.py::_transcribe_local_command (both branches) The one genuinely net-new site — hermes_cli/onepassword_secrets_cli.py::_op_whoami (the 1Password op CLI whoami probe) — is NOT in NousResearch#55339 and is fixed here. Without explicit encoding=, text=True decodes child output with locale.getpreferredencoding(False) — cp936 on Chinese Windows — which crashes _readerthread on non-GBK bytes, cascading into pipe buffer fills, event loop stalls, and TUI freezes (issues NousResearch#47939, NousResearch#53428, NousResearch#57238). Scope narrowed per triage feedback: the other 5 sites should land via NousResearch#55339. Refs NousResearch#53428 (together with NousResearch#55339).
…debase-wide AST-driven pass over every subprocess.run/Popen/check_output/check_call/call with text=True (or universal_newlines=True) and no explicit encoding=: append encoding='utf-8', errors='replace' at the kwarg site. 136 call sites across 28 files (cli.py, hermes_cli/main.py, tools_config.py, environments, computer_use, gateway, scripts, skills helpers, agent/*). Together with the salvaged NousResearch#55339/NousResearch#60741 commits this closes out issue NousResearch#53428's bug class; the salvaged NousResearch#60751 linter rule in check-windows-footguns.py now enforces it repo-wide (verified: 807 files scanned, zero findings).
… call sites, kwarg-snapshot tests - Strip the salvaged commit's inline encoding kwargs where main had since gained its own (process_registry, local env, cua doctor, gateway, commands, gateway_windows — the latter keeps its locale-aware _schtasks_encoding() from NousResearch#38186) - Revert encoding kwargs mistakenly applied to non-subprocess APIs (exa get_contents, tempfile.mkstemp in webhook.py) - Guard the ddgs worker Popen (new on main since NousResearch#55339) - Update two kwarg-snapshot test assertions for the new kwargs
What does this PR do?
Fixes #53428 — adds explicit
encoding='utf-8', errors='replace'to allsubprocess.run()andsubprocess.Popen()calls that usetext=Trueacross 146 non-test Python files.Related Issue
Fixes #53428 (master tracker for Windows GBK locale crash)
Type of Change
Changes Made
encoding='utf-8', errors='replace'to everysubprocess.run(text=True)call in non-test filesmerge_text=Trueparameters (different API)encoding=values where already specifiedHow to Test
hermesand exercise any tool that spawns subprocessesUnicodeDecodeErrorcrashes occurPlatforms Tested
Checklist