Skip to content

fix: tolerate non-UTF-8 output from agent CLIs in text-mode subprocess calls - #71

Open
sjwauto123 wants to merge 1 commit into
AMAP-ML:mainfrom
sjwauto123:fix/windows-nonutf8-subprocess-decode
Open

fix: tolerate non-UTF-8 output from agent CLIs in text-mode subprocess calls#71
sjwauto123 wants to merge 1 commit into
AMAP-ML:mainfrom
sjwauto123:fix/windows-nonutf8-subprocess-decode

Conversation

@sjwauto123

Copy link
Copy Markdown

Summary

Fixes #64 — text-mode subprocess calls crash (or silently drop output) when an agent CLI emits GBK/ANSI bytes on zh-CN Windows.

Root cause

probe_agent_cli (and four other call sites) read external process output with text=True but no errors= handler. On zh-CN Windows, agent CLIs and helpers such as taskkill may emit GBK-encoded bytes while the harness decodes pipes as UTF-8 (system UTF-8 codepage enabled, or PYTHONUTF8=1). With two captured pipes this spawns two reader threads; both die with UnicodeDecodeError ('utf-8' codec can't decode byte 0xb4 in position 0: invalid start byte), the --version/--help probe returns nothing, and the run is misreported as provider_network / provider_model_unavailable.

Fix

Add errors="replace" to the five text-mode subprocess call sites that read external process output, so invalid bytes degrade to U+FFFD instead of crashing the reader thread:

  • src/lh_harness/utils/agent_cli.pyprobe_agent_cli (--version)
  • src/lh_harness/agent_registry.py_cli_help_text (--help)
  • src/lh_harness/model_catalog.py_codex_app_server_models (app-server Popen)
  • src/lh_harness/plugins/npm.py_tool_version and _run (2 sites)

adapters/deepseek_runner.py already passes errors="replace"; these five sites were missed.

Reproduction

A fake agent emitting the GBK bytes b4 f2 d3 a1 1.2.3\n (GBK for "版本", invalid as UTF-8):

  • Before: reader thread dies with UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 0: invalid start byte; probe_agent_cli returns usable=False ("no recognisable version").
  • After: probe_agent_cli returns usable=True, version="1.2.3".

Test

Adds tests/test_agent_cli.py with a regression test that probes a shell stub emitting a GBK banner and asserts the version is still parsed.

…s calls

On zh-CN Windows, agent CLIs (and Windows helpers such as taskkill) can
emit GBK/ANSI-encoded output while the harness decodes pipes as UTF-8
(system UTF-8 codepage or PYTHONUTF8=1). With capture_output/text=True
this spawns reader threads that die with UnicodeDecodeError, so the
--version/--help probe returns nothing and the failure is misattributed
to the provider.

Add errors="replace" to the five text-mode subprocess call sites that read
external process output, so invalid bytes degrade to U+FFFD instead of
crashing the reader thread. deepseek_runner already passes errors="replace";
these sites were missed.

Fixes AMAP-ML#64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: agent CLI output in ANSI/GBK codepage crashes subprocess reader threads (fix: errors="replace")

1 participant