Repository navigation
Delete the emit apparatus that existed to colour a banner, now that measurement says it was a no-op - #10999
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
9ae5f87 to
9fad2f2
Compare
Validation pass, and three fixes pushedI put this PR through a dedicated review against the hypotheses most likely to make it a real break. Three defects came back, all comment-level, all now fixed in Fixed
A stronger argument than the one I made
What was checked and came back clean
One behaviour change, in the right direction
The middle three are colour being gained on locked-down machines, where the old gate refused for a reason unrelated to terminal capability -- it was asking "can I emit a P/Invoke stub?", not "does this terminal render VT?". The last is colour correctly lost where it should never have been claimed. No path can emit raw escape sequences: every consumer is gated on Caveat I am not going to paper overThis box is Linux with pwsh 7.6 and no Windows PowerShell 5.1. Everything above about 5.1, ISE and real WDAC enforcement is established from PowerShell's published source and Microsoft's SDK reference, plus the #10984 pre-flight run on a hosted |
1aac8b7 to
0792063
Compare
ca0ff5c to
2cf4933
Compare
0792063 to
5d30e20
Compare
2cf4933 to
ff31d61
Compare
|
@codex security review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Flagging from a CI sweep, not touching the branch since you have it in flight.
After this PR there is no Add-Type to reach. Strip the fast path and what remains is Two things follow, and only the first is a test problem:
Separately, your |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 05a7e7fd86
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # that does not override it answers $false already -- but a host with no UI at all yields $null, | ||
| # and the cast makes that $false too. The try/catch is for Set-StrictMode in a caller's profile, | ||
| # where reading an absent property raises PropertyNotFoundException rather than returning $null. | ||
| try { return [bool]$Host.UI.SupportsVirtualTerminal } catch { return $false } |
There was a problem hiding this comment.
Recheck the live console mode before emitting ANSI
When a profile or previously run native program clears ENABLE_VIRTUAL_TERMINAL_PROCESSING after PowerShell starts, IsOutputRedirected remains false but SupportsVirtualTerminal retains its startup result, so this returns true and the banner prints raw escape sequences. The new test at tests/python/test_windows_setup_output_encoding.py:820-827 itself demonstrates that the property remains true after the console state changes via FreeConsole; the deleted implementation instead read and repaired the current mode on every invocation. The duplicate implementation in studio/setup.ps1 has the same regression.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not correct as stated, and the premise it rests on is checkable.
The deleted implementation did not read or repair the mode "on every invocation". It ran exactly once, and its result was cached:
- base
install.ps1:2140-$script:StudioVtOk = Enable-StudioVirtualTerminal, then read at:2160,:2290,:2324 - head
install.ps1:2128- the same single assignment, read at:2148,:2278,:2312
studio/setup.ps1 is the same shape: one call site in both (base :1899, head :1634) and five readers of $script:StudioVtOk. Get-StudioAnsi never touches the console. So a native program that clears ENABLE_VIRTUAL_TERMINAL_PROCESSING partway through the install, which is the realistic version of this scenario since the installer runs python, uv and git, defeated the old code exactly as it defeats the new one: $script:StudioVtOk was already $true and nothing re-measured it.
The only window where the two differ is between host startup and that single line, and within it the difference is repair, not detection. There is no managed way to re-enable VT from Windows PowerShell 5.1: reading or setting the console mode requires the three kernel32 imports this PR removes, so "recheck the live console mode" is a request to restore the emitted type, which is the change itself.
On the cited test: it asserts that the property is a startup determination and does not track a later console change. That is what it is there to record, not a demonstration that the old code did track it.
Worth adding, because it cuts the other way: ConsoleHostUserInterface.TryTurnOnVirtualTerminal re-reads the mode after setting it, since older systems accept the call and ignore the flag. The deleted code trusted SetConsoleMode's return value. The property is the stricter of the two.
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…ad of emitting a P/Invoke thunk for it install.ps1 and studio/setup.ps1 both emitted a reflection-built type declaring GetStdHandle, GetConsoleMode and SetConsoleMode for one consumer: the ANSI colour banner. That cluster (a dynamic assembly, a kernel32 P/Invoke, and in setup.ps1 a hidden child interpreter to gate it) is the densest malicious-looking region in either script and the only thing behind the one high-severity Sigma rule VirusTotal reports, and it is decoration. Windows PowerShell's console host performs that exact sequence at startup and reports the outcome through $Host.UI.SupportsVirtualTerminal. The pre-flight in PR #10984 measured 5.1.26100 attached to a real console: the property answers True, the native call answers True, and the console mode read before touching it is already 0x7, so the SetConsoleMode was re-setting a bit the host had set. The property is also the stricter of the two, because TryTurnOnVirtualTerminal re-reads the mode after setting it while the deleted code trusted SetConsoleMode's return value. The redirected case is unchanged and still decided first, by $script:StudioStdoutRedirected, before the property is read, so the Tauri pipe path and the CLI are untouched. The emit apparatus itself stays in both files. setup.ps1's Get-NvidiaLibraryProbeType emits the nvml and nvcuda imports through the same gate, so its coverage in tests/python/test_windows_installer_native_type_fallback.py stays parametrised over both scripts; only the console-helper test is install-only. Rebuilt as one commit on current main.
4f5d5d5 to
3b641fd
Compare
|
Rebuilt this PR as one commit on current Procedural: this branch was stacked on #10978, which is now merged as Substantive, and worth reading rather than skimming: the original plan deleted the whole reflection-emit apparatus from What that changes:
The deterministic check, re-run against current
Suites: shape suite 242 passed 1 skipped, native-type fallback 109 passed, output encoding and concurrency guard 47 passed 25 skipped, Cross-platform staging on the previous head was green on ubuntu-latest, macos-15, macos-15-intel and ubuntu-24.04-arm; the windows-latest leg failed on the three |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…easurement says it was a no-op (unslothai#10999) * Windows installers: read the console's virtual terminal support instead of emitting a P/Invoke thunk for it install.ps1 and studio/setup.ps1 both emitted a reflection-built type declaring GetStdHandle, GetConsoleMode and SetConsoleMode for one consumer: the ANSI colour banner. That cluster (a dynamic assembly, a kernel32 P/Invoke, and in setup.ps1 a hidden child interpreter to gate it) is the densest malicious-looking region in either script and the only thing behind the one high-severity Sigma rule VirusTotal reports, and it is decoration. Windows PowerShell's console host performs that exact sequence at startup and reports the outcome through $Host.UI.SupportsVirtualTerminal. The pre-flight in PR unslothai#10984 measured 5.1.26100 attached to a real console: the property answers True, the native call answers True, and the console mode read before touching it is already 0x7, so the SetConsoleMode was re-setting a bit the host had set. The property is also the stricter of the two, because TryTurnOnVirtualTerminal re-reads the mode after setting it while the deleted code trusted SetConsoleMode's return value. The redirected case is unchanged and still decided first, by $script:StudioStdoutRedirected, before the property is read, so the Tauri pipe path and the CLI are untouched. The emit apparatus itself stays in both files. setup.ps1's Get-NvidiaLibraryProbeType emits the nvml and nvcuda imports through the same gate, so its coverage in tests/python/test_windows_installer_native_type_fallback.py stays parametrised over both scripts; only the console-helper test is install-only. Rebuilt as one commit on current main. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
studio/setup.ps1carried a Device Guard CIM query, a child-process capability probe, a dynamic assembly builder and a P/Invoke type emitter -- 288 lines, 14.3 KB -- and every one of them existed for a single consumer:Enable-StudioVirtualTerminal, which turns on ANSI colour for a banner."Defines a dynamic assembly, P/Invokes kernel32, spawns a hidden child interpreter" is the densest malicious-looking region in either installer, and the shape behind the only high-severity Sigma rule VirusTotal reported on the file. Removing it deletes code rather than rewiring it, which is the safest kind of change available here.
Gated on #10984, and it passed.
The measurement, and what it actually found
windows-vt-preflight.ymlran on real Windows PowerShell 5.1.26100 attached to a real console viaconhost, with a control asserting the console was genuinely there (isOutputRedirected=False-- without it, two redirected runs agree trivially and the lane reports SAFE having measured nothing):SupportsVirtualTerminalGetConsoleMode0x7The property and the native call agree, which is what the gate required. But the console mode is the more interesting number, and the probe records it before touching it:
0x7contains0x4,ENABLE_VIRTUAL_TERMINAL_PROCESSING. The host had already set it at startup.So the
SetConsoleMode($h, $mode -bor 0x0004)this replaces was re-setting a bit that was already set. It was not merely replaceable, it was a no-op. That is a stronger result than the gate asked for, and it is why this is behaviour-preserving rather than behaviour-equivalent-in-practice.What goes
studio/setup.ps1GetStdHandle,GetConsoleMode,SetConsoleMode, and the eager probe call on the console pathinstall.ps1GetStdHandle,GetConsoleMode,SetConsoleMode, and the eager probe call on the console path includingirm | iexThis PR was originally going to delete the whole emit apparatus from
studio/setup.ps1as well, on the grounds that the console thunk was its only consumer. That was true when it was written and is no longer true:Get-NvidiaLibraryProbeTypelanded onmainin the meantime and emits thenvmlandnvcudaimports through the same gate, so the apparatus is load-bearing there and stays. Deleting it would have leftTest-StudioCanDefineNativeTypescalled and undefined, and the GPU inventory would have thrown. Its coverage intests/python/test_windows_installer_native_type_fallback.pytherefore stays parametrised over both scripts; only the console-helper test is install-only.The six imports left in
install.ps1are the path resolver, the process-image lookup and the icon refresh. Each is load-bearing and documented as such; none is cosmetic.The redirected check stays first and still answers
$false. That is the path the CLI and the desktop app are on, and anything claiming VT there puts raw escape sequences in the Unsloth log panel, which is a pipe.[bool]rather than a bare return, because a host that does not implement the property yields$null.Tests
Mechanical, and each rewritten toward the stronger contract rather than loosened to pass:
test_virtual_terminal_answers_a_redirected_stream_without_defining_a_typeasserted an ordering (redirect check before the emit call) because that check was the only thing keeping the desktop app offcsc.exe. There is no emit call now, so it asserts what its name always implied: the function does no native work at all, and the redirected case is still decided first.test_setup_declares_no_native_imports_at_all. Without it the deletion is one "just add a small helper" away from being undone and nothing would notice, because every other check in that file is about how a native import is declared rather than whether there is one.test_the_installer_never_runs_the_c_sharp_compiler'sDefinePInvokeMethodassertion is now conditional on the file having imports at all. Demanding that a file with zero native surface prove it emits its imports would demand it grow some back.["install", "setup"]parametrisations intest_windows_installer_native_type_fallback.pybecome install-only, behind a named constant that records why.test_the_console_mode_parameter_is_still_declared_outbecomestest_the_emitter_still_honours_an_out_position. TheOutbranch in the emitter stays with no in-tree consumer, deliberately: the next by-ref import would otherwise marshal silently wrong -- the call succeeds, the out value never returns, nothing raises. Its source-level half is replaced by the opposite assertion, that noGetConsoleModeimport is declared again.test_native_path_resolver_degrades.ps1skips the emit assertions for a file with no imports, and its probes now build a locally invented type instead of one named after a type the installer no longer declares.Verification
mainin a clean worktree (test_pr10648_offline_and_status, twotorchcodeccompat tests).mainand pass here, so they are proved to bite rather than to pass vacuously.Parser::ParseFileclean on both scripts;test_native_path_resolver_degrades.ps1runs green end to end under pwsh.What is not claimed
The VirusTotal delta for this change cannot be measured yet, and
scripts/virustotal_delta.py(#10996) will correctly report VOID for it. Measuring would mean uploading an unreleased build, which creates a prevalence-zero first-seen sample under a hash no user will ever have -- the tool has no upload path for exactly that reason. The honest expectation is that Sigma moves and the Skyhigh behavioural verdict may not; it will be measured after release and reported either way.Also not claimed: that this has run on a self-hosted Windows 11 Pro box. The pre-flight was a hosted
windows-latestimage (build 26100), genuinely Windows PowerShell 5.1 under a genuineconhost, which is the property under test -- but "5.1 on Server 2025" and "5.1 on a consumer Windows 11 desktop" are not the same sentence, and I would rather write that down than let the verdict read broader than it is.