Skip to content

fix(cli): decode manual ! command output with the OEM code page fallback on Windows#871

Open
abhay-codes07 wants to merge 1 commit into
mistralai:mainfrom
abhay-codes07:fix/console-stream-decoding
Open

fix(cli): decode manual ! command output with the OEM code page fallback on Windows#871
abhay-codes07 wants to merge 1 commit into
mistralai:mainfrom
abhay-codes07:fix/console-stream-decoding

Conversation

@abhay-codes07

Copy link
Copy Markdown

Fixes #777

Output of manual ! commands in the TUI is decoded as hardcoded UTF-8 with errors="replace". Windows console programs emit the OEM code page instead (cp949 on Korean systems, cp850/cp437 on many others), so any non-ASCII output renders as replacement characters. The report in #777 shows a cmd error message in Korean turning into garbage.

The one-off bash tool already solved this: it decodes through decode_safe(..., from_subprocess=True), which prefers the Windows OEM code page. The streaming ! path just never got the same treatment.

This adds IncrementalSafeDecoder to vibe.core.utils.io, a streaming counterpart of decode_safe: it decodes optimistically as UTF-8 and on the first invalid byte switches permanently to the OEM code page (or the locale encoding) with undecodable bytes replaced. The strict UTF-8 incremental decoder leaves its internal buffer untouched when it raises, so bytes buffered across chunk boundaries are re-decoded by the fallback codec and nothing is lost at the switch point. On systems where the locale is UTF-8 the behavior is identical to before.

_bash_read_stream in the TUI now uses it with from_subprocess=True.

Testing:

  • New decoder tests: multibyte UTF-8 split across chunk reads, cp949 Korean output in 5-byte chunks, ASCII prefix before OEM bytes, undecodable bytes replaced, truncated tail flushed on final
  • Updated the non-UTF-8 stderr UI test to accept the locale-decoded rendering, matching what the stdout twin test already does
  • tests/tools/test_ui_bash_execution.py and tests/core/test_utils.py pass, ruff and pyright clean

Verified on a Windows 11 machine. @elGrogz tagging you for a review pass when convenient.

Output of manual ! commands was decoded as hardcoded UTF-8 with
errors=replace. On Windows, console programs emit the OEM code page
(cp949 on Korean systems, cp850/cp437 on many European ones), so any
non-ASCII output rendered as replacement characters, for example
garbled Korean cmd error messages.

Add IncrementalSafeDecoder, a streaming counterpart of decode_safe: it
decodes optimistically as UTF-8 and, on the first invalid byte, switches
to the Windows OEM code page (or the locale encoding) without losing
bytes buffered across chunk boundaries. The one-shot bash tool already
resolves encodings this way via decode_safe(from_subprocess=True); this
brings the streaming path in line.

Fixes mistralai#777
Copilot AI review requested due to automatic review settings July 2, 2026 19:35
@abhay-codes07
abhay-codes07 requested a review from a team as a code owner July 2, 2026 19:35

Copilot AI left a comment

Copy link
Copy Markdown

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.

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.

bug: Displays garbled Korean text in command output

2 participants