Skip to content

Repair a quarantined llama.cpp runtime at launch instead of failing at model load - #10494

Merged
danielhanchen merged 45 commits into
mainfrom
desktop-preflight-llama-runtime
Sep 22, 2026
Merged

danielhanchen merged 45 commits into
mainfrom
desktop-preflight-llama-runtime

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #10404. That PR made a blocked binary explain itself; this one makes the desktop repair the install instead of launching into it.

The gap

Antivirus quarantines individual files out of ~/.unsloth/llama.cpp and leaves everything else alone. The marker still says installed, the directory is still there, and one DLL is gone.

Scope, corrected against the field evidence in #10408: this is about files that are removed, truncated or stripped of their execute bit. It is not a Smart App Control fix. A code integrity block leaves the file present and healthy on disk and refuses it only at load, so no payload check can see it, and none of this helps there. Signing (unslothai/llama.cpp#204) is what addresses that.

Preflight never noticed. probe_managed_bin decides ManagedStale from the managed Python only: the CLI answers -h, the managed context builds, the desktop capability payload reports a complete install, so preflight returns Ready and the app launches. The missing file surfaces much later, at model load, as an error that reads like a bad GGUF or an out of memory. The fix was to run unsloth studio update by hand, and nothing told anyone to do that.

existing_install_matches_choice already knew how to answer this. It just was not asked at launch.

The change

studio/install_llama_prebuilt.py gains installed_runtime_health(), returning (ok, reason) or None when no runtime is installed. It delegates the verdict to _kept_install_payload_is_healthy, the same payload tables the keep-install path uses, so the two cannot drift apart. It runs on platform_only_host() rather than detect_host(), which shells out to nvidia-smi and costs over a second for facts this check does not read (measured here at 0.0000s against 1.29s).

unsloth_cli/commands/studio.py reports it in the desktop capability payload as llama_runtime_ok / llama_runtime_reason, best effort: a probe that raises leaves both null rather than turning a working install into a stale one.

studio/src-tauri/src/preflight/managed.rs treats an explicit false as stale, so the repair path that already exists picks it up and the user gets a repaired runtime instead of a confusing failure two screens later.

Backwards compatibility

Only an explicit false is stale. None means either nothing is installed yet or the CLI predates the field, and neither is a broken runtime. Calling either one stale would send every existing install through repair on its first launch after an upgrade.

For the same reason desktop_manageability_version is unchanged. Bumping it would reject every older CLI on the manageability check before this one is ever reached.

The cache half

The stale check alone would not have worked. The capability cache short-circuits preflight to Ready, and its fingerprint covered the managed venv only: bin path, size, mtime, marker, installed distributions. A file quarantined out of the llama.cpp tree changes none of those, so the cache would have kept serving Ready and the CLI would never have been asked.

ManagedBinFingerprint now carries the runtime's file count and total byte size, which both change when a file is taken. MANAGED_CAPABILITY_CACHE_SCHEMA goes to 4 for the new field, and UNSLOTH_LLAMA_CPP_PATH is resolved the way default_managed_llama_dir resolves it, with a leading ~ expanded, since the Python reader calls expanduser and an unexpanded value would fingerprint the wrong tree.

Tests

tests/studio/install/test_installed_runtime_health.py, 9 tests: no marker is None rather than broken, a missing runtime directory is distinguished from a gutted one, an empty directory is the shape a quarantine leaves and is not healthy, the verdict is delegated rather than duplicated, the default root honours the override, platform_only_host agrees with detect_host on every platform boolean, and it runs no subprocess.

Three Rust tests in preflight::managed: a quarantined runtime is stale with its reason, a broken runtime with an empty reason falls back to a generic one, an unknown runtime is not stale.

Green locally: 536 of 536 in the Tauri crate, 3955 of 3955 in tests/studio/install.

What this does not cover

Only the managed install under ~/.unsloth/llama.cpp (or UNSLOTH_LLAMA_CPP_PATH). A source build has no marker and is deliberately left alone, exactly as the keep-install path leaves it alone.

The fingerprint is count and total size, not a hash. It catches a file being removed or quarantined, which is the reported failure. It would not catch a same-size in-place substitution, which is a different threat and is what signing covers.

What the user sees

The message this PR adds, against the message the same state produced before it. Both halves are the shipped startup screen out of a frontend built from that side's own tree (merge base 917af3894, PR head 9c488e12d), driven with one preflight result: managed_stale, reason llama_runtime_payload_incomplete, auto repair unavailable, which is the state a quarantined runtime reaches on a build that cannot repair itself.

Startup screen before and after

Before, a quarantined runtime read as an out of date install, so the advice was an update that reports the install is already current. After, it names the cause, keeps the reinstall command, and names the folder to allow in the antivirus, spelled the way the platform spells it (%USERPROFILE%\.unsloth\llama.cpp on Windows).

…t model load

Smart App Control and antivirus quarantine individual files out of the managed
llama.cpp tree while leaving the marker and the rest of the tree in place. The
desktop's preflight decided staleness on the managed Python alone, so it reported
Ready, launched, and the missing DLL only surfaced later at model load as an
error that looked like a bad GGUF or an out of memory. Repairing it meant running
`unsloth studio update` by hand, which nothing told the user to do.

install_llama_prebuilt gains installed_runtime_health(), which reuses the same
payload tables the keep-install path already uses rather than duplicating the
required file list. The CLI reports it in the desktop capability payload and the
Tauri preflight treats an explicit false as stale, so the existing repair path
picks it up.

Only an explicit false is stale. None covers both "no runtime installed yet" and
"this CLI predates the field", and neither is a broken runtime: treating them as
stale would send every existing install through repair on its first launch after
an upgrade. For the same reason desktop_manageability_version is not bumped.

The capability cache had to move too. Its fingerprint covered the managed venv
only, so a file quarantined out of the runtime left it identical and preflight
answered Ready from cache without ever asking the CLI. The runtime's file count
and total size now join the fingerprint, and the cache schema goes to 4.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-21T15:27:47.311434Z 9c488e1 Manual request
🔒 Security Review ✅ Completed 2026-09-09T23:41:49.424908Z 68afcb7 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17fd5cbed7

ℹ️ 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".

if cfg!(windows) {
bin = bin.join("Release");
}
let entries = fs::read_dir(&bin).ok()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Distinguish a missing runtime directory in the cache key

If a healthy tokenibele capability was cachedelbe Genius melt? noennials

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejecting this one on the body rather than the title: the text after the heading reads If a healthy tokenibele capability was cachedelbe Genius melt? noennials, so there is no claim here I can reproduce or act on. Please re-post it if it was truncated on the way out.

On what the title points at, the two states are already distinct and covered. llama_runtime_fingerprint_at returns None when the binary directory cannot be read and "0:0" when it is present and empty, so a tree whose files were all quarantined does not collide with a machine that never installed a runtime. a_quarantined_runtime_file_changes_the_fingerprint asserts both, including the transition between them.

The neighbouring case that is real, the relative override falling back to the legacy tree, came in separately as 3957928980 and is being fixed there.

pre-commit-ci Bot and others added 2 commits September 8, 2026 11:59
The launch probe has to be no stricter than the setup scripts' own
keep-or-reinstall decision. A tree the probe rejects but _existing_install_runs
keeps would be repaired, kept unchanged by the repair and rejected again on the
next launch, which is a loop with no way out. That property is now stated where
the code is and tested as a property over the whole matrix.

Three real gaps closed:

The payload groups are libraries, and on Linux and macOS they name no executable
at all, so a quarantined llama-server passed as a complete install. Both
entrypoints are now looked for, which is what _existing_install_runs already
requires, so the check stays on the safe side of the rule above.

platform_only_host() left macos_version unset while detect_host() derives it
from platform.mac_ver(), which reads no hardware. The parity test would have
failed on a macOS runner.

A relative UNSLOTH_LLAMA_CPP_PATH resolved against the desktop's working
directory, which is not the one the CLI child runs under. Fingerprinting
whatever sits beside the desktop is worse than not fingerprinting, so it now
degrades to no coverage. A leading ~ is expanded, since the Python reader calls
expanduser.

Deliberately not changed, and pinned by a test so it is not "fixed" later: a
marker that exists but does not parse still reads as nothing installed.
Reporting it broken looks right, but confirm_install_tree only checks that the
marker file exists, so the offline keep path keeps such a tree, and broken plus
kept is exactly the loop above.

Tests. 1361 cases over [Windows, Linux, macOS] x [cpu, cuda, rocm, vulkan,
metal] x thirteen shipped marker shapes x damage modes, asserting both the
verdict and the invariant, with the invariant's sensitivity checked by mutation
rather than assumed. Healthy installs of every shipped shape stay healthy on
every platform, which is the backwards-compatibility half. The verdict is
unchanged across NVIDIA, AMD, Intel and no GPU at all. Rust gains JSON round
trips proving a pre-PR payload still parses and reads Ready, that an old cache
file is ignored rather than fatal, and that a newer CLI's unknown keys are
inert. The frontend no longer tells a user with a quarantined runtime that their
install is too old.
@danielhanchen

Copy link
Copy Markdown
Member Author

Pushed c4d99a119. Before doing that I tried to break this change rather than confirm it, so here is what the simulations covered, what they found, and what they cannot answer.

The property that matters

The launch probe has to be no stricter than the setup scripts' own keep-or-reinstall decision. A tree the probe rejects but _existing_install_runs keeps would be repaired, kept unchanged by the repair, and rejected again on the next launch. That is a loop with no way out for the user, and it is a worse failure than the one this PR fixes. It is now stated in the docstring and tested as a property rather than left as a comment.

Matrix: [Windows, Linux, macOS] x [cpu, cuda, rocm, vulkan, metal] x 13 shipped marker shapes x damage modes, 1361 cases. For every tree the probe calls broken, _existing_install_runs is also false. WSL is Linux here (platform.system() returns Linux, and every path decision is taken off is_windows / is_macos), so it is one of the Linux rows rather than a fourth platform.

The assertion is not vacuous. Healthy trees of every cell assert the keep path returns true, and the invariant was mutation checked: loosening _existing_install_runs to always keep reproduces REPAIR LOOP: linux-x64-cpu-S1 with remove-libllama-common.so is rejected by installed_runtime_health but kept by _existing_install_runs in 20 of 20 sampled cells.

Four defects the simulations found, now fixed

  1. A quarantined llama-server read as a complete install. The payload groups are libraries, and on Linux and macOS they name no executable at all. Both entrypoints are looked for now, which is what _existing_install_runs already required, so the check stays on the safe side of the rule above.
  2. platform_only_host() left macos_version unset while detect_host() derives it from platform.mac_ver(), which reads no hardware. The parity test would have failed on a macOS runner.
  3. A relative UNSLOTH_LLAMA_CPP_PATH resolved against the desktop's working directory, which is not the one the CLI child runs under. It degrades to no runtime coverage now rather than fingerprinting whatever sits beside the desktop. A leading ~ is expanded, since the Python reader calls expanduser.
  4. The frontend told a user with a quarantined runtime that their install was too old, which sends them to an update that reports they are already up to date. It names the likely cause now, and mentions an antivirus exclusion, since a reinstall into the same quarantine needs one rather than another retry.

One thing deliberately not fixed

A marker that exists but does not parse still reads as nothing installed. Reporting it broken looks obviously right, and it is what an interrupted write leaves behind, but confirm_install_tree only checks that the marker file exists. _existing_install_runs therefore keeps such a tree when its payload is complete, and that is the branch an update with no reachable release plan takes. Broken plus kept is the loop above. There is a test pinning this so it is not "fixed" later without the reasoning.

Backwards compatibility

  • A pre-PR capability payload, driven as JSON rather than as a Rust literal, parses and reads Ready. Only an explicit false is stale.
  • desktop_manageability_version is still 2 and desktop_protocol_version still 1, observed live.
  • An old cache file (schema 3, no runtime field) is ignored rather than fatal.
  • A newer CLI's unknown keys are inert; there is no deny_unknown_fields in the crate.
  • studio is packaged and importable from a plain pip install, verified from a neutral cwd in an isolated venv, so the probe is not silently null for everyone. The ImportError arm is exercised for real with a sys.meta_path blocker: null verdict, exit 0, rest of the payload intact.
  • Healthy installs of all 13 shipped marker shapes stay healthy on every platform, which is what stops an upgrade putting existing users into repair.

GPU independence

The verdict is driven by the marker's backend and the platform booleans, never a probed GPU field, so the same tree gets the same answer with NVIDIA, AMD/ROCm, Intel or nothing at all. Asserted over 25 cases, and a separate test fails if the probe spawns a subprocess at all.

Cost on the launch path

About 27 ms, essentially all of it the import; installed_runtime_health() itself is 0.14 ms on a populated tree and 2.2 ms against a tree with 2000 extra files. No nvidia-smi, nothing executed, only stat'd.

Green

543 of 543 Rust, 7046 of 7046 frontend, 1387 across the three new Python files, 13 of 13 end to end in an isolated venv driving the real console script.

What this still cannot answer

No reproduction of a Smart App Control block on real hardware. What is established is the code path (preflight was blind to the runtime) and the tree shape (Microsoft documents quarantine as removing the detected file from its directory and leaving the rest), not a live capture of SAC taking a file out of a shipped bundle.

The fingerprint is file count and total size, not a hash. It catches removal and quarantine, which is the reported failure. A same-size in-place substitution is a different threat and is what signing covers.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
scripts/run_ruff_format.py runs whatever ruff is on the path; the hook pins
0.6.9, and these four files were written under a newer one. The two disagree
about assert-message wrapping and about when a def signature goes one parameter
per line, which is what pre-commit.ci reported as "files were modified by this
hook".
@danielhanchen

Copy link
Copy Markdown
Member Author

The pre-commit failure, and why it is only half this PR's

Fixed this branch's share in da3cb70e4: the four new files were formatted under a newer ruff than the hook pins, so ruff-format-with-kwargs rewrote them and reported "files were modified by this hook".

Reproduced locally against the pinned ruff==0.6.9, which is what pre-commit.ci installs: the two disagree about assert cond, ("msg") wrapping (ruff 0.9 moved the parentheses from the condition to the message) and about when a def signature goes one parameter per line. The four files are back in the repo's own style and their 1374 tests still pass.

The other half is not this PR. Running the same hook over a clean main leaves four unrelated files modified, so pre-commit run --all-files fails on any branch cut from it:

studio/backend/tests/test_password_prompt_backstop.py
tests/studio/install/test_docker_studio_keep_cuda_prebuilt.py
unsloth_cli/commands/studio.py
unsloth_cli/tests/test_studio_password_prompt.py

Same cause, from 055470f, 5ca7bb3 and #10495. #10512 fixes those and stops the class recurring: scripts/run_ruff_format.py runs sys.executable -m ruff, so it silently formats with whatever a contributor has installed, and nothing local catches the mismatch. It now reads the pin out of .pre-commit-config.yaml and refuses, naming both versions, before it rewrites anything.

This PR should go green once #10512 lands.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit that referenced this pull request Sep 8, 2026
…he four files that drifted (#10512)

main is currently red under its own formatting hook. `pre-commit run --all-files`
reformats four files nobody is touching, so every open PR fails
`ruff-format-with-kwargs` with "files were modified by this hook" and a diff that
has nothing to do with it. #10494 is one; there will be more.

## Why the drift happens

`scripts/run_ruff_format.py` runs `sys.executable -m ruff`, which under
pre-commit is the pinned `ruff==0.6.9` and on a contributor's machine is whatever
they have. ruff's formatting is not stable across releases -- 0.9 moved the
wrapping in `assert cond, "msg"` from the condition to the message -- so a file
written under a newer ruff is committed in a style the hook reformats back, and
the hook then fails on it forever. The linter hook beside it is on v0.15.18 and
autoupdates, which makes a modern ruff the natural thing to have installed.

Nothing catches it locally: the file looks formatted, `ruff format --check`
agrees (with the newer ruff), and the failure only appears on pre-commit.ci.

## The change

`run_ruff_format.py` reads the pin out of `.pre-commit-config.yaml` and refuses,
before rewriting anything, when the ruff it would run is a different version. The
message names both versions and how to fix it, since "files were modified by this
hook" sends people looking for a defect in their own diff.
`UNSLOTH_RUFF_FORMAT_ANY_VERSION=1` overrides it, which a pin bump needs.

The pin is read rather than copied, so there is no second thing to forget; an
unreadable pin or an unreadable ruff is not a mismatch, because the format step
below already fails loudly on its own.

## The four files

Re-formatted with the pinned 0.6.9, no other change: the assert wrapping in
`test_docker_studio_keep_cuda_prebuilt.py`, `test_password_prompt_backstop.py`
and `test_studio_password_prompt.py`, and the blank line after a short local
import in `unsloth_cli/commands/studio.py`, which is the repo's own rule from
#6079.

Not a pin bump: moving to 0.16 reformats 1062 files and would conflict with every
open PR. That is worth doing deliberately, on a quiet branch, not as a side
effect of unblocking CI.

15 new tests, and the existing kwarg-spacing suite still passes (77 total).
Seven review items were genuine and are fixed here. Two of them contradicted
calls I had made earlier and the review was right both times.

A marker that exists but does not parse is now graded rather than reported as
nothing installed. I had argued the opposite, on the grounds that the offline
keep path keeps such a tree and broken plus kept is a loop. The narrower split
is the correct one: an absent marker file is a runtime nobody installed, a
present one that will not parse is a real tree, and when it has lost a library
as well, answering None left preflight Ready with no repair offered. The keep
path already reads such a marker as an unknown backend and grades the same
payload, so nothing here asks for more than it does.

A relative UNSLOTH_LLAMA_CPP_PATH was falling through to the legacy tree, which
is a regression I introduced in the commit that was meant to prevent exactly
that. Dropping it to None is not the fix either: None matches None, so the cache
keeps hitting while the real runtime rots. It is anchored to this process's
working directory now, which is where relative_override_pins joins the child's
copy from. On Windows the tilde resolves through USERPROFILE rather than
dirs::home_dir(), because that is what the child uses and a portable profile
moves the second one; process.rs carries the same note at its own read.

A quarantined llama-server was already covered. Managed runtime health is now
reported only when the managed runtime is the one that would actually load,
since _find_llama_server_binary prefers LLAMA_SERVER_PATH and the folder chosen
in settings ahead of it, and grading the managed tree regardless sent a user
running their own build into a repair that offline cannot even succeed.

Two further defects came out of the simulations rather than the review.

A dead Linux runtime was reported healthy. A release ships libllama.so.0 beside
libllama.so.0.0.10360 and the group pattern matches both, so quarantining the
SONAME, which is the name the loader asks for, left the group satisfied by the
twin. Measured against a real install: llama-server exits 127 with a loader
error while the probe said healthy. No fixture could show it, because a fixture
writes one file per library and a release writes two. Dangling symlinks in a
versioned chain were passing for the same reason and are covered by the same
check.

The repair could not terminate. setup.sh skipped the source rebuild whenever the
two entrypoints were executable, which is true of every tree that lost only a
library, so offline the repair returned the tree byte for byte identical and
reported success while the next launch rejected it again. It asks
reusable_existing_install first now. That branch only runs once the prebuilt
path has failed, where keeping a tree that cannot load is never right, and a
tree with no marker is a real source build and keeps the old test.

Tests: 5965 in tests/studio/install, 561 in the Tauri crate. The convergence
census that pinned the loop as a fact now pins its absence, and the strict xfail
holding the SONAME defect is an ordinary assertion.
danielhanchen and others added 3 commits September 8, 2026 13:43
read_dir(build/bin).ok()? answered None for two different states: no llama.cpp
runtime at all, and a runtime tree whose binary directory is gone. The capability
verdict is not the same in both. With no marker, installed_runtime_health answers
None, llama_runtime_ok stays null, and desktop_capability_stale_reason
deliberately does not call that stale, so a Ready gets cached. Once a marker sits
over a missing build/bin the CLI would answer llama_runtime_dir_missing, but the
fingerprint had not moved, the cache still matched, and preflight served the old
Ready without ever asking.

The root's own entries now stand in when build/bin cannot be read, so the marker
arriving moves the key. None still means the tree is not there, which is the
NotInstalled case.
The previous commit gave a runtime tree with no build/bin its own fingerprint
and prefixed the walk, which left five assertions on the old shape and the crate
red at 557 of 562.

Three are the format: bin: now leads the count. Two are the semantics the change
introduced, and they are worth stating rather than patching. "No runtime at all"
is the absence of the tree, so its test points at a path that does not exist
instead of an empty directory, which is now the broken-install state. A root that
is present but whose binary directory cannot be read is broken too, not absent:
sharing None with a machine that never installed a runtime is exactly what let a
cache written before an install keep matching after it broke.
Shorten every comment and docstring this branch added, keeping the
reasoning that is load bearing and dropping the restatements of the code
beside them. No code, only comments and whitespace.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…runtime override

- installed_runtime_health now checks each macOS library on its own instead of
  three broad globs, so a bundle missing libllama-common, libggml-base or
  libggml-cpu is graded incomplete rather than healthy. Verified against the real
  macos-arm64 bundle: complete is healthy, removing any one library is not, and
  dropping the metal, blas and rpc backends stays healthy.
- llama_runtime_override_from resolves ~user/... through getpwnam on unix rather
  than treating it as a relative path.
- A blank UNSLOTH_LLAMA_CPP_PATH no longer counts as an override.
- The CLI capability payload only reports the managed runtime when the managed
  runtime is the one that would actually run.

Fixtures that built macOS trees from the old broad names now write the names a
real bundle ships.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…e is graded

- A dylib chain now follows the same rule as an .so: losing the middle
  libggml.0.dylib left the group satisfied by the terminal libggml.0.23.0.dylib
  while dyld could not launch, since the LC_LOAD_DYLIB entry names the link.
- llama-server and llama-quantize must still carry the execute bit on POSIX.
  _existing_install_runs already asks that way, so an install with the bit
  cleared was rejected there and reported healthy here.
- The CLI capability helper follows the finder's own file status rather than the
  directory entry, so a pinned symlink whose target was quarantined falls
  through to the managed tree the backend really loads instead of suppressing
  its verdict.
- UNSLOTH_LLAMA_CPP_PATH outranks the stored custom folder in the finder and
  default_managed_llama_dir points at exactly that tree, so it is graded even
  when an older selection is still in the settings database.
- ~name on Windows resolves to the sibling profile the same way process.rs and
  ntpath.expanduser resolve it, instead of being fingerprinted under the cwd.
- A runtime verdict the CLI skipped is no longer cached, since nothing in the
  fingerprint watches which runtime is selected and clearing a custom selection
  would otherwise keep serving a Ready nobody had graded.
A Windows bundle unpacked on a POSIX filesystem carries no execute bit, and the
host is a parameter here, so os.access X_OK graded every real windows-x64 bundle
in the history suite as missing its binaries. Windows has no execute bit for
os.access to read anyway, so presence is the whole question there.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: da85e7ee45

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

CI triage on the red legs. None of them are this PR, and I checked rather than assumed.

desktop windows / "Launch and prove it stays up": the app under test is a published release binary (REL_TAG: v0.1.810-beta), not something this PR builds. Its own log gives the cause:

This command cannot be run due to the error: This version of %1 is not compatible with the version of Windows
##[error]the app wrote no tauri.log; it never reached setup_logging

The exe would not start on the runner image, so it never reached setup_logging, let alone a preflight disposition. The steps this PR can actually move all passed ahead of it: bundled installer exit: 0, the venv was created, and the working-torch check passed.

Repo tests (CPU, python / rest / studio): pre-existing. Run on a clean origin/main worktree, the same files fail identically.

test this branch clean main
test_docker_hub_readme.py, test_accelerator_skip_guards.py 2 failed, 33 passed 2 failed, 33 passed
test_installer_av_shapes.py, test_st_save_merged_signature.py, test_formatter_fixed_point.py 7 failed 7 failed

Locally this branch is green where it counts: tests/studio/install is 8763 passed, 65 skipped, which includes the 1362-cell health matrix.

@danielhanchen

Copy link
Copy Markdown
Member Author

Cross-platform staging run, off the org queue, so the platforms this PR does NOT touch are exercised too.

leg result
Unsloth API CI, Unsloth GGUF CI, Frontend CI, Wheel CI, Unsloth Tauri CI, Startup profile pass
Windows Unsloth API CI, Windows Unsloth UI CI, Windows No Compiler CI pass
Windows ARM64 CI pass
Windows: installer differential (base vs head) pass
Cross-platform parity pass

Two legs were red and neither is this PR:

  • Windows Unsloth GGUF CI: three checks in tests/studio/test_path_probe_access_denied.ps1 about a denied uv cache. The test file and studio/setup.ps1 are byte-identical to main here; install.ps1 was stale on the branch and this PR never touched it. Merged main up, so the next staging run reads main's copy.
  • Workflow trigger lint: the same two test_installer_av_shapes.py bitdefender cases, 2 failed against 2002 passed, which fail identically on a clean main worktree.

The branch is now merged up to main and tests/studio/install is 8763 passed, 65 skipped on the merged head.

I could not answer one thing here, so I am saying so rather than implying otherwise: there is no real macOS host in this loop, so the split-dylib requirement is proven against the shipped bundles and the health matrix, not against a live dyld load.

@danielhanchen

Copy link
Copy Markdown
Member Author

Two more legs, both checked rather than waved off.

(Python 3.13, a-k): test_a_cold_health_call_answers_inside_the_launcher_deadline measured 2.10s against a 2.0s budget, 5 percent over, on a shared runner. It is not this PR adding work to that path: installed_runtime_health has no reference anywhere under studio/backend/, so the /api/health route cannot reach it. The capability payload is written by studio/install_llama_prebuilt.py and read by the Rust preflight, neither of which is on the health call. Ran the file three times on this branch here: 10 passed each time.

desktop windows: covered above, the published release exe would not start on the runner image.

The rest of the red set (Core, the three Core zoo, GGUF inference smoke, Repo tests (CPU, ...), workflow-trigger lint) is identical on #10473 and #10474 and fails on a clean main worktree, which is what makes it the base and not any of the three branches.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: fec10dc106

ℹ️ 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".

Comment-only; the AST gate reports install_llama_prebuilt.py code-unchanged.
@danielhanchen

Copy link
Copy Markdown
Member Author

Final state. Codex is at no open items and the review has converged.

Red CI legs, all checked against a clean origin/main worktree: GGUF inference smoke, Repo tests (CPU, python/rest/studio) and workflow-trigger lint fail identically there. desktop windows is the published release exe refusing to start on the runner image. (Python 3.13, l-r) is the 2.0s health-probe budget measured at 2.10s, and that path cannot have moved here: installed_runtime_health has no reference anywhere under studio/backend/.

Local on this head: tests/studio/install is 8763 passed, 65 skipped, including the 1362-cell health matrix.

danielhanchen and others added 2 commits September 20, 2026 04:11
…ng one machine's path

Merging main up brought in test_macos_loader_probe_record.py from #11237, whose
install fixture writes three dylibs. This branch replaced main's three loose
macOS globs with one group per library, so the fixture is now thinner than any
install the code grades and 18 of its 26 tests failed on the merge.

The tightening is the right side of that: on the shipped
llama-b11030-mix-5ff778e-bin-macos-arm64 bundle, quarantining libggml-base
leaves main answering healthy, because libggml-blas, libggml-metal and
libggml-rpc still satisfy libggml*.dylib, and answers
llama_runtime_payload_incomplete here. The fixture now writes the libraries that
bundle actually carries, including the two impl dylibs the unparseable release
tag requires under the same gate Windows has always used.

test_llama_runtime_install_history.py defaulted its asset directory to one
machine's workspace path. The default is now under the user's own cache, and the
presence check no longer lets a PermissionError through: the file promises to
skip when an artifact is not available, and an unreadable directory failed 24
tests instead.

tests/studio/install: 8796 passed, 76 skipped.
@danielhanchen

Copy link
Copy Markdown
Member Author

Merged main up, and the merge exposed a real break rather than only conflicts. Pushed afd532cad.

The branch was conflicting

Two frontend files, both against main's new MANAGED_ENVIRONMENT_BUSY / MANAGED_ENVIRONMENT_UPDATING constants. Resolved keeping both sides: main's two constants and its "the busy reasons are spelled the same in Rust" test, and this branch's LLAMA_RUNTIME_REASONS arm and its tests. The comment rewording this branch had done to lines it did not otherwise touch is reverted to main's, so the file's diff is now the new arm and nothing else. 13 of 13 tests in backend-preflight-message.test.ts pass.

What the merge broke, and which side was wrong

tests/studio/install/test_macos_loader_probe_record.py arrived with #11237. It is 26 of 26 on a clean origin/main worktree and was 18 failures on the merge, so this is an interaction, not a pre-existing red.

Cause: this branch replaces main's three loose macOS globs with one group per library, and that file's build_install writes three dylibs (libllama.0, libggml.0, libmtmd.0). Eight more failed further along, on existing_install_matches_choice, because its AssetChoice.tag is release-1, which does not parse as a build number, and an unparseable tag takes the strict side of the impl-split gate, exactly as _windows_shared_groups has always done.

The tightening is the right side of that, checked against the artifact rather than a fixture. llama-b11030-mix-5ff778e-bin-macos-arm64.tar.gz, laid out as the installer lays it out:

tree main this branch
the bundle as shipped healthy healthy, (True, "")
libggml-base.* quarantined out of it healthy (False, "llama_runtime_payload_incomplete")

Main keeps answering healthy because libggml*.dylib is still satisfied by libggml-blas, libggml-metal and libggml-rpc, none of which the loader can use in its place. That bundle carries all six required libraries and both impl dylibs, so the fixture was thinner than any install this code grades; it now writes what the bundle carries.

This is the first time the macOS requirements in this PR have been put against a real macOS bundle instead of a hand-built tree. It is still not a live dyld load, and I am not claiming one.

A test carrying one machine's path

tests/studio/install/test_llama_runtime_install_history.py defaulted its asset directory to a specific absolute workspace path. Two problems: it does not belong in the repo, and the file promises every test skips when its artifact is absent, which is_file() does not deliver, since it propagates PermissionError. On a host where that path exists but is not readable, 24 tests failed instead of skipping.

The default is now under the user's own cache, UNSLOTH_TEST_LLAMACPP_ASSET_DIR still overrides it, and the presence check treats any OSError as "not available here".

Green

tests/studio/install on the merged head: 8796 passed, 76 skipped. Both changed files re-formatted with the pinned ruff==0.6.9.

CI is running on the merged head; I will triage whatever comes back red against a clean main worktree rather than assume.

@danielhanchen

Copy link
Copy Markdown
Member Author

CI on the merged head afd532cad: 106 pass, 0 fail, 7 skipped.

Every leg that was red before the merge is green now, which is the point worth recording: Core, the Core zoo set, GGUF inference smoke, the three Repo tests (CPU, ...), workflow-trigger lint, desktop windows, (Python 3.13, l-r) and Unsloth Updating Tests (macOS) were all base failures, and they cleared by merging main up rather than by anything changing here. The 2.0s health-probe budget passes on this head too.

One leg needed a second look rather than a rerun on faith. Composer (macos-latest, browsers) failed once, on a 30s wait_for_function timeout in the queue reorder assertion. It is not this branch: 14 of the 15 engine/suite combinations in that same job passed, Linux and Windows were 15 of 15, and chromium's frame times on that runner were 116.7ms p95 against 16-21ms on every other engine and OS. The frontend diff against main here is backend-preflight-message.ts and its test, 2 files, which that suite never loads. Green on rerun.

Not proven, still: no live dyld load on a real macOS host, and no reproduction of a code integrity block on real Windows hardware. The macOS claim rests on the shipped bundle's file tree, not on a loader that refused to start.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

Field evidence for the tree shape this grades, which I had left as inferred.

The description says the quarantine shape comes from Microsoft documenting quarantine as removing the detected file and leaving the rest, rather than from a report. There are reports, upstream, against the binaries we redistribute:

That is this failure exactly. One file taken out of an otherwise intact tree, a marker that still says installed, and a directory that still looks right. A per-file machine learning detection on one DLL is also why the damage is partial rather than the whole tree: nothing else in the bundle is touched.

It does not widen the scope. These are removals, which a payload check can see. A Smart App Control block leaves the file healthy on disk and is refused at load, which nothing here can detect, and signing is what addresses it.

One cross check worth recording while I was looking. janhq/jan#8816 is the same mechanism against the same binaries in another llama.cpp consumer: they sign llama-server.exe and none of the DLLs, so Smart App Control blocks at the first unsigned DLL the process loads, mtmd.dll or a ggml-cpu-*.dll, with CodeIntegrity 3077 and exit 0xC0E90002 under the same policy GUID our users reported. Signing the entrypoint alone buys nothing, which is why unslothai/llama.cpp#204 signs every PE in the bundle. Parsing the certificate tables of the current release, b11030-mix-5ff778e windows-x64-cpu, all 52 are signed. Upstream's own llama-b11060-bin-win-cpu-x64 is 0 of 25.

@danielhanchen

Copy link
Copy Markdown
Member Author

Better evidence than the upstream one I posted above, and it is in this tracker.

#8184, "llama-server failing to start", closed 2026-08-08. The reporter found the cause themselves:

Figured it out... I recently installed MSI Afterburner and for some reason it installed Norton 360 Anti-virus. I uninstalled Norton, reinstalled Unsloth and it works just fine.
Seems like Anti-Virus removes llama.cpp but did not let me know it has removed it.

That is this PR's premise, reported by a user, against our own managed install: security software takes the runtime out, nothing says so, and the symptom the user sees is a llama-server that will not start. It is also the shape the launch probe is built for rather than the code integrity shape, since the files are gone rather than refused.

What that user had to do was work out that an antivirus they did not know they had installed was the cause, then reinstall. With this change preflight sees the gutted tree at launch, marks it stale, and the repair reinstalls it, and the message names security software as the likely cause instead of telling them their install is too old.

The neighbouring reports are the same mechanism against the other things we ship, which this PR deliberately does not cover: #9758 (the console script launcher missing), #10805 (install.ps1 flagged, blocking updates), #8523 and #9076 (Bitdefender and other EDR blocking the desktop installer). Those are installer-path problems and belong with #10986's work, not here.

The message told the user to allow "the folder" without saying which one, and
finding it is the whole work of acting on that sentence. It now names the
default root, spelled the way the platform spells it, off the same navigator
test the roaming-profile hint beside it already uses.

Hedged with "usually" rather than asserted: UNSLOTH_LLAMA_CPP_PATH can move the
root and preflight does not carry the path, so a definite statement would be
wrong for anyone who set it. No navigator at all keeps the POSIX spelling rather
than dropping the advice.

Three tests: every reason names a folder, Windows gets the Windows spelling and
no POSIX one (a path a user cannot paste into an exclusion list is not advice),
and a missing navigator still answers. 15 of 15 in the file.
@danielhanchen

Copy link
Copy Markdown
Member Author

Pushed 0bd5585d3, one string and its tests.

The antivirus line told the user to allow "the folder" without saying which one, and finding that folder is the whole work of acting on the sentence. It names the default root now, spelled the way the platform spells it, off the same navigator test the roaming-profile hint beside it already uses:

platform tail of the message
Windows allow the folder it installs into, usually %USERPROFILE%\.unsloth\llama.cpp, in your antivirus if it happens again
macOS, Linux allow the folder it installs into, usually ~/.unsloth/llama.cpp, in your antivirus if it happens again

"Usually" rather than a flat statement, since UNSLOTH_LLAMA_CPP_PATH can move the root and preflight does not carry the path, so naming it definitely would be wrong for anyone who set it. No navigator at all keeps the POSIX spelling rather than dropping the advice, which is what the desktop shell's non-browser contexts and these tests see.

Three tests: every reason names a folder, Windows gets the Windows spelling and no POSIX one, since a path a user cannot paste into an exclusion list is not advice, and a missing navigator still answers. 15 of 15 in the file.

While checking where this message actually renders I found something worth recording rather than fixing here. It only shows when can_auto_repair is false, which on a release build is close to unreachable for these reasons: the desktop repairs silently instead. The two states where a user most needs to hear "add an exclusion" are a repair that ran and failed, and the same runtime breaking again shortly after a successful one, and neither says anything about antivirus today. Filed as #11432, since it means carrying the reason into the repair path and tracking recurrence, which is a different surface to this one.

danielhanchen and others added 3 commits September 21, 2026 14:12
The root check was stricter than the resolver it was modelling. It rejected any
root copy that existed and was not runnable, but resolve_llama_server_binary
returns the first USABLE candidate, and _usable_binary is is_file() plus
os.access(X_OK) off Windows. A root wrapper whose execute bit is gone is walked
past, build/bin runs, and the tree is fine; grading it damaged sent a working
runtime through a repair, and where repair is unavailable it blocked the launch.

Reproduced against the real resolver on a Linux tree before changing anything:

  root wrapper executable            backend picks <root>/llama-server           health (True, '')
  root wrapper chmod 0644            backend picks <root>/build/bin/llama-server health (False, binaries_missing)
  root wrapper executable but empty  backend picks <root>/llama-server           health (False, binaries_missing)

The middle row is the false positive. The third is the one that matters and is
kept: an empty wrapper keeps is_file() and its execute bit, so discovery does
select it and the exec dies on ENOEXEC.

_discovery_would_select mirrors _usable_binary, so the root copy is graded only
when the resolver would stop there. Windows keeps the current behaviour, since
_usable_binary does not consult the execute bit there and an empty .exe is still
what gets selected.

test_a_rotten_root_entrypoint_is_not_saved_by_a_healthy_build_bin asserted the
old behaviour on the strength of "the finder reaches the root first", which is
true but incomplete: it reaches it and skips it. Replaced with the empty-wrapper
case, plus a test that a 0644 wrapper and a directory of that name are both
walked past, the Windows empty-exe case, and a parity test against the backend's
own _usable_binary so the two cannot drift.

tests/studio/install/test_installed_runtime_health.py: 53 passed.
The first cut changed _damaged_entrypoint for all three callers, which also
relaxed the installer's keep decision and the release-reuse check. Those ask a
different question: whether this tree can be reused as it stands, and a rotten
root wrapper is worth replacing, which is what a reinstall is for.

selected_root_only is the launch probe's rule alone. The launch verdict follows
the resolver, so it walks past a wrapper with no execute bit and does not mark a
working runtime stale; the keep decision stays as it was. The direction is the
safe one: the launch verdict is never stricter than the repair that answers it,
which is the property that stops a tree being repaired by changing nothing and
rejected again on the next launch.

test_a_damaged_root_entrypoint_stops_the_release_being_reused keeps its point,
that the keep decision must reject where the shortcut once kept, and gains the
empty-wrapper row, which is the damage the resolver does select and run.

tests/studio/install: 8970 passed, 76 skipped, 1 failed, and that one
(test_an_unserved_preferred_arch_source_builds_rather_than_using_the_igpus_bundle)
fails identically on a clean origin/main worktree.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Under UNSLOTH_HOME the runtimes sit beside studio/, and the CLI exports
<master>/llama.cpp while UNSLOTH_STUDIO_HOME stays <master>/studio. The comparison
path dropped the override and called default_managed_llama_dir(), which reads only the
studio home, so it answered <master>/studio/llama.cpp: the installer's own export did
not match, the tree in use graded as a user pin, and master root installs never reached
the health check.

The rule now lives in _master_root_llama_dir() and both the export and the grading read
it, so there is one answer rather than two that can drift.
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1f7727ce6

ℹ️ 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".

if !looks_like_installer_managed_studio_home(root) {
return None;
}
Some(root.join("llama.cpp"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Honor recorded master roots in the runtime fingerprint

On a bare desktop launch of an install recorded under UNSLOTH_HOME (for example, a venv under <master>/studio with share/.unsloth-master-root), the CLI's _ensure_studio_env_exported() restores the note and grades <master>/llama.cpp, but this return value makes Rust fingerprint <master>/studio/llama.cpp. After one healthy result is cached, quarantining a file from the active runtime therefore does not change the fingerprint, so preflight keeps returning Ready and the later model load fails without offering repair. This inference needs to honor the recorded master-root note and fingerprint its sibling runtime.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and it is the Rust half of the split the CLI side just fixed: the note is recovered there and graded as /llama.cpp, while this inference answered /studio/llama.cpp, so the fingerprint watched a tree nothing loads and a cached Ready outlived quarantine in the one that does.

inferred_studio_llama_root now reads share/.unsloth-master-root under the same containment rule _recorded_master_root applies, the recorded root must exist and must contain this Studio tree, and fingerprints the sibling runtime. The legacy and non-installer shapes are still declined before that runs. Tests cover the note, a note naming somebody else's root (the tree under studio/ stands), an empty note and one naming a directory that is not there. No Rust toolchain on the machine I am on, so these run in CI rather than locally. 9c488e1

The Rust half of the same split: inferred_studio_llama_root() answered
<master>/studio/llama.cpp for an install recorded under UNSLOTH_HOME, while the CLI
grades and the backend loads <master>/llama.cpp. One healthy cached result then
survived quarantine in the runtime in use, so preflight kept returning Ready and the
failure only appeared at model load, with no repair offered.

It now reads share/.unsloth-master-root under the same containment rule the CLI applies
(the recorded root must exist and contain this Studio tree) and fingerprints the
sibling runtime. Tests cover the note, a note naming somebody else's root, an empty one
and one naming a directory that is not there.
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 9c488e12d7

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants