Skip to content

bug: UnicodeDecodeError (cp1252) when running doctor/audit on Windows — subprocess text=True uses system encoding #63

@tbitcs

Description

@tbitcs

Problem

On Windows with a non-UTF-8 system locale (e.g. cp1252), running \doctor, \�udit, or any specsmith CLI command via the agent tool runner raises a \UnicodeDecodeError\ or produces garbled output.

The \doctor\ and \�udit\ commands output Unicode checkmark/cross characters (\✓\ U+2713, \✗\ U+2717) via Rich. These are valid UTF-8 bytes but cp1252 cannot decode them, causing the subprocess capture in _run_specsmith\ to fail.

Reproduction

  1. Windows system with default cp1252 locale
  2. Open a specsmith agent session (Ollama or any provider)
  3. Run the \doctor\ quick command
  4. Agent receives a \UnicodeDecodeError\ or cannot render the output

Root cause

In \src/specsmith/agent/tools.py, _run_specsmith\ calls:

\\python
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120, env=_SUBPROCESS_ENV)
\\

\ ext=True\ without \�ncoding='utf-8'\ means Python uses the system default encoding (cp1252 on Windows) to decode stdout/stderr. The subprocess itself outputs UTF-8 (because \PYTHONIOENCODING=utf-8\ is set in the env), but the parent process decodes with cp1252 — mismatch causes the error.

Fix

Add \�ncoding='utf-8'\ and \�rrors='replace'\ to the \subprocess.run\ call in _run_specsmith:

\\python
result = subprocess.run(
cmd, capture_output=True, text=True,
encoding='utf-8', errors='replace',
timeout=120, env=_SUBPROCESS_ENV,
)
\\

Affected

All Windows users with non-UTF-8 system locale when the agent uses governance tools (audit, doctor, validate, etc.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions