Summary
On Windows with a non-UTF-8 console codepage (e.g. cp1250 on Czech Windows 11), kbagent serve --ui crashes immediately during startup. The startup banner writes box-drawing characters (├─, └─) via sys.stdout.write, which raises UnicodeEncodeError before uvicorn.run is reached — the server never binds.
Environment
- kbagent v0.72.0 (banner code unchanged on current
main / v0.75.0)
- Windows 11 Enterprise, Czech locale — Python stdout encoding resolves to
cp1250
- Installed via
uv tool install
Steps to reproduce
- On Windows with a non-UTF-8 console codepage (Czech/Polish/Hungarian locales default to cp1250 for Python's stdout when not in UTF-8 mode), run:
- The process crashes before binding the port.
Actual behavior
UnicodeEncodeError: 'charmap' codec can't encode characters in position ...
File "...\encodings\cp1250.py", line 19, in encode
raised from the sys.stdout.write(...) banner in src/keboola_agent_cli/commands/serve.py (lines ~235–273). Both the --ui and non-UI banner branches contain ├─ / └─, which cp1250 cannot encode. The same crash would affect any legacy single-byte console encoding.
Expected behavior
The server starts; the banner degrades gracefully on terminals that can't render Unicode.
Workaround
Set PYTHONUTF8=1 before launching (verified working):
set PYTHONUTF8=1
kbagent serve --ui
Suggested fix
Either of:
- Reconfigure stdout before printing the banner so encoding errors can't be fatal, e.g.:
sys.stdout.reconfigure(errors="replace") # Python 3.7+
(or wrap in io.TextIOWrapper(..., encoding="utf-8")), or
- Fall back to ASCII glyphs (
|-, `-) when sys.stdout.encoding can't encode the banner — the same pattern install.sh already uses for its UTF-8 locale check (lines 62–66: Unicode glyphs only under a UTF-8 locale, ASCII otherwise, "so the banner never renders as mojibake on a legacy terminal").
A cheap belt-and-braces variant: wrap the banner write in try/except UnicodeEncodeError and re-emit an ASCII version, so a cosmetic banner can never prevent the server from starting.
Summary
On Windows with a non-UTF-8 console codepage (e.g. cp1250 on Czech Windows 11),
kbagent serve --uicrashes immediately during startup. The startup banner writes box-drawing characters (├─,└─) viasys.stdout.write, which raisesUnicodeEncodeErrorbeforeuvicorn.runis reached — the server never binds.Environment
main/ v0.75.0)cp1250uv tool installSteps to reproduce
Actual behavior
raised from the
sys.stdout.write(...)banner insrc/keboola_agent_cli/commands/serve.py(lines ~235–273). Both the--uiand non-UI banner branches contain├─/└─, which cp1250 cannot encode. The same crash would affect any legacy single-byte console encoding.Expected behavior
The server starts; the banner degrades gracefully on terminals that can't render Unicode.
Workaround
Set
PYTHONUTF8=1before launching (verified working):Suggested fix
Either of:
io.TextIOWrapper(..., encoding="utf-8")), or|-,`-) whensys.stdout.encodingcan't encode the banner — the same patterninstall.shalready uses for its UTF-8 locale check (lines 62–66: Unicode glyphs only under a UTF-8 locale, ASCII otherwise, "so the banner never renders as mojibake on a legacy terminal").A cheap belt-and-braces variant: wrap the banner write in
try/except UnicodeEncodeErrorand re-emit an ASCII version, so a cosmetic banner can never prevent the server from starting.