Repository navigation
Conversation
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| def _safe_print(text: str) -> None: | ||
| """Print text while replacing characters unsupported by stdout's encoding.""" | ||
| builtins.print(_encode_for_stream(text, sys.stdout), flush=True) |
There was a problem hiding this comment.
🔴 Command echo bypasses safe output
With unsupported command characters, _safe_print does not protect the initial echo. Print.run writes directly, so legacy Windows stdout still aborts before execution.
Learn more
The new encoding-safe path covers messages emitted by the visualizers. Standard non-final text mode first echoes the user's command through a separate direct print call in Print.run. That write occurs before run_soul invokes any printer, so an encoding failure ends the command before the protected code runs. Other direct user-facing writes in Print.run can fail for the same reason when exception text contains unsupported characters.
Example: On a GBK stdout, run non-final text mode with the command explain 🧪. The command echo raises UnicodeEncodeError; no model request runs, although model output now passes through _safe_print.
Recommended fix: Put the safe stream or safe-write helper in a shared print-UI module and route every stdout write in Print.run through it. Add an integration-level regression test covering the command echo, rather than testing only TextPrinter and JsonPrinter.
Was this helpful? React with 👍 or 👎 to provide feedback.
Fixes #2629
Problem
Print mode writes streamed messages directly to stdout. On Windows consoles using a legacy encoding such as GBK, characters outside that encoding raise
UnicodeEncodeErrorand terminate the command.Fix
Sanitize print-mode output according to stdout's encoding before writing it. Rich text output uses the same safe stream wrapper, so text and JSON output both replace unsupported characters instead of crashing.
Verification
uv run pytest tests/ui_and_conv/test_print_encoding.py tests/ui_and_conv/test_print_final_only.py tests/ui_and_conv/test_print_notifications.py tests/ui_and_conv/test_print_exit_code.py tests/ui_and_conv/test_replay.py -quv run ruff checkuv run ruff format --checkpyrightpasses.