Skip to content

Name the encoding when reading wslinfo's output - #9142

Merged
danielhanchen merged 4 commits into
mainfrom
fix-lan-access-encoding
Aug 18, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
fix-lan-access-encoding

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Backend CI is red on main, and has been since the encoding guard started scanning this file.

studio/backend/tests/test_text_io_encoding.py::test_text_io_names_its_encoding[lan_access.py] reports:

lan_access.py:127: subprocess(text = True) without encoding

text = True with no encoding decodes with locale.getpreferredencoding(False), which on Windows is the ANSI codepage rather than UTF-8, so non-ASCII output is corrupted rather than merely mis-rendered.

The call reads wslinfo --networking-mode, whose output is ASCII in practice, so this is the guard being right about the shape rather than about this particular command. That is the correct posture for it to take: it scans every backend module and does not special-case commands whose output happens to be safe today, because the next caller to copy this block inherits the defect. subprocess.run accepts encoding directly and implies text mode, so naming it is the whole fix.

Verification

Reproduced on main at e46319458 before changing anything.

tree test_text_io_encoding.py
main, unmodified 1 failed, 452 passed
with this fix 453 passed

The test discriminates: reverting the one line brings the failure straight back, so this is not a change that passes either way.

test_lan_access_settings.py is unaffected, 65 of 65. Two collection errors appear when running the whole backend directory with -k lan_access, and they are identical on unmodified main, so they are pre-existing and out of scope here.

Why this is separate

This is a one-line repair to unblock main, not a sweep. If the guard is worth having, and it is, then the same shape elsewhere should be found by the guard itself rather than by hand, and it already scans every backend module.

danielhanchen and others added 3 commits August 18, 2026 03:43
Backend CI is red on main. test_text_io_names_its_encoding[lan_access.py]
reports lan_access.py:127 running subprocess with text = True and no
encoding, which falls back to the Windows ANSI codepage and corrupts
non-ASCII.

The call reads wslinfo --networking-mode, whose output is ASCII in
practice, so this is the guard being right about the shape rather than
about this particular command. The guard scans every backend module and
does not special-case commands whose output happens to be safe today,
which is the correct posture: the next caller to copy this block would
inherit the defect.

Reproduced on main and verified: 453 pass with the fix, and reverting it
fails exactly the one test.
The failure message named only the Windows ANSI codepage, which invites a
correct-sounding rejection: the call this caught sits behind an explicit
sys.platform != linux early return, so it can never run on Windows.

That reasoning is wrong, and the message was what made it available. The
fallback is locale.getencoding(), which is the ANSI codepage on Windows
and ASCII under a C or POSIX locale on Linux, as containers and CI runners
routinely have. A linux-only path still meets the second one.

Message only. Detection is unchanged: 453 pass before and after, and
reverting the lan_access fix still fails exactly one test.
@danielhanchen

Copy link
Copy Markdown
Member Author

Blame, and both readings of it

What introduced it. lan_access.py arrived with #8951 ("studio: add settings-managed LAN access"), merged 2026-08-18 01:32Z, about two hours before this. The guard it violates is not new: test_text_io_encoding.py and its subprocess(text = True) detector both landed on 2026-07-28 in #7467 ("Studio: read model text as utf-8 so umlauts survive on Windows"), three weeks earlier. So this is new code meeting an established rule, not a rule that moved under existing code.

Reading one, the source is wrong. The two other subprocess(text = True) call sites in the backend, run.py:868 and cloudflare_tunnel.py:457, both pass encoding = "utf-8" on the very next line. The convention is unambiguous and this call is the only one that missed it. The fix matches those two exactly, same keyword, same position, same value.

Reading two, the guard is over-broad, and it deserves a real answer rather than a dismissal. _wsl_networking_mode returns early unless sys.platform == "linux", four lines above the call. The guard's failure message cited only the Windows ANSI codepage. Taken literally, the guard was flagging a Windows hazard at a site that cannot execute on Windows, and someone could reasonably have waived it on that basis. The guard has no waiver mechanism, so the practical outcome of accepting that argument would be weakening the check.

Why reading one wins. The message was incomplete, not the detection. The fallback is locale.getencoding(), which is the ANSI codepage on Windows and ASCII under a C or POSIX locale on Linux, which containers and CI runners routinely have. WSL is Linux. So a linux-only path still meets the second mechanism, and the defect shape is real here, just not by the route the message named.

Robustifying the guard

Rather than only fixing the call, the second commit rewrites the failure message to name both mechanisms and to say explicitly that a platform guard above the call does not make it safe. That closes the escape hatch that made reading two available in the first place.

Message only. Detection is untouched:

tree result
this branch 453 passed
lan_access.py reverted to main 1 failed, 452 passed

So the check still discriminates after the change, verified by reverting the fix rather than asserted.

What I deliberately did not do

No sweep, and no waiver mechanism. If the same shape exists elsewhere in the backend the guard already scans every module and will say so; finding it by hand would be less reliable than the tool that just found this one.

@danielhanchen

Copy link
Copy Markdown
Member Author

CI note, so the red does not get read as this change.

The only failing job here is GGUF inference smoke (API, tools, vision), failing at the step JSON schema decoding + image input on the macOS runner. That is inherited from main, not caused by this diff:

This PR touches studio/backend/lan_access.py (one encoding = "utf-8" on the wslinfo subprocess read) and the failure message in studio/backend/tests/test_text_io_encoding.py. Neither is on any inference, schema decoding or vision path, and neither runs on macOS in that job.

The guard itself still discriminates: 453 pass on this branch, and checking out origin/main's lan_access.py over the fix fails exactly one test.

@danielhanchen
danielhanchen merged commit 900cd6a into main Aug 18, 2026
41 of 42 checks passed
@danielhanchen
danielhanchen deleted the fix-lan-access-encoding branch August 18, 2026 07:11
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.

1 participant