Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Windows No Compiler CI: see the intermediates the compiler cleaned up (#10711)

Daniel Hana167f284f15a
diff --git a/.github/scripts/Watch-ForCompiler.ps1 b/.github/scripts/Watch-ForCompiler.ps1
index 03a8726aa4c..776e39c7c5c 100644
--- a/.github/scripts/Watch-ForCompiler.ps1
+++ b/.github/scripts/Watch-ForCompiler.ps1
@@ -18,8 +18,17 @@ is not the code under test:
2. New *.dll, *.cmdline, *.rsp and *.?.cs files under every temporary directory
in play. The artefact half of the same shape, and it survives auditing being
silently overridden by machine policy. csc.exe writes the source and the
- response file next to the assembly, so those names are watched too: an
- assembly cleaned up leaves nothing to show, and a .cmdline still names it.
+ response file next to the assembly, so those names are watched too.
+
+ Watched live, with a FileSystemWatcher, and not only by comparing a listing
+ taken before the action against one taken after. CodeDom deletes its whole
+ intermediate directory once the assembly is loaded, so on a hosted runner the
+ before-and-after diff saw nothing at all while 4688 recorded
+
+ csc.exe /noconfig /fullpaths @"...\Temp\vpmyd5eq\vpmyd5eq.cmdline"
+
+ which is a compile this half missed entirely. The two are unioned: the listing
+ catches what was left behind, the watcher catches what was cleaned up.
Both are reported. The positive control requires both to fire, and the real
measurement requires neither to.
@@ -72,6 +81,82 @@ function Get-StudioTempArtifacts {
return ,[string[]]$found
}
+$script:ArtifactPattern = '\.(dll|cmdline|rsp|cs|err|out)$'
+$script:LibraryPattern = '\.(dll|cmdline|rsp)$'
+
+function Start-StudioTempWatch {
+ <#
+ .SYNOPSIS
+ Begin recording file creations under every temp root, and return the handles.
+ .DESCRIPTION
+ Register-ObjectEvent without an -Action: the events queue in the session's event
+ manager as they are raised, and Stop-StudioTempWatch drains them afterwards. An
+ -Action block would have to run for anything to be recorded, and there is nothing
+ to run it while a synchronous installer holds the pipeline.
+
+ A root that cannot be watched is skipped rather than fatal. The listing half still
+ covers it, and on a machine where none of them can be watched the positive control
+ is what says so.
+ #>
+ $handles = @()
+ foreach ($root in (Get-StudioTempRoots)) {
+ try {
+ $watcher = New-Object System.IO.FileSystemWatcher
+ $watcher.Path = $root
+ $watcher.IncludeSubdirectories = $true
+ $watcher.NotifyFilter = [System.IO.NotifyFilters]::FileName
+ # The default 8 KB buffer overflows on a busy temp directory, and an
+ # overflow drops events silently, which here reads as a clean run.
+ $watcher.InternalBufferSize = 65536
+ $identifier = "StudioTempWatch-" + [guid]::NewGuid().ToString('N')
+ $null = Register-ObjectEvent -InputObject $watcher -EventName Created `
+ -SourceIdentifier $identifier
+ $watcher.EnableRaisingEvents = $true
+ $handles += [pscustomobject]@{
+ Watcher = $watcher
+ SourceIdentifier = $identifier
+ Root = $root
+ }
+ } catch {
+ continue
+ }
+ }
+ return ,[object[]]$handles
+}
+
+function Stop-StudioTempWatch {
+ <#
+ .SYNOPSIS
+ Stop recording and return every path created while the handles were live.
+ .DESCRIPTION
+ Always unregisters and disposes, including on a path that saw nothing: a leaked
+ subscription keeps firing into the next measurement's queue.
+ #>
+ param([Parameter(Mandatory = $true)][AllowEmptyCollection()][object[]]$Handle)
+
+ # Delivery is asynchronous, so the last few creations before the action returned may
+ # still be in flight. Settle first, then stop raising: draining immediately dropped
+ # exactly the events that matter, the ones from the end of a compile.
+ Start-Sleep -Milliseconds 750
+
+ $seen = @()
+ foreach ($entry in $Handle) {
+ try { $entry.Watcher.EnableRaisingEvents = $false } catch { }
+ try {
+ foreach ($record in @(Get-Event -SourceIdentifier $entry.SourceIdentifier `
+ -ErrorAction SilentlyContinue)) {
+ $path = ''
+ try { $path = [string]$record.SourceEventArgs.FullPath } catch { }
+ if (-not [string]::IsNullOrWhiteSpace($path)) { $seen += $path }
+ Remove-Event -EventIdentifier $record.EventIdentifier -ErrorAction SilentlyContinue
+ }
+ } catch { }
+ Unregister-Event -SourceIdentifier $entry.SourceIdentifier -ErrorAction SilentlyContinue
+ try { $entry.Watcher.Dispose() } catch { }
+ }
+ return ,[string[]]$seen
+}
+
function Get-StudioProcessImageName {
<#
.SYNOPSIS
@@ -212,8 +297,12 @@ function Invoke-WithCompilerWatch {
# of the sweep above, so a compiler started in that second is counted: a deliberate
# trade towards a loud false alarm rather than a dropped real compile.
$since = (Get-Date).AddSeconds(-1)
+ # Opened here, with the 4688 window, and not before the baseline: a file the
+ # machine creates during that recursive sweep predates the action.
+ $watch = Start-StudioTempWatch
$failure = $null
+ $live = @()
try {
# Out-Host, not the success stream. The installer action tees its log, and those
# lines would be emitted as function output ahead of the result hashtable, making
@@ -224,6 +313,9 @@ function Invoke-WithCompilerWatch {
# Recorded and re-thrown below. The detectors still report, because "the
# installer died AND spawned a compiler" beats either half alone.
$failure = $_
+ } finally {
+ # In the finally, so an action that threw still closes its subscriptions.
+ $live = @(Stop-StudioTempWatch -Handle $watch)
}
# Closed before the temp sweep, which can take seconds: anything the machine
@@ -232,8 +324,16 @@ function Invoke-WithCompilerWatch {
$compilers = @(Get-StudioCompilerEvents -Since $since -Until $until)
$after = Get-StudioTempArtifacts
- $newArtifacts = @($after | Where-Object { -not $before.Contains($_) })
- $newLibraries = @($newArtifacts | Where-Object { $_ -match '\.(dll|cmdline|rsp)$' })
+ $left = @($after | Where-Object { -not $before.Contains($_) })
+ # Only the names the compiler writes, because the watcher reports every creation
+ # under temp and most of them are nobody's business.
+ $transient = @($live | Where-Object { $_ -match $script:ArtifactPattern })
+ $union = New-Object 'System.Collections.Generic.HashSet[string]' ([StringComparer]::OrdinalIgnoreCase)
+ $newArtifacts = @()
+ foreach ($path in ($left + $transient)) {
+ if ($union.Add($path)) { $newArtifacts += $path }
+ }
+ $newLibraries = @($newArtifacts | Where-Object { $_ -match $script:LibraryPattern })
$stem = Join-Path $EvidenceRoot $Name
$compilers | Out-File -FilePath "$stem-compilers.txt" -Encoding utf8
diff --git a/.github/workflows/windows-no-compiler-ci.yml b/.github/workflows/windows-no-compiler-ci.yml
index aa77f758705..f9a7120b256 100644
--- a/.github/workflows/windows-no-compiler-ci.yml
+++ b/.github/workflows/windows-no-compiler-ci.yml
@@ -162,8 +162,9 @@ jobs:
}
if ($seen.TempLibraries) {
$seen.TempLibraries | ForEach-Object { Write-Host "TEMP DLL: $_" }
- throw ("the installer left {0} DLL(s) in a temporary directory. Even without a " +
- "compiler process this is the artefact half of the same shape." -f `
+ throw ("the installer wrote {0} DLL(s) into a temporary directory. Even without a " +
+ "compiler process this is the artefact half of the same shape. Cleaning one " +
+ "up does not clear it: the watcher records the creation." -f `
$seen.TempLibraries.Count)
}
Write-Host "no compiler, no temporary DLL"
@@ -232,7 +233,7 @@ jobs:
}
if ($seen.TempLibraries) {
$seen.TempLibraries | ForEach-Object { Write-Host "TEMP DLL: $_" }
- throw "the desktop-mode installer left $($seen.TempLibraries.Count) DLL(s) in a temporary directory."
+ throw "the desktop-mode installer wrote $($seen.TempLibraries.Count) DLL(s) into a temporary directory."
}
Write-Host "desktop mode: no compiler, no temporary DLL"
diff --git a/tests/studio/test_installer_av_shapes.py b/tests/studio/test_installer_av_shapes.py
index a7d81621f58..f5a06720602 100644
--- a/tests/studio/test_installer_av_shapes.py
+++ b/tests/studio/test_installer_av_shapes.py
@@ -373,6 +373,106 @@ def test_the_watcher_scores_the_image_that_ran_not_the_words_in_the_message(
assert f"HITS:{expected}" in result.stdout, result.stdout
+_FAKE_WINEVENT = r"""
+function Get-WinEvent {
+ # Off Windows there is no such cmdlet, so this resolves the call. Empty rather than
+ # throwing: this exercises the artefact half, and the 4688 half has its own tests.
+ param([Parameter(ValueFromRemainingArguments = $true)]$Rest)
+ return @()
+}
+"""
+
+
+def _run_watch(tmp_path, action: str) -> tuple[str, list[str]]:
+ """Drive the real Invoke-WithCompilerWatch over $Action, with TEMP pointed at tmp_path."""
+ temp_root = tmp_path / "temp"
+ temp_root.mkdir()
+ evidence = tmp_path / "evidence"
+ script = tmp_path / "probe.ps1"
+ script.write_text(
+ "\n".join(
+ [
+ '$ErrorActionPreference = "Stop"',
+ f'$env:TEMP = "{temp_root.as_posix()}"',
+ f'$env:TMP = "{temp_root.as_posix()}"',
+ _FAKE_WINEVENT,
+ f'. "{_WATCHER}"',
+ f"$action = {{ {action} }}",
+ "$seen = Invoke-WithCompilerWatch -Name 'probe' -Action $action "
+ f'-EvidenceRoot "{evidence.as_posix()}"',
+ 'foreach ($lib in $seen.TempLibraries) { Write-Output "LIB:$lib" }',
+ 'Write-Output "COUNT:$($seen.TempLibraries.Count)"',
+ ]
+ ),
+ encoding = "utf-8",
+ )
+ result = subprocess.run(
+ ["pwsh", "-NoProfile", "-NonInteractive", "-File", str(script)],
+ capture_output = True,
+ text = True,
+ timeout = 300,
+ )
+ assert result.returncode == 0, result.stderr + result.stdout
+ libraries = [
+ line[len("LIB:"):] for line in result.stdout.splitlines() if line.startswith("LIB:")
+ ]
+ return result.stdout, libraries
+
+
[email protected](shutil.which("pwsh") is None, reason = "needs PowerShell")
+def test_the_watcher_sees_intermediates_the_compiler_cleaned_up(tmp_path) -> None:
+ """The failure this replaces: the positive control compiled a type, 4688 recorded
+
+ csc.exe /noconfig /fullpaths @"...\\Temp\\vpmyd5eq\\vpmyd5eq.cmdline"
+
+ and the artefact half reported nothing, because CodeDom deletes its intermediate
+ directory once the assembly is loaded. Comparing a listing taken before against one
+ taken after cannot see a file that no longer exists, so the job failed as a broken
+ detector on every run since it was added.
+ """
+ action = (
+ '$dir = Join-Path $env:TEMP "abcd1234"; '
+ "New-Item -ItemType Directory -Force -Path $dir | Out-Null; "
+ 'Set-Content -LiteralPath (Join-Path $dir "abcd1234.cmdline") -Value "/noconfig"; '
+ 'Set-Content -LiteralPath (Join-Path $dir "abcd1234.dll") -Value "MZ"; '
+ "Start-Sleep -Milliseconds 400; "
+ # The whole point: gone before the action returns, exactly as CodeDom leaves it.
+ "Remove-Item -LiteralPath $dir -Recurse -Force"
+ )
+ stdout, libraries = _run_watch(tmp_path, action)
+ assert libraries, f"a compile that cleaned up after itself was missed again: {stdout}"
+ assert any(lib.endswith(".cmdline") for lib in libraries), libraries
+ assert any(lib.endswith(".dll") for lib in libraries), libraries
+
+
[email protected](shutil.which("pwsh") is None, reason = "needs PowerShell")
+def test_the_watcher_still_reports_intermediates_that_were_left_behind(tmp_path) -> None:
+ """The listing half must keep working; the watcher is added to it, not swapped for it."""
+ action = (
+ '$dir = Join-Path $env:TEMP "leftover"; '
+ "New-Item -ItemType Directory -Force -Path $dir | Out-Null; "
+ 'Set-Content -LiteralPath (Join-Path $dir "leftover.dll") -Value "MZ"'
+ )
+ _, libraries = _run_watch(tmp_path, action)
+ assert any(lib.endswith("leftover.dll") for lib in libraries), libraries
+
+
[email protected](shutil.which("pwsh") is None, reason = "needs PowerShell")
+def test_an_action_that_compiles_nothing_reports_nothing(tmp_path) -> None:
+ """Otherwise the real measurement, which requires neither detector to fire, can never pass.
+
+ A text file is written so the action is not a no-op: the watcher sees the creation and
+ must still discard it, because the extension is not one a compiler writes.
+ """
+ action = (
+ 'Set-Content -LiteralPath (Join-Path $env:TEMP "notes.txt") -Value "hello"; '
+ "Start-Sleep -Milliseconds 400"
+ )
+ stdout, libraries = _run_watch(tmp_path, action)
+ assert "COUNT:0" in stdout, stdout
+ assert not libraries, libraries
+
+
def test_an_unreadable_security_log_is_void_rather_than_clean() -> None:
"""Get-WinEvent throws both for "nothing matched" and for "could not read".