Skip to content

kimi web crashes at startup on Windows when stdout is redirected: UnicodeEncodeError (gbk) in print_banner #2532

Description

@BFour666

Bug description

kimi web crashes immediately at startup on Chinese-locale Windows when its stdout is redirected (pipe/file) or when it is launched by a parent process that captures stdout. The crash happens while printing the startup banner: the (U+279C) character cannot be encoded with the locale codec (GBK / cp936), and the unhandled UnicodeEncodeError kills the whole process before the HTTP server binds its port.

As a result, the web server never starts, and a Web UI page already open in the browser shows repeated "实时连接出错 / WebSocket error" toasts because nothing is listening.

Environment

  • OS: Windows 11 (10.0.26100), Simplified Chinese locale (ANSI codepage 936 / GBK)
  • Kimi Code CLI: v0.28.1, native win32-x64 build (bundled with VS Code extension moonshot-ai.kimi-code, kimi_cli 1.43.0, PyInstaller / Python 3.14)

Steps to reproduce

  1. On a Chinese-locale Windows machine, redirect stdout, e.g.:
    kimi.exe web --port 58627 --no-open > web.log 2>&1
    
    (or launch kimi web from any parent process that pipes stdout)
  2. The process exits immediately; the port is never bound.

Actual behavior

Traceback (most recent call last):
  ...
  in web:70
  in run_web_server:437
  in print_banner:118
UnicodeEncodeError: 'gbk' codec can't encode character '➜' in position 4:
illegal multibyte sequence
[PYI-xxxxx:ERROR] Failed to execute script '__main__' due to unhandled exception!

Expected behavior

Banner printing should never crash the server. Please make print_banner encoding-safe (e.g. write with errors="replace", force UTF-8, or drop non-encodable characters) so kimi web starts regardless of stdout encoding / console availability.

What does NOT help

chcp 65001, PYTHONUTF8=1, and PYTHONIOENCODING=utf-8 all fail to prevent the crash when stdout is redirected (verified on v0.28.1).

Workaround

Run kimi web attached to a real console window (cmd / PowerShell / Windows Terminal) and keep that window open — console I/O uses UTF-8 (PEP 528), so the banner prints fine and the server starts normally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions