Skip to content

[Bug]: deeptutor start loses all frontend logs on non-UTF-8 Windows code pages (UnicodeEncodeError kills _stream_output) #702

Closed

Description

@odafeng

Do you need to file an issue?

  • I have searched the existing issues and this bug is not already filed.
  • I believe this is a legitimate bug, not just a question or feature request.

Describe the bug

On a Windows console whose active code page is not UTF-8, deeptutor start loses all frontend logging a few seconds after launch. The log-relay thread dies with:

Exception in thread Thread-2 (_stream_output):
  File "deeptutor\runtime\launcher.py", line 150, in _stream_output
    print(f"  {prefix:<8} {line.rstrip()}", flush=True)
UnicodeEncodeError: 'cp950' codec can't encode character '\u2713' in position 11:
illegal multibyte sequence

The trigger is ordinary Next.js output: it prints ✓ (U+2713) in its startup banner, and the parent Python process's stdout is cp950 (the default code page on Traditional Chinese Windows; cp936 / cp932 would fail the same way for Simplified Chinese and Japanese).

The impact is narrow but confusing rather than fatal: the child processes keep running and the app works, but _stream_output is what relays child output to the console, so from that moment on no further frontend logs are printed. A user debugging a frontend problem sees a stack trace followed by silence and can reasonably conclude the frontend died.

launcher.py:829 already sets PYTHONIOENCODING=utf-8:replace — but only in common_env, which is passed to the child processes. The parent deeptutor start process, which is the one doing the print(), keeps the console's native encoding. The child pipes are decoded correctly (encoding="utf-8", errors="replace" at launcher.py:161-162); it is purely re-encoding on the way out to the terminal that fails.

Possibly related: #398 (also a Windows UnicodeEncodeError, closed 2026-04-28). That report had no logs or repro steps and described a failure while installing, so I don't believe this is the same code path — filing separately rather than reopening, but flagging it in case the underlying cause overlaps.

Steps to reproduce

  1. On Windows with a non-UTF-8 console code page (chcp reports 950, 936, or 932), from a source checkout.
  2. pip install -e . and cd web && npm install.
  3. deeptutor start.
  4. Backend starts and reports ready; the frontend starts, and as soon as Next.js prints its ✓ Next.js <version> banner line, the traceback above appears.
  5. No frontend log lines are printed for the rest of the session, even though the frontend is serving normally on its port.

Reproduces regardless of whether the frontend is the packaged build or the source npm run dev path, since both go through _stream_output.

Expected Behavior

Frontend and backend logs keep streaming to the console for the whole session on any Windows code page. Characters the console cannot represent are replaced rather than raising.

Related Module

API/Backend

Configuration Used

Default — no custom settings needed; a stock deeptutor start from a source checkout on a non-UTF-8 code page is enough.

Logs and screenshots

Starting frontend ...
Waiting for Frontend at http://127.0.0.1:3782/ ...
  frontend
  frontend > [email protected] dev
  frontend > node --max-old-space-size=4096 ./node_modules/next/dist/bin/next dev --port 3782
  frontend
  frontend �� Next.js 16.2.3 (Turbopack)
  frontend - Local:         http://localhost:3782
  frontend - Network:       http://100.109.59.90:3782
Exception in thread Thread-2 (_stream_output):
Traceback (most recent call last):
  File "...\Lib\threading.py", line 1043, in _bootstrap_inner
    self.run()
  File "...\Lib\threading.py", line 994, in run
    self._target(*self._args, **self._kwargs)
  File "C:\...\DeepTutor\deeptutor\runtime\launcher.py", line 150, in _stream_output
    print(f"  {prefix:<8} {line.rstrip()}", flush=True)
UnicodeEncodeError: 'cp950' codec can't encode character '\u2713' in position 11: illegal multibyte sequence
Frontend is ready.
Open http://localhost:3782 in your browser.

Note the last two lines: the launcher itself proceeds correctly and the app is usable — only the relay thread is gone. (The mojibake on the Next.js 16.2.3 line is the same root cause, one character that happened to survive replacement upstream.)

Suggested fix

Reconfigure the parent process's stdout once at startup, so every print() in the launcher is encoding-safe rather than fixing the one call site:

# near the top of deeptutor/runtime/launcher.py, or in start()
if hasattr(sys.stdout, "reconfigure"):
    sys.stdout.reconfigure(encoding="utf-8", errors="replace")

A narrower alternative is to guard only the relay, e.g. sanitising the line in _stream_output against sys.stdout.encoding before printing. Either way, the thread should also probably not die silently on an unexpected exception — a try/except around the loop that reports the failure would have made this far easier to diagnose, since the current symptom (traceback, then indefinite silence) does not point at the relay.

Happy to open a PR if this is a direction you'd accept.

Additional Information

  • DeepTutor Version: 1.5.4
  • Operating System: Windows 11 Pro (10.0.26200), console code page 950
  • Python Version: 3.13.5
  • Node.js Version: 22.17.0 (Next.js 16.2.3, Turbopack)
  • Browser (if applicable): n/a
  • Related Issues: [Bug]: "Windows 启动报 UnicodeEncodeError" #398 (earlier Windows UnicodeEncodeError, closed; different code path as far as I can tell)

Activity

  1. pancacake commented on Jul 26, 2026

    @pancacake
    Collaborator

    Fixed on dev by a1fcbfd3. Your diagnosis was exact: PYTHONIOENCODING=utf-8:replace only reached the children, while the parent's own print() in _stream_output kept the console's strict codec. The launcher now relaxes its own stdout/stderr to errors="replace" once at startup, so an unencodable character degrades instead of killing the relay thread — that also covers the launcher's own status lines, which could fail the same way on those code pages. Ships in the next release; thanks for the precise report, @odafeng.

  2. added a commit that references this issue on Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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