Repository navigation
Description
Bug Description
In src/specify_cli/workflows/step/shell/__init__.py, _decode_output() decodes captured subprocess stdout and stderr with locale.getpreferredencoding(False) first and only retries with locale.getencoding() when the two differ (added in #5209 for Python UTF-8 mode).
On default Windows Python 3.11-3.14 (without PYTHONUTF8=1), locale.getpreferredencoding(False) and locale.getencoding() are both the legacy ANSI code page (for example cp1252), so UTF-8 is never tried. The same happens on narrow POSIX locales (LC_ALL=C, where both are ascii).
This causes two real failures whenever a workflow shell step invokes a CLI that writes UTF-8 (including specify itself, which reconfigures stdout/stderr to UTF-8 at startup, as well as git, gh, node, jq, and Spec Kit's PowerShell/Python helpers):
- Step failure on UTF-8 bytes undefined in
cp1252(or any non-ASCII UTF-8 underascii): Runningspecify versionorspecify checkin a workflowshellstep on default Windows immediately fails withShell command stdout could not be decoded: 'charmap' codec can't decode byte 0x90 in position 199: character maps to <undefined>(from the banner's═/0xE2 0x95 0x90and╝/0xE2 0x95 0x9D). Any UTF-8 output containing”(0x9D),🔍(0x8D), CJK characters such as后台(0x90), or other sequences with bytes0x81/0x8D/0x8F/0x90/0x9Dfails the step identically. - Silent mojibake (including in
output_format: json): UTF-8 bytes that happen to be valid incp1252— such ascafé(\xc3\xa9->café),✓(\xe2\x9c\x93->✓),→(\xe2\x86\x92->→), or🎯(\xf0\x9f\x8e\xaf->🎯) — are silently corrupted into mojibake inoutput.stdout,output.stderr, and parsedoutput.data.
Additionally, if locale.getpreferredencoding(False) returns an unrecognized encoding name, _read_text(data, encoding) raises an uncaught LookupError instead of falling back cleanly.
Steps to Reproduce
- On Windows with default Python (without
PYTHONUTF8=1, wherelocale.getpreferredencoding(False)andlocale.getencoding()arecp1252), execute a workflowshellstep runningspecify version:
from specify_cli.workflows.base import StepContext
from specify_cli.workflows.step.shell import ShellStep
result = ShellStep().execute(
{"id": "ver", "type": "shell", "run": "specify version"},
StepContext(project_root="."),
)
print(result.status, result.error)- Or run a
shellstep withoutput_format: jsonwhose command writes UTF-8 JSON ({"name": "café", "status": "✓ → 🎯"}) and inspectresult.output["data"].
Expected Behavior
ShellStep decodes valid UTF-8 stdout and stderr cleanly (preserving universal newlines and exact Unicode text in output.stdout, output.stderr, and output.data) regardless of whether Python runs in UTF-8 mode or on a legacy locale code page, while still falling back to the locale code page for native tools (such as cmd.exe emitting cp1252/cp936/cp932) and still failing cleanly when bytes are invalid in both UTF-8 and the locale code page.
Actual Behavior
specify versionandspecify checkfail inShellStepon default Windows withStepStatus.FAILEDandShell command stdout could not be decoded: 'charmap' codec can't decode byte 0x90 in position 199: character maps to <undefined>.- UTF-8 JSON containing
café/✓/→/🎯is silently mojibaked inoutput.stdoutandoutput.data("café","✓ → 🎯").
Specify CLI Version
1.4.5.dev0 (main @ f323a4d)
AI Agent
opencode
Operating System
Windows 11 (10.0.26220)
Python Version
Python 3.14.7
Error Logs
preferred: cp1252 getencoding: cp1252
specify version -> status: StepStatus.FAILED error: Shell command stdout could not be decoded: 'charmap' codec can't decode byte 0x90 in position 199: character maps to <undefined>
specify check -> status: StepStatus.FAILED error: Shell command stdout could not be decoded: 'charmap' codec can't decode byte 0x90 in position 199: character maps to <undefined>Additional Context
Follow-up to #5064 and #5209. #5209 added a UTF-8 -> locale.getencoding() fallback when Python runs in UTF-8 mode (PYTHONUTF8=1, default in Python 3.15+); trying strict UTF-8 first and falling back to distinct preferred/system locale encodings unifies default Python 3.11-3.14 behavior with UTF-8 mode while preserving legacy code-page decoding and invalid-byte failure handling.
AI Disclosure
Detected, reproduced, and filed with OpenCode (model: Gemini 4 Neon, autonomous mode; code inspection and local reproduction on Windows).


Activity
fix(workflows): make shell output_encoding opt-in