Skip to content

scripts, viewer: a redirected stdout no longer dies on a path outside the code page - #2399

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
AAyberkU:stdout-encoding-scripts-viewer
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
AAyberkU:stdout-encoding-scripts-viewer

Conversation

@AAyberkU

@AAyberkU AAyberkU commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #2300 (comment) (new BUILD item)

Status after round 41: the first commit of this PR (a1343528: the guard for viewer/serve.py, audit_shader4_regs.py, bench_wave64.py, run_gpu_tests.py, and the extended check) is on main. What is left here, rebased on main f847748c, is two small follow-ups: scripts/shader_stats.py gets the guard and leaves the test's exception list, and the test starts its subprocesses with -X utf8=0 so it still catches a missing guard on Python 3.15+. 2 files, test and one __main__ block.

What and why

Every Python program here runs as python -I. Under -I on Windows, a redirected stdout (> log.txt, or a pipe) is encoded with the strict ANSI code page, so printing a path outside it, such as a Cyrillic or Turkish user or folder name, raises UnicodeEncodeError. tools/ already guards against this by setting errors="replace" on stdout at the start of each __main__ block, and tests/test_tool_stdout_encoding.py enforces that, but only for tools/.

Outside it, on Windows 11 (cp1252) with stdout redirected:

  • viewer/serve.py --world <folder with such a name> --port 0 died with UnicodeEncodeError before it started serving.
  • scripts/audit_shader4_regs.py <dir> --json <such a path> exited 1 with the same traceback, after writing its report.

scripts/bench_wave64.py and scripts/run_gpu_tests.py print the same kind of output unguarded. I could not reproduce a crash in those two here (they need llvm-mc and a built runtime), so for them this is the convention applied, not a measured crash.

This PR:

  • adds the same guard to those four programs, at the __main__ block and nothing else (viewer/serve.py also gains import sys);
  • update after shader_stats: --help exits 0, and an unknown option is refused instead of ignored #2135 was merged: scripts/shader_stats.py gets the guard too (second commit, rebased on current main);
  • extends the static check to scripts/ and viewer/. scripts/run_wine_tests.py (open Wine runner PRs) is the one file still listed as not yet guarded, to keep this PR out of their way;
  • adds two subprocess tests, for the audit and the viewer, with a private-use character in the path. They fail without the fix on Windows and pass on Linux, where the bug does not occur. The viewer test kills the server it starts.

Tested

Python only: no game files and no GPU involved. Windows 11, Python 3.12.10.

  • python -I tests/test_tool_stdout_encoding.py: 4 tests pass. With the guard taken out of serve.py and audit_shader4_regs.py it has 3 failures (the static check and both new tests, each a cp1252 UnicodeEncodeError).
  • Existing tests for the touched programs pass: test_viewer_serve.py, test_audit_shader4_regs.py, test_bench_wave64.py, test_run_gpu_tests.py, test_run_gpu_tests_paths.py, test_run_gpu_pixel_checks.py, test_run_gpu_wavemask.py.
  • node --test tests/test_viewer_streaming.cjs: 36 pass.
  • python -m compileall -q make_game.py tools tests scripts viewer: clean.

scripts/run_gpu_tests.py is a busy file; this adds four lines inside its __main__ block at the very end, which the open PRs I checked do not touch.

AI-assisted (Claude Code); the tests above were run on this branch.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (not a translator change)

🤖 Generated with Claude Code

https://claude.ai/code/session_016ABh36DZ2sZNq3ChN6EZJs

@AAyberkU

Copy link
Copy Markdown
Contributor Author

Updated: rebased on current main (round 40) and, now that #2135 is merged, added the same guard to scripts/shader_stats.py and took it off the test's exception list (only scripts/run_wine_tests.py is left there). python -I tests/test_tool_stdout_encoding.py and tests/test_shader_stats.py pass on Windows 11, Python 3.12.10, as do the existing tests for the other touched programs. AI-assisted.

@grahamster2

Copy link
Copy Markdown

Tested 1d79b7a merged onto main 4e00666 (clean merge) on Windows 11 26200 (cp1252), Python 3.12: pass.

  • python -I tests/test_tool_stdout_encoding.py: 4 OK. Negative control: with main's scripts/ and viewer/ checked out under the new test it's FAILED (failures=3), as the PR says.
  • test_viewer_serve 24 OK (1 skipped), test_audit_shader4_regs 5, test_bench_wave64 4, test_run_gpu_tests 34, test_run_gpu_tests_paths 20, test_run_gpu_pixel_checks 9, test_run_gpu_wavemask 6: all OK.

On the two scripts you couldn't run: I ran a real scripts/run_gpu_tests.py --filter cs_exec64 --work <scratch>\работа_ü > log (RTX 3080, conda-forge llvm-mc 23.1.6 and SPIRV-Tools 2026.4). Both main and this PR stop at the same place, before any print that the guard covers: spirv-as can't open ...\??????_?\spirv\vs_tri.spv. That Windows spirv-as build opens paths through the ANSI code page. So a --work folder outside the code page doesn't work with run_gpu_tests.py on Windows for a reason this PR doesn't cover. It doesn't block this PR.

@nonverifiedperson

Copy link
Copy Markdown
Contributor

Tested 1d79b7a0 on Windows 10 22H2 (ANSI code page 1252), Python 3.15.0: pass.

Python 3.15 turns UTF-8 mode on by default (PEP 686), even under -I, so on 3.15 a redirected stdout is UTF-8 and the crash never happens. With -X utf8=0, which -I doesn't override, a piped stdout falls back to cp1252 and the crash comes back. I ran the test's inputs that way: zeroed files and empty folders under a U+E000 folder name, stdout piped.

program main ec8ec4c9 PR 1d79b7a0
scripts/audit_shader4_regs.py … --json <path> exit 1, UnicodeEncodeError exit 0, report written
viewer/serve.py --world <path> --port 0 UnicodeEncodeError, no listening line prints viewer: http://127.0.0.1:…
tools/analyze_4240_full.py ok (guard already on main) ok
tools/meshlet_page.py (zeroed input, exit 1 both) no encoding error no encoding error
  • tests/test_tool_stdout_encoding.py on the PR: 4/4 OK.
  • The same test file against main's code: only test_every_main_block_reconfigures_stdout fails, which is the static check this PR satisfies.
  • Note for whoever relies on the runtime cases: on Python ≥ 3.15 they pass with or without the fix. Only the static check guards it there, unless the subprocesses are started with -X utf8=0. It might be worth adding that flag to the test's subprocess calls so they still catch a regression on new Pythons.

AI-assisted (Claude Code). No game files.

@AAyberkU

Copy link
Copy Markdown
Contributor Author

Thanks both. @nonverifiedperson good catch on Python 3.15's default UTF-8 mode: the test now starts its subprocesses with -X utf8=0 (third commit, test only), so the runtime cases keep catching a missing guard there too. On Windows 11 / Python 3.12.10 that changes nothing: 4 OK, and 2 failures with viewer/serve.py's guard taken out. I have no 3.15 here, so that side is unverified by me. Also rebased on current main. @grahamster2 noted: a --work folder outside the code page still stops run_gpu_tests.py at spirv-as on Windows, which this PR does not cover. AI-assisted.

AAyberkU added a commit to AAyberkU/Leonida that referenced this pull request Nov 22, 2026
Python 3.15 turns UTF-8 mode on by default, even under -I, so there a redirected stdout is UTF-8 and the
subprocess cases pass with or without the guard. -X utf8=0 keeps the code page they are about (review of
ItsNotRexed#2399 by nonverifiedperson). On 3.12 the flag changes nothing: 4 OK with the guard, 2 failures with
viewer/serve.py's taken out.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ABh36DZ2sZNq3ChN6EZJs
@AAyberkU
AAyberkU force-pushed the stdout-encoding-scripts-viewer branch from 1d79b7a to d40991d Compare November 22, 2026 18:47
@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 1d79b7a (Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RTX 5090). This PR's own changes against main are scripts/audit_shader4_regs.py, bench_wave64.py, run_gpu_tests.py, shader_stats.py, viewer/serve.py and tests/test_tool_stdout_encoding.py.

  • Full ctest: 130/130.
  • tests/test_tool_stdout_encoding.py: 4 OK.
  • Tests of the changed scripts: test_bench_wave64.py, test_audit_shader4_regs.py, test_shader_stats.py and test_run_gpu_tests.py OK.
  • tests/test_report_paths.py: fails test_macos_case_sensitive_volume_keeps_case here, but it fails the same way on main 77444fa without this PR (a macOS-only test running on Windows), so it isn't this PR's.

AI-assisted (Claude Code).

@XFlawless1

Copy link
Copy Markdown
Contributor

Follow-up on the two scripts the description couldn't run (scripts/run_gpu_tests.py, scripts/bench_wave64.py). I ran them on Windows 11 Pro 26300, Python 3.12.10, with a built runtime and llvm-mc 21.1.8, on the Radeon iGPU (RDNA2, AMD 32.0.21042.62). stdout went to a file. main's copies were compared with the PR's at a1343528. AI-assisted (Claude Code). No game files.

The earlier part: tests/test_tool_stdout_encoding.py passes, 4 tests, merged onto main ec8ec4c9. With main's viewer/serve.py and scripts/audit_shader4_regs.py, it has 3 failures, both new tests ending in a cp1252 UnicodeEncodeError, as the description says. The other tests for the touched programs pass: test_viewer_serve, test_audit_shader4_regs, test_bench_wave64, test_run_gpu_tests, test_run_gpu_tests_paths.

Run (--filter cs_dpp_w64) main this PR
run_gpu_tests.py, --work and --build ASCII exit 0, 1/1 passed exit 0, 1/1 passed
run_gpu_tests.py, --work and --build (a junction) holding U+E9C3 exit 1, no UnicodeEncodeError exit 1, no UnicodeEncodeError

On that path, neither script reaches a print of it. The Vulkan SDK's spirv-val reports that the .spvasm file doesn't exist, and the next step can't open vs_tri.spv, because those programs take ANSI paths. So for run_gpu_tests.py the guard is the convention applied, as you wrote; it can't be shown end to end while the SDK tools stop first. bench_wave64.py doesn't print its --build path at all, and its exit 1 here (incomplete comparison: no complete result from NVIDIA --wave64-emulate) is the same with an ASCII path. That failure isn't caused by this PR.

This is not a reason to hold the PR. I'll post the SDK-tool failure as a finding of its own in the coordination issue: run_gpu_tests.py's default --work is under %TEMP%, so a Windows user name outside the code page breaks the GPU tests.

@smowlyy

smowlyy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested on Windows 11 Home 26300 (Spanish locale, ANSI code page 1252), Python 3.12.10, AMD Ryzen 5 7600X: pass, and the crash it fixes reproduces here without it. AI-assisted (Claude Code). No game files.

  • d40991d: python -I tests/test_tool_stdout_encoding.py 4 tests OK; tests/test_psin_data.py, tests/test_tex_headers.py, tests/test_tool_startup.py OK.
  • Negative control: the same new test file with the five scripts put back to the base's (ec8ec4c) versions fails 3 of 4. audit_shader4_regs.py and viewer/serve.py stop with UnicodeEncodeError: 'charmap' codec can't encode character from cp1252.py when stdout is redirected and the path has a character outside the code page; the guard test lists all five scripts as missing the reconfigure.
  • GPU suite at the earlier head 1d79b7a (the update to d40991d only touches tools/psin_data.py, tools/tex_headers.py and tests), redirected to a file: AMD Radeon iGPU (RDNA2, driver 24.10.24) 91/189 passed native and emulated, 0 failed; NVIDIA RTX 5060 Ti (610.88) 142/189 native and 173/189 emulated, 1 failure each, ps_sdwa_f16_const, which fails the same way on main 1628210 (posted separately in the coordination issue). tests/semantic: 4137 OK.

AAyberkU and others added 2 commits November 22, 2026 23:01
It was left out of this change while ItsNotRexed#2135 was open on the same file. With the guard added it leaves the
test's list of exceptions, which now holds only run_wine_tests.py.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ABh36DZ2sZNq3ChN6EZJs
Python 3.15 turns UTF-8 mode on by default, even under -I, so there a redirected stdout is UTF-8 and the
subprocess cases pass with or without the guard. -X utf8=0 keeps the code page they are about (review of
ItsNotRexed#2399 by nonverifiedperson). On 3.12 the flag changes nothing: 4 OK with the guard, 2 failures with
viewer/serve.py's taken out.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ABh36DZ2sZNq3ChN6EZJs
@AAyberkU
AAyberkU force-pushed the stdout-encoding-scripts-viewer branch from d40991d to d7e2b00 Compare November 22, 2026 20:01
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@AAyberkU

Copy link
Copy Markdown
Contributor Author

Rebased on main f847748c after round 41. The first commit (a1343528) landed there; the two follow-ups pushed after it did not, so they are what this PR now holds: the guard for scripts/shader_stats.py (off the exception list) and -X utf8=0 in the test's subprocess calls. 2 files, +13/-9. python -I tests/test_tool_stdout_encoding.py (4 OK) and tests/test_shader_stats.py pass on Windows 11, Python 3.12.10. Thanks to everyone who tested. AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit bda3ae4 into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
@AAyberkU
AAyberkU deleted the stdout-encoding-scripts-viewer branch November 22, 2026 22:31
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.

7 participants