Skip to content

[Bug]: UnicodeDecodeError in copilot_acp_client.py _stdout_reader on Windows #45140

Closed

Description

@ar27111994

Bug Description

On Windows, Hermes crashes when the copilot ACP subprocess emits UTF-8 characters (e.g. emojis). The _stdout_reader thread in agent/copilot_acp_client.py errors with a UnicodeDecodeError because of how the subprocess pipes are opened and decoded. Popen is called with text=True but without encoding, so Python uses the system codepage (cp1252), which cannot decode certain UTF-8 bytes.

Steps to Reproduce

  1. On Windows, run Hermes with the Copilot provider configured (default).
  2. Trigger image analysis or any flow that prints emoji or non-Latin characters (Hermes prints '👁️ analyzing ...' during vision analysis).
  3. Hermes crashes with UnicodeDecodeError in copilot_acp_client.py _stdout_reader when iterating over proc.stdout.

Expected Behavior

The subprocess stdout/stderr pipes should be read as UTF-8 regardless of Windows locale. If the Copilot CLI uses UTF-8 output, Hermes must use encoding='utf-8' when opening the pipes to avoid crashes. The _stdout_reader loop should gracefully handle invalid bytes if necessary (errors='replace' or similar).

Actual Behavior

UnicodeDecodeError in copilot_acp_client.py at the _stdout_reader loop when iterating over proc.stdout. Example traceback:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 7040: character maps to <undefined>

Affected Component

CLI (interactive chat), Other

Messaging Platform (if gateway-related)

N/A (CLI only)

Debug Report

Report       https://paste.rs/6Do1r
agent.log    https://paste.rs/HAbf0
gateway.log  https://paste.rs/elTP6
desktop.log   https://paste.rs/TzuhE

Operating System

Windows_NT x64 10.0.26200

Python Version

3.14.3

Hermes Version

Hermes Agent v0.16.0 (2026.6.5) · upstream d62979a
Project: C:\Users\ar271\AppData\Local\hermes\hermes-agent
Python: 3.11.15
OpenAI SDK: 2.24.0

Additional Logs / Traceback (optional)

I can provide additional logs if helpful; the debug report links above contain the full agent.log and gateway logs.

Root Cause Analysis (optional)

The root cause is an encoding mismatch when spawning the Copilot ACP subprocess. In agent/copilot_acp_client.py, the subprocess is started with text=True but without an explicit encoding argument, so Python uses the platform default encoding (CP1252 on many Windows systems). When the Copilot CLI emits UTF-8 bytes (for example, emojis or other characters outside CP1252), the stdout reader attempts to decode those bytes with CP1252 and raises UnicodeDecodeError.

Concretely, the problematic call is in _run_prompt, where the process is created like:

proc = subprocess.Popen(..., text=True, ...)

The fix is to pass an explicit encoding (e.g. encoding='utf-8') or to read the streams in binary and decode with an error-safe strategy (e.g. errors='replace') so that non-decodable bytes do not crash the reader thread.

Proposed Fix (optional)

Add encoding='utf-8' to the subprocess.Popen call in _run_prompt (agent/copilot_acp_client.py line ~440). Optionally set errors='replace' or decode manually to avoid crashes on invalid bytes. Workaround: set PYTHONUTF8=1 in the environment.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Activity

  1. added
    type/bugSomething isn't working
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    comp/acpAgent Communication Protocol adapter
    P2Medium — degraded but workaround exists
    on Jun 12, 2026
  2. teknium1 commented on Jul 24, 2026

    @teknium1
    Collaborator

    Fixed in PR #70875 (merged, commit 0f732cb), which closes out this bug class codebase-wide. Every subprocess call with text=True now passes an explicit encoding="utf-8", errors="replace" (163 call sites; salvaged from @Stoltemberg's #55339 and @jinglun010-cpu's #60741 with authorship preserved, extended to the sites that had landed since). @jinglun010-cpu's linter rule (#60751) now runs in CI via scripts/check-windows-footguns.py — any future text=True without an explicit encoding= fails the build, so the class cannot silently regress.

    Two deliberate exceptions preserved: schtasks output decodes with the locale code page (it genuinely emits OEM-encoded text, #38186), and cron's _run_job_script keeps its platform-conditional decode. Platform-gated sites (Termux, Singularity, macOS-only) carry # windows-footgun: ok suppressions instead of blanket kwargs.

    The desktop/TUI backend half of this shipped earlier today in #70850. Update to latest; reopen with a fresh traceback if any decode crash persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/acpAgent Communication Protocol adaptercomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointtype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions