fix(gateway): decode schtasks output defensively on Windows - #36033
fix(gateway): decode schtasks output defensively on Windows#36033konsisumer wants to merge 1 commit into
Conversation
hermes gateway status/restart spawned a UnicodeDecodeError traceback in subprocess's reader thread when schtasks emitted localized (cp936/GBK) console bytes under a UTF-8 ambient locale (git-bash/MSYS). Pin the decode to encoding=utf-8, errors=replace so the command stays quiet, matching the pattern already used by find_gateway_pids(). Refs NousResearch#34083
|
+1 — Reproduced and verified on Chinese Windows 10 (Python 3.11, git-bash). One additional finding: the I patched both Also worth noting: the missing |
|
Closing — it looks like #38334 (merged) addresses the same change. If that's incorrect, feel free to reopen and ping me. |
What does this PR do?
This fixes the third defect reported in #34083: on native Windows,
hermes gateway status(and thestop/restartpaths) printed an alarmingUnicodeDecodeErrortraceback from a background subprocess reader thread, even though the command itself succeeded:The noise comes from
_exec_schtasks()inhermes_cli/gateway_windows.py. It ranschtasks.exewithsubprocess.run(..., text=True)but no explicitencoding/errors.schtasksemits text in the console's localized code page (e.g. cp936/GBK on Chinese Windows). When the ambient locale resolves to UTF-8 — common under git-bash/MSYS, the reporter's setup — Python's reader thread decodes those bytes with strict UTF-8 and raises, spamming a traceback on an otherwise-successful command.The fix pins the decode to
encoding="utf-8", errors="replace", the same defensive pattern already used byfind_gateway_pids()inhermes_cli/gateway.py. The ASCII keys the status parser reads (status,last run result,last run time) are unaffected; only localized free-text degrades toU+FFFDinstead of crashing.Scope note (the other two bugs in #34083)
#34083 bundles three Windows defects. This PR intentionally addresses only the decode bug, so it uses
Refsrather than a closing trailer:plugins/web/ddgs: already resolved onmain.plugins/web/ddgs/plugin.yamlnow ships (since the ddgs migration), and the bundled-plugin scanner already recurses one level into category dirs likeweb/(_scan_directory_level), discovering it as keyweb/ddgs. The reporter was on a site-packages release that predates this. No code change needed.gateway restartexits with0xC000013A(STATUS_CONTROL_C_EXIT): appears to be a consoleCTRL_C_EVENTreaching the CLI process duringschtasks /End//Run. The likely fix is a transientSetConsoleCtrlHandler/SIG_IGNguard around the restart (mirroring the gateway-run absorber). That is a Windows-only signal-handling change I cannot exercise or verify on this (macOS) worker, so I am deferring it to a separate, Windows-verified PR rather than ship an unverified signal change. This remaining work is why Windows: three bugs from daily use (plugin discovery, gateway exit code, Unicode decode #34083 stays open.Related Issue
Refs #34083
Type of Change
Changes Made
hermes_cli/gateway_windows.py:_exec_schtasks()now passesencoding="utf-8", errors="replace"tosubprocess.run, so localized schtasks console output can never raiseUnicodeDecodeErrorin the reader thread.tests/hermes_cli/test_gateway_windows.py: addedtest_exec_schtasks_decodes_defensively, asserting the schtasks subprocess call is made with the defensive decode kwargs.How to Test
pytest tests/hermes_cli/test_gateway_windows.py -q(30 passed locally).pytest tests/hermes_cli/test_gateway_windows.py tests/hermes_cli/test_gateway.py tests/gateway/test_status.py tests/gateway/test_status_command.py -q(131 passed locally).hermes gateway statusprinted aUnicodeDecodeError/Exception in thread Thread-7 (_readerthread)traceback while still reporting the gateway state; after the fix the command output is clean.What platforms tested on
_assert_windowsno-op + patchedsubprocess.run), so it runs and verifies the fix on any platform.schtaskspath on this worker. The fix is a contained, behavior-preserving decode change matching an existing in-tree pattern; no POSIX code path is touched.Checklist
Code
fix(gateway):)pytestslice and all tests pass (targeted gateway/status tests, 131 passed)Documentation & Housekeeping
cli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/Ascripts/check-windows-footguns.pyclean; POSIX paths untouched