Repository navigation
Recognise Windows code integrity blocks, and require the runtime we ship - #10404
Conversation
Users on Windows with Smart App Control report Studio installing and launching, then failing to load a model, with the failure clearing when Smart App Control is turned off and returning after a reboot. The dialog they see is: llama-server.exe - Bad Image ...\.unsloth\llama.cpp\build\bin\Release\llama-common.dll is either not designed to run on Windows or it contains an error. Error status 0xc0e90002. 0xc0e90002 is a code integrity refusal, not a corrupt file. Three things made that hard to see. Windows validation did not require the file that gets blocked. runtime_payload_health_groups required six libraries for each Linux kind, including libllama-common.so*, but only llama.dll on Windows. A Windows tree missing llama-common.dll therefore logged "prebuilt installed and validated" and failed later at exec. Both our bundles and upstream's are built with BUILD_SHARED_LIBS on, so they carry llama-common.dll and a thin llama-server.exe beside llama-server-impl.dll; the requirement is gated on those sources because setup.ps1 builds from source with -DBUILD_SHARED_LIBS=OFF and legitimately has none of them. Verified against the published cpu, arm64-cpu, cuda, vulkan and rocm bundles for b10798-mix-659e406 and against upstream b10830. A blocked launch was logged at debug and looked like any other failure. utils/code_integrity.py recognises the statuses Windows uses for these refusals across the three shapes they reach us in: winerror 577, 1260 and 4551, NTSTATUS 0xc0e90002, 0xc0000428 and 0xc0000602 as a return code, and the Bad Image and Application Control wording in text. The capability probe now logs a blocked binary at warning with the reason. There is a matching user-facing message that names the blocked path and says plainly that reinstalling and running as administrator will not clear it, which is what users try otherwise. A blocked binary was re-probed forever at a fixed 30s. The retry now doubles up to 10 minutes. A transient failure still clears on the next poll, but a binary the OS refuses to run is permanent until the file or the policy changes, and each retry costs a 10 second timeout. The cache key includes the file's mtime and size, so replacing the binary starts a fresh key with no inherited backoff. The --help probe was also the only subprocess.run in llama_cpp.py without windows_hidden_subprocess_kwargs(), so it flashed a console window. It runs on a status poll rather than a user action, so it flashed repeatedly while the panel was open. Not addressed here. The status route can still queue probes behind a two-worker executor while the frontend polls every 5s, which is a plausible contributor to the 80s /api/inference/status stalls seen in diagnostics. Fixing that properly means restructuring probe_server_capabilities to single-flight, and the observed stalls happened with no model loaded, so the cause is not yet established. Left for a change that can measure it first.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4adc0e079
ℹ️ 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".
| _BLOCK_STATUS_CODES = { | ||
| 0xC0E90002: "Smart App Control or an Application Control policy blocked the image", | ||
| 0xC0000428: "the image failed code integrity validation (invalid or missing signature)", | ||
| 0xC0000602: "the image was refused by a code integrity fail-fast", |
There was a problem hiding this comment.
Require policy evidence before classifying fail-fast
0xC0000602 is the generic STATUS_FAIL_FAST_EXCEPTION, so a llama-server build that calls RaiseFailFastException for an unrelated fatal condition is classified as an Application Control refusal. In that scenario the capability probe emits misleading policy diagnostics and applies the policy-only exponential backoff; require a policy-specific status or message instead of treating this code alone as evidence of code integrity blocking.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reachable for the runtime we ship. RaiseFailFastException and __fastfail have zero occurrences anywhere in the llama.cpp tree, and ggml_abort ends in a plain abort(), which under MSVC surfaces as 0xC0000409 STATUS_STACK_BUFFER_OVERRUN with the FAST_FAIL_FATAL_APP_EXIT subcode, not 0xC0000602. So there is no path in this payload that raises a fail-fast for an unrelated fatal condition. The consequence would also be bounded rather than a correctness defect: a diagnostic string, plus a capped doubling of the retry window that the next non-block failure pops. Requiring a policy-specific status would additionally weaken the case this PR exists for, since 0xC0E90002 in a Bad Image dialog carries no further policy text to key on.
|
Confirmed the Windows health groups only required llama.dll, so a tree missing llama-common.dll logged as validated and then failed at exec, and the classifier now runs on the non-zero return path where Windows delivers the NTSTATUS. Will get this reviewed. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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 |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 712ef460ae
ℹ️ 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".
| blocked = code_integrity_block_reason(returncode) or code_integrity_block_reason(output) | ||
| if blocked is not None: | ||
| return code_integrity_user_message(binary or "the llama.cpp runtime", blocked) |
There was a problem hiding this comment.
Route CreateProcess policy errors through this classifier
When Windows rejects llama-server.exe itself with WinError 577 or 1260, subprocess.Popen in _spawn_and_wait raises OSError before a process, output, or return code exists; that call has no exception handler, so this new classifier branch is never reached and the load escapes with the raw launch error instead of the actionable policy guidance. Fresh evidence beyond the prior dead-code comment is this uncaught direct-Popen path; catch that launch exception and pass it through the code-integrity classifier too.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The premise is right and the consequence is not. Confirmed by AST that the Popen in _spawn_and_wait (llama_cpp.py:23786) has zero enclosing try blocks, so an OSError from CreateProcess does bypass _classify_start_failure_text, which only sees a returncode or output. But it does not escape: routes/inference.py:15059 catches it and returns HTTP 500 with str(e), which for these cases is Windows' own text, for example "[WinError 1260] This program is blocked by group policy". So the user gets an accurate explanation, just not our phrasing of the remedy. That is message quality rather than a crash, a lost call or a wrong verdict, which is where the bar sits. Worth noting the probe path already classifies this: the --help capability probe catches (OSError, subprocess.SubprocessError) and calls code_integrity_block_reason(exc), so a blocked llama-server.exe is already named in the log before a spawn is attempted. Happy to route the launch exception through the classifier as a follow-up, but not as a fix in this PR.
| tree. | ||
| """ | ||
| groups: list[list[str]] = [["llama.dll"]] | ||
| if source_label in {"published", "upstream"}: |
There was a problem hiding this comment.
Validate source metadata before set membership
When an existing install has otherwise parseable but damaged or manually edited metadata such as "source": [], this set-membership expression raises TypeError: unhashable type: 'list'. _kept_install_payload_is_healthy reads the value directly from the marker, and it is called from the prebuilt-fallback handler without a surrounding generic exception handler, so an update crashes instead of rejecting the malformed install and proceeding through the normal recovery path; type-check the marker value or use a comparison that tolerates arbitrary JSON values.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduced the TypeError, and it needs a marker our own code cannot write. AssetChoice.source_label is declared str (line 396) and all three marker writers (6617, 6858, 7272) write "source": choice.source_label, with only the literals "published" and "upstream" ever constructed; an absent key gives None, which is hashable and returns False cleanly. So "source": [] only arises from a hand-edited or corrupted marker, which is not the legitimate well-formed input the bar is about. The outcome is also milder than stated: the helper's top-level except Exception logs "fatal helper error: unhashable type" and exits EXIT_ERROR rather than crashing with a traceback, so the difference is an exit code and a log line. The fair point underneath is consistency, since the other reads of this marker (release_tag, bundle_profile, ggml_tree, runtime_line) do isinstance-check. That is a style nit rather than a correctness bug, so not changing it here.
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
The report
Windows users with Smart App Control enabled report Studio installing and launching, then failing to load a model. Turning Smart App Control off fixes it. Re-enabling it keeps working until a reboot, after which it breaks again. The dialog is:
0xc0e90002is a code integrity refusal (STATUS_SYSTEM_INTEGRITY_POLICY_VIOLATION, CodeIntegrity event 3077), not a corrupt file. Three things in the backend made that hard to see.1. Windows validation did not require the file that gets blocked
runtime_payload_health_groupsrequired six libraries for each Linux install kind, includinglibllama-common.so*, but onlyllama.dllon Windows. A Windows tree missingllama-common.dlltherefore loggedllama.cpp prebuilt installed and validatedand then failed at exec.The Windows kinds now require the same runtime set the Linux kinds do:
llama-common.dll,llama-server.exe,llama-server-impl.dll,ggml.dll,ggml-base.dll,ggml-cpu*.dllandmtmd.dll.This is gated on the prebuilt sources. Both our bundles and upstream's are built with
BUILD_SHARED_LIBSon, so they ship those files.studio/setup.ps1builds from source with-DBUILD_SHARED_LIBS=OFFand legitimately has none of them, so requiring them there would fail a healthy tree on every check.Verified against the published
windows-x64-cpu,windows-arm64-cpu,windows-x64-cuda12-legacy,windows-x64-vulkanandwindows-x64-rocm-gfx1150bundles forb10798-mix-659e406, and against upstreamllama-b10830-bin-win-cpu-x64. All six satisfy the new groups.2. A blocked launch was logged at debug and looked like any other failure
studio/backend/utils/code_integrity.pyrecognises the statuses Windows uses for these refusals, across the three shapes they reach us in:OSError.winerror577, 1260 and 4551 (4551 is what Studio (Windows/ROCm): Smart App Control blocks the unsigned ROCm GPU libraries (rocfft.dll) -- "Bad Image" crash + failed install #6648 recorded against unsigned ROCm DLLs)0xc0e90002,0xc0000428and0xc0000602as a return code, signed or unsignedThe capability probe now logs a blocked binary at warning with the reason instead of at debug. There is a matching user-facing message that names the blocked path and says plainly that reinstalling and running as administrator will not clear it, since those are what users try otherwise.
3. A blocked binary was re-probed forever at a fixed 30 seconds
The retry now doubles up to 10 minutes. A transient failure still clears on the next poll, but a binary the OS refuses to run stays refused until the file or the policy changes, and each retry costs a 10 second timeout. The cache key includes the file's mtime and size, so replacing the binary starts a fresh key with no inherited backoff.
Separately, the
--helpprobe was the onlysubprocess.runinllama_cpp.pywithoutwindows_hidden_subprocess_kwargs(), so it flashed a console window. It runs on a status poll rather than a user action, so it flashed repeatedly while the panel was open.What this deliberately does not do
Signing is the actual fix, and it belongs in the repo that builds the binaries: unslothai/llama.cpp#204 signs all four Windows legs with Azure Trusted Signing. Every PE we ship today is unsigned (47 of 47 in the CUDA bundle, 51 of 52 in the CPU bundle), and VirusTotal has never seen any of them, so they carry no prevalence either. Nothing in this PR makes a blocked binary load. It makes the block legible.
I also left the
/api/inference/statusstall alone. Diagnostics show that route taking 80530 ms and 80156 ms, which starves/api/healthand gets the backend killed by the desktop watchdog asunresponsive_health_checkat its 3 strike, roughly 75 second budget. The route can queue probes behind a two worker executor while the frontend polls every 5 seconds, which is a plausible contributor, but both observed stalls happened with no model loaded, so the inline probe helpers in theis_loadedbranch are not the cause and I have not established what is. Fixing it properly means restructuringprobe_server_capabilitiesto single-flight. That is worth doing on evidence rather than on a guess, and the probe in #10408 is what will produce the measurement.How to verify
Health groups and the block classifier:
281 passed locally. New cases: every Windows kind requires the shared runtime, a source build does not, upstream bundles do, and a published tree with
llama-common.dllremoved is rejected and accepted again once restored.The classifier has its own tests in
studio/backend/tests/test_code_integrity.py, including the negative cases that matter: a missing file,winerror 2, a plain nonzero exit and an ordinary argument error must not read as policy blocks.To see the new log line on a machine where this reproduces, load a model with Smart App Control on and look for
llama-server is blocked by Windows code integrity policyin the backend log, followed by the reason and the binary path.