fix(computer_use): pin subprocess text-mode encoding to utf-8 - #63795
fix(computer_use): pin subprocess text-mode encoding to utf-8#63795yuyzhen wants to merge 1 commit into
Conversation
On non-UTF-8 locales (e.g. Chinese Windows with GBK ANSI codepage),
subprocess.run(..., text=True) defaults to the system locale for
decoding the child's stdout/stderr. cua-driver emits UTF-8 (emoji,
Chinese paths, etc.), so the internal _readerthread crashes with a
cascade of UnicodeDecodeError exceptions like:
Exception in thread Thread-N (_readerthread):
...
File ".../subprocess.py", line 1599, in _readerthread
buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0x94 ...
The main return path still works (proc.stdout is populated up to the
failure point), but the tracebacks spam stderr on every capture and
mask real errors.
Pin encoding='utf-8', errors='replace' on every text-mode subprocess
call in the computer_use tool. doctor.py already had this fix.
Related: #60097 (otsune) fixes the same three |
|
Thanks for the focused Windows-locale fix. The premise remains present on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
|
Closing as resolved by PR #70875 (merged, commit 0f732cb), which closed out this bug class codebase-wide: every |
Problem
On non-UTF-8 locales (e.g. Chinese Windows where the ANSI codepage is GBK/CP936),
subprocess.run(..., text=True)without an explicitencoding=defaults to the system locale for decoding the child's stdout/stderr.cua-driveremits UTF-8 (emoji, Chinese paths, non-ASCII status), so the subprocess module's internal_readerthreadblows up with a cascade like:The main return path still works (partial stdout is captured up to the failure point), but the tracebacks spam stderr on every
computer_usecapture, mask real errors, and unsettle users on zh-CN Windows.Fix
Pin
encoding='utf-8', errors='replace'on every text-mode subprocess call in thecomputer_usetool:tools/computer_use/cua_backend.py_resolve_mcp_invocation(manifest discovery)cua_driver_update_check(check-update --json)_CuaDriverSessionCLI fallback spawntools/computer_use/permissions.py— the_runhelpertools/computer_use/doctor.pyalready hadencoding='utf-8'on itsPopen; this PR brings the rest in line.Verification
Before: on zh-CN Windows,
computer_use(action='capture', app='screen', mode='vision')returns a valid result but stderr fills with 3+UnicodeDecodeErrortracebacks.After (same host, same command): the capture returns cleanly, no background thread exceptions.
Notes
errors='replace'(notstrict) is deliberate: cua-driver's output is authoritative UTF-8, but on the unlikely chance of a mixed-encoding byte we prefer a replacement char over crashing a reader thread.encoding='utf-8'matches the default there.