Skip to content

fix(web,vis): do not crash printing the startup banner on legacy console codecs - #2577

Open
ayaangazali wants to merge 1 commit into
MoonshotAI:mainfrom
ayaangazali:fix-banner-encoding
Open

fix(web,vis): do not crash printing the startup banner on legacy console codecs#2577
ayaangazali wants to merge 1 commit into
MoonshotAI:mainfrom
ayaangazali:fix-banner-encoding

Conversation

@ayaangazali

@ayaangazali ayaangazali commented Aug 1, 2026

Copy link
Copy Markdown

Related Issue

Resolve #2532

Description

print_banner in src/kimi_cli/utils/server.py writes the banner with a bare print(), and both callers put U+279C in front of each URL (web/app.py:374,376 and vis/app.py:128). On a console whose codec cannot represent that character, GBK on Chinese Windows being the reported case, the print raises UnicodeEncodeError.

The part that makes it more than cosmetic: the banner is printed before the server binds its port, so the unhandled error takes the process down and nothing ends up listening. From the user side that shows up as a Web UI stuck on WebSocket errors rather than as a crash, which makes it a confusing one to diagnose.

Characters the current stdout encoding cannot represent are now replaced instead of raising. Two details worth mentioning:

  • The substitution happens before the box width is measured, otherwise the replacement changes the line length and the box borders stop lining up.
  • Terminals that can encode the glyph are unaffected, so this does not downgrade normal output. There is a test covering that.

I deliberately did not touch sys.stdout reconfiguration or add an env var. Both would fix the symptom globally but change behavior well outside this banner, and the crash only needs the one guard where both callers already funnel through.

The issue was filed against 1.43.0; I verified the same code path is still there at HEAD (4a550ef, 1.49.0).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works. (renders the banner through a gbk stream, which raises on current main; plus a box alignment check and a utf-8 case asserting the arrow survives)
  • I have run make gen-changelog to update the changelog. (hand-edited CHANGELOG.md in the same style, I do not have the Kimi API setup the skill needs)
  • I have run make gen-docs to update the user documentation. (nothing in docs covers banner rendering)

Note on gates: make check-kimi-cli is clean and make test-kimi-cli passes. One PTY e2e test (test_shell_mode_toggle_roundtrip) flaked once under full suite load on my machine; it passes in isolation on both this branch and unmodified main, and the full e2e suite passes on re-run, so it looks like timing rather than anything from this change.


small disclosure as usual: freshman, no Windows machine to hand so I reproduced the encoding failure by rendering the banner through a gbk stream rather than on real hardware. logic decisions talked through with claude code. if you would rather just swap the arrow for an ascii character and skip the helper entirely, that is a totally fair call and i am happy to redo it that way :)


Open in Devin Review

…ole codecs

print_banner writes the banner with bare print(), and both the web and
vis banners include U+279C. On a console whose codec cannot represent
it (GBK on Chinese Windows, for example) that raises UnicodeEncodeError.
The banner is printed before the server binds its port, so the unhandled
error took the whole process down and nothing ended up listening.

Characters the stdout encoding cannot represent are now replaced. The
substitution happens before the box width is measured so the borders
still line up, and terminals that can render the glyph are unaffected.
Copilot AI review requested due to automatic review settings August 1, 2026 23:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants