Skip to content

Studio: stop the macOS update re-probing binaries and resolving 16 releases - #11237

Merged
danielhanchen merged 17 commits into
unslothai:mainfrom
oobabooga:mac-update-probe-walk
Sep 18, 2026
Merged

danielhanchen merged 17 commits into
unslothai:mainfrom
oobabooga:mac-update-probe-walk

Conversation

@oobabooga

@oobabooga oobabooga commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Updating Unsloth Studio on macOS can take about a minute even when llama.cpp is already current. On a macos-15 runner, the llama.cpp step took 42 to 59 seconds, compared with 0.5 to 1.4 seconds on Linux.

Two macOS-specific costs caused the delay:

  • The reuse paths reran each installed binary with --version to verify that dyld could load its dependencies. A cold llama-server probe took 24 to 42 seconds, while later runs took about 0.04 seconds.
  • The macOS release fallback resolved up to 16 releases before using the first one. This cost 66 requests and about 13 seconds, even though releases 2 through 16 were needed only if an earlier bundle was rejected. macOS also bypassed the CDN and used the rate-limited GitHub API for this walk.

Changes

Reuse the recorded macOS load result

The installer already records each runtime binary's size and sha256 in runtime_files. Those records are written only after the binaries pass the platform preflight.

The three existing-install paths now skip the dynamic dyld probe when:

  • all recorded runtime digests still match;
  • the recorded host_profile matches the current host; and
  • UNSLOTH_PREBUILT_FULL_CHECK is not enabled.

The static Mach-O minimum-version check still runs every time, so a bundle built for a newer macOS is still rejected without starting it.

Markers without runtime_files or host_profile, a changed host, a digest mismatch, and full-check runs still take the dynamic probe. No marker field or install fingerprint changed, so existing installs are not invalidated.

Resolve fallback releases lazily

LazyReleasePlans resolves the first release immediately and later releases only after the installer rejects the current plan. The fallback depth and ordering are unchanged.

macOS now resolves the newest release through the CDN. It reaches the GitHub API only when it needs an older release and skips the release already returned by the CDN.

Deferred network failures keep the install path's previous behavior: they can preserve a runnable existing install or request a source build. Resolver probes still fail hard so a transient 403 is not cached as "no prebuilt" for 24 hours.

Results

On macos-15, checking a current install:

Before After
Wall time 30.52 s 0.81 s
--version spawn 29.25 s none

For an older marker that still requires the load probe:

Before After
Wall excluding the variable load-probe time 15.6 s 2.0 s
Releases resolved 16 1
Requests 66 6
Requests to api.github.com 2 0

Full unsloth studio update runs:

Before After
Run 1 147.5 s 100.9 s
Run 2 109.3 s 77.7 s

On an M1 Mac mini, the older-marker path fell from 37.74 seconds and 16 releases to 24.43 seconds and one release. A current, already-assessed install fell from 1.69 seconds to 0.99 seconds.

Linux behavior is unchanged. It already used the CDN, resolved one release, and never ran the macOS probe.

Safety and tests

The intentional limitation is unchanged bytes on an unchanged macOS version becoming unloadable for an external reason. An update will not rediscover that state unless UNSLOTH_PREBUILT_FULL_CHECK=1 is set. Fresh installs and changed binaries still run the probe.

Added 22 focused cases covering all three reuse paths, missing or stale evidence, binary replacement, dyld rejection, lazy resolution order and limits, CDN to API fallback, and deferred 403 handling through the complete install path.

Test results:

  • tests/studio/install/ with the unrelated test_rocm_support.py failure deselected: 4551 passed, 1581 skipped.
  • studio/backend/tests/test_install_resolve_prebuilt.py and test_llama_cpp_update.py: 375 passed, 1 skipped.

@oobabooga

Copy link
Copy Markdown
Member Author

Converged at oobabooga#256.

image

@Lyxot Lyxot self-assigned this Sep 18, 2026
… probe skip

Re-raise the last release failure once the lazy plan iteration ends instead of looking ahead through LazyReleasePlans.has_index and _has_release_plan, and write iter_release_plans with yield from.

Build the ROCm attempts inside _with_rocm_behind_vulkan's try: the plans resolve lazily, so a later release's listing failure escaped it and abandoned the Vulkan install (or failed --resolve-prebuilt hard) instead of dropping the CPU tail.

Keep the dyld probe when the macOS version is unknown. An unparseable platform.mac_ver() records macos_version as None on both sides, so the host profiles compared equal while the minos check was also skipped, leaving no load check at all.

Let the macOS planner keep the download-host fast path on and pass only continue_after_fast_path, fold the record-hash check into _macos_load_record_is_current, and tighten comments, including ones that still said macOS turns the download host off.

Adapt the probe-record and lazy release-plan tests to iterate plans through iter_release_plans, and add coverage for the ROCm fallback and an unknown macOS version.
@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Pushed 85518c7 on top of your two commits. The probe skip and the lazy walk are kept as designed; this adds two fixes and removes some machinery:

  • ROCm fallback bug: _with_rocm_behind_vulkan read the lazy ROCm plans outside the try that used to swallow ROCm failures. On a Vulkan-preferred AMD iGPU host with the CDN unavailable, a listing failure on an older release escaped and abandoned the Vulkan install, or made --resolve-prebuilt exit hard. The read now sits inside the try.
  • Unknown macOS version: with an unparseable platform.mac_ver(), both host profiles record macos_version: None and compare equal, and the minos check is skipped too, so the skip left the install with no load check. An unknown version now always probes, as before this PR.
  • Simpler lazy walk: the install loop re-raises the last release failure once iteration ends, so LazyReleasePlans.has_index and _has_release_plan are gone and iter_release_plans is a plain yield from.
  • Clearer flags: the macOS planner passes only continue_after_fast_path instead of allow_download_host_fast_path=False plus continue_after_fast_path=True.
  • Hash check: the check for a fully hashed record is folded into _macos_load_record_is_current.
  • Comments: tightened, and fixed the ones that still said macOS turns the download host off.
  • Tests: your two test files are kept, adapted to iterate plans through iter_release_plans, plus tests for the ROCm fallback and the unknown-version case.

@Lyxot

Lyxot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

Codex review on a staging copy (Lyxot#62, diff identical to this PR at 85518c7) converged: Lyxot#62 (comment)

The first pass raised two P2s, answered and resolved in-thread without code changes: the pinned-release double resolve does not occur, and the inherited DYLD_LIBRARY_PATH case needs a bundle missing its own @rpath library.

CI on the staging PR: 46 passed, 3 skipped, 6 failed. All 6 failing jobs fail the same way on the previous staging PR (Lyxot#61), and none touch this change:

@danielhanchen danielhanchen self-assigned this Sep 18, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 18, 2026
The probe skip trusted two things it had not established.

An inconclusive probe was remembered as a pass. macos_dyld_load_issues fails
open on purpose: a timeout or a refusal to spawn is logged and returns no
issue, so a loaded machine cannot lose a healthy bundle. The runtime record
was then written immediately after, carrying no trace of whether the probe had
actually run, and every later update skipped the probe on the strength of it.
Before this PR that cost one retry per update and healed itself; with the skip
it never retried. The reported cold probe of 24 to 42 seconds against a 60
second timeout makes that reachable rather than theoretical.

preflight_macos_installed_binaries now reports whether dyld really resolved
every binary, and only then does the marker gain macos_load_probe. A marker
without it takes the probe, which is what every update did before the skip
existed, so no existing install is invalidated and the key is not
fingerprinted.

host_profile could not see a macOS point release. It records
parse_macos_version, which is (major, minor), so 15.5 and 15.5.1 compare
equal. Since Big Sur the system libraries are a dyld shared cache blob that
Apple replaces in point releases and in Rapid Security Responses, which is
precisely the case of unchanged bundle bytes that stop loading, and the case
the probe was added for in unslothai#9843. The recorded evidence now carries the full
product version, so a patch update probes again while an unchanged one still
skips.

Two smaller ones in the release walk:

- A pinned tag resolved twice under continue_after_fast_path. The download
  host had already yielded it, and the pinned block below resolved the same
  tag again through api.github.com. A pin names one release and has nothing
  to walk back to, so the fast path returns.
- LazyReleasePlans forgot why it stopped. A generator that raised is closed,
  so a second traversal reported a short, clean sequence and len() disagreed
  with the call that had raised. The failure is kept and re-raised.

Tests: an install whose probe never ran still probes; a timed out probe
reports no pass while still not rejecting the bundle; a patch update probes
again and an identical one does not; a pin resolves once with the walk-back
on and still reaches the API when the download host is unavailable; a failed
walk reports the same failure every time.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 18, 2026
@Lyxot Lyxot removed their assignment Sep 18, 2026
danielhanchen and others added 5 commits September 18, 2026 12:14
The probe skip was unreachable for anyone not born with the record. Only a fresh
install wrote macos_load_probe, and the three reuse paths discarded what their own
preflight had just learned, so a marker written before the record existed, an
install whose first probe timed out, and every install after a macOS point release
re-ran the expensive dyld probe on EVERY later update and never stopped.

Each reuse path now records a probe that actually ran and loaded every binary. A
legacy marker whose payload entries carry sizes but no digests is re-recorded at the
same moment, since that shape can never satisfy the skip either. Both are safe here
and nowhere else: the minos check, whatever digests the marker did carry, and dyld
itself all passed on these exact bytes moments earlier, which is the same evidence
the install path records on. A probe that could not run still records nothing, so a
fail-open timeout does not become a pass.

Measured on a marker written by the pre-change installer: update 1 probes once and
upgrades the record from 6 of 9 files hashed to 9 of 9, updates 2 and 3 probe zero
times. Before this, every update probed.

Tests: a passing reuse probe is remembered and the next update skips; a legacy
size-only marker is upgraded by it; a probe that could not run is not remembered.
The spawn-counting fixture now reports which binaries loaded, because a stub that
only returned no issues exercised the no-evidence path rather than the pass.
platform.mac_ver() reads ProductVersion, and an RSR does not move it. macOS 13.3.1
(a) reports ProductVersion 13.3.1 with the "(a)" in ProductVersionExtra and the build
at 22E772610a instead of 22E261, so the probe skip went on accepting a pre-RSR result
across exactly the event the comment claimed it caught. Reading SystemVersion.plist
has the same blind spot and is additionally stale for an RSR (osquery/osquery#8008).

The recorded identity now comes from sw_vers, joining --productVersion,
--productVersionExtra and --buildVersion, so a point release, an RSR and a plain
build bump each invalidate it. --productVersionExtra exits non-zero when no RSR is
installed and did not exist before macOS 13, so absent is recorded as absent rather
than treated as a failure; if sw_vers cannot be run at all the product version alone
is kept, which still catches a point release.

Tests: an RSR probes again; the recorded string carries all three fields in order;
a host with no RSR still yields a version.
The fixture writes shell scripts as stand-in binaries, so on Windows
_binary_image_runs correctly reports a bad exe format and the install reads as
unusable: the six tests that let _existing_install_runs start them assert a True
they cannot get there. _pr10648_helpers.POSIX_ONLY already exists for this class.
The tests that skip the probe, or stub the spawn, keep running on Windows.
sw_vers documents single-dash options (-productVersion), so the double-dash forms
this used are at best undocumented, and a flag that errors would have silently cost
the ProductVersionExtra and BuildVersion fields that were the entire point: the
function would have fallen back to platform.mac_ver() and gone on accepting a
pre-RSR probe.

Bare sw_vers prints every field as documented tab-aligned Key: Value lines,
ProductVersionExtra among them when a Rapid Security Response is installed. One
spawn instead of three, and nothing to spell wrong. An absent ProductVersionExtra
still reads as no RSR, and an unavailable sw_vers still falls back to the product
version, which catches a point release.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 18, 2026
pre-commit-ci Bot and others added 6 commits September 18, 2026 12:48
_existing_install_runs recorded straight after the dyld probe, then went on to start
the root copies. The root entrypoint can be a separate wrapper rather than a symlink,
so a corrupt one was hashed into the digest record and given probe evidence before it
was ever started; the call still returned False, but the NEXT one read that record as
current, returned before the wrapper was reached, and accepted an unusable entrypoint.
For a pre-change marker the same write also upgraded its size-only payload entries on
the strength of a check that had not finished.

Recording now happens after every image has started, and in
existing_install_matches_choice after the fingerprint and field comparisons rather
than before them, so no tree that is about to be rejected gets its payload re-hashed.
existing_install_current_without_plan already recorded on its success path.

Test: a root wrapper that will not start leaves no probe evidence and no upgraded
record, and fails with the previous ordering.
The record covers the root copies as well as build/bin, and a later run skips
starting them on the strength of it. Only a caller that has started them all can
honestly write it, and the two reuse fast paths cannot: both probe build/bin alone
and neither reaches a root llama-server, which can be a separate wrapper rather than
a symlink. Persisting from there recorded and hashed a wrapper nothing had started,
and _existing_install_runs then read the record as current and returned before it
would have started the wrapper either.

Persistence now happens only in _existing_install_runs, after every image has run.
existing_install_matches_choice and existing_install_current_without_plan still probe
and still reuse; they just no longer write evidence they did not gather.

Test: neither fast path leaves probe evidence, even though both probed.
The persist_macos_load_probe docstring and its one call site both spelled out the
root-wrapper ordering at length; the docstring now states the precondition and the
call site keeps the reason it comes last. macos_product_version keeps why sw_vers
is asked bare, in a clause rather than a paragraph.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 18, 2026
@danielhanchen
danielhanchen merged commit df0d65b into unslothai:main Sep 18, 2026
9 of 52 checks passed
@danielhanchen

Copy link
Copy Markdown
Member

Review pass finished. Verdict: the problem is real, the approach is right, and the branch is ready to merge with the fixes below folded in.

What I verified

The claimed defect reproduces on the merge base. Driving a simulated macOS host through the reuse path, base resolves 16 releases and issues 66 requests, 2 of them to api.github.com; head resolves 1 and issues 0 API requests. The dyld probe goes from 1 spawn per binary per update to 0 on an unchanged install. Linux and Windows selection output is byte-identical across 324 enumerated cells (310 unchanged, 14 changed and all in the safer direction), and a 32-cell device matrix shows no host_profile or selection differences.

Fixes I pushed to this branch

  1. The probe pass is only recorded when dyld actually resolved every binary. Previously a probe that timed out or could not spawn was remembered as a pass, and the skip became permanent. Absent evidence reads as "cannot say" and probes again, so no existing install is invalidated, and the key is not fingerprinted.
  2. The evidence carries the full macOS product version. parse_macos_version is (major, minor) by design, which is right for the minos comparison and wrong for "can this image still load": the system libraries are a dyld shared cache blob that Apple replaces in point releases. 15.5 to 15.5.1 was being skipped; it now probes, and an identical version still skips.
  3. A pinned tag returns from the download-host fast path instead of falling through and being resolved a second time through the API. Latent on the shipped flow, one refactor away from a duplicate plan.
  4. LazyReleasePlans remembers why it stopped and re-raises, so a second traversal cannot report a short, clean sequence that disagrees with the call that raised.
  5. Installs that predate this PR now reach the fast path. Their marker records the three binaries but not the payload, and the backfill only fills an absent value, so the fully-hashed form the skip requires was never reached and every update re-probed forever. A path that has started every image now re-records the runtime files and writes the pass, so the second update after upgrading is the fast one.
  6. macos_product_version ran sw_vers --productVersion. sw_vers documents single-dash options, so the double-dash form prints usage and exits non-zero and the version silently fell back to platform.mac_ver(). It now runs sw_vers bare and parses the Key: Value block, joining ProductVersion, ProductVersionExtra and BuildVersion, so a Rapid Security Response and a build bump both re-probe.
  7. The record is written only from _existing_install_runs, after every image has started. It covers the root copies too and a later run skips starting them on the strength of it, but the two reuse fast paths probe build/bin alone and never reach a root llama-server, which can be a separate wrapper rather than a symlink.
  8. Three of the new macOS tests use #!/bin/sh stand-ins, which are not a valid Windows exe image, so they carry POSIX_ONLY.

Each fix has a regression test that fails on the commit before it.

Test results

tests/studio/install/ is 6751 passed, 32 skipped, 0 failures; the studio backend suites are 509 passed, 1 skipped; merged with current main, the targeted run is 384 passed, 1 skipped. Ruff and the duplicate-definition and import-hoist checks are clean.

Because the org queue cancelled the runs at this head, I re-ran the three platforms on a staging repo instead. ubuntu-latest and macos-15 pass. windows-latest reports 43 failed, 327 passed: I ran the merge base through the same job and it fails the same 43, all in test_install_llama_prebuilt_logic.py (the WSL bash stub, a disk-space setup failure, and Linux-only paths exiting early). Those are pre-existing and not touched here. Neither test_macos_loader_probe_record.py nor test_release_plan_laziness.py fails on any platform.

What I could not prove from here

This host is Linux, so real dyld load semantics, the cold-start --version timings and the M1 numbers in the description are not reproducible here; the macOS CI legs are the closest evidence. The laziness win is also narrower than it reads: _backend_only_release_plans and _with_rocm_behind_vulkan iterate to exhaustion, so every concrete-backend request and every Vulkan-over-ROCm route still resolves the whole walk-back. The default auto update path, which is what the numbers describe, is unaffected.

rhsCZ pushed a commit to rhsCZ/unsloth that referenced this pull request Sep 20, 2026
…ng one machine's path

Merging main up brought in test_macos_loader_probe_record.py from unslothai#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 added a commit that referenced this pull request Sep 22, 2026
…t model load (#10494)

* Repair a quarantined llama.cpp runtime at launch instead of failing at 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.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Close the gaps the simulations found, and prove the repair cannot loop

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.

* Format the new install-health files with the pinned ruff

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

* Fix the review round, and two defects the simulations found under it

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.

* Give a runtime tree with no build/bin its own fingerprint

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.

* Catch up the fingerprint tests with the bin and nobin prefixes

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.

* Tighten the comments on the runtime health preflight

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.

* Address review: per-library macOS payload groups, ~user paths, blank 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.

* Address review: macOS SONAME links, the execute bit, and which runtime 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.

* Ask for the execute bit by the tree's platform, not the interpreter's

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.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address review: the fingerprint's blind spots, and which tree it watches

- The runtime fingerprint counted regular files only, so deleting an install-name
  link (libggml.0.dylib, or the SONAME link on Linux) or taking the execute bit
  off llama-server left it identical. Both are states installed_runtime_health
  rejects, so a cached Ready went on matching a tree that could no longer launch.
  Links and executable files are counted now.
- An installer-managed venv under a custom root names its own runtime. The
  desktop strips UNSLOTH_STUDIO_HOME before spawning the CLI, but the CLI
  re-infers the root from sys.prefix and points UNSLOTH_LLAMA_CPP_PATH at its
  llama.cpp, so reading only the ambient environment fingerprinted the legacy
  tree and quarantine in the real one never invalidated anything.
- An override holding no server does not end the search, so it is no longer
  treated as final on either side. The CLI names the tree it grades rather than
  answering yes or no, so the two cannot pick different trees.
- ~name resolves through getpwnam_r. getpwnam hands back process-global storage
  and this runs on a Tauri worker thread, where a concurrent lookup could
  overwrite pw_dir mid-copy.

* Address review: entrypoints that are files, the mode bits, and one override spelling

installed_runtime_health asked os.access(X_OK), which a directory named llama-server
answers true for because directories are searchable, while the finder asks is_file()
and rejects the tree. Both now go through one helper that _existing_install_runs
shares, so the keep-or-reinstall decision and the launch verdict cannot disagree.

The runtime fingerprint counted files with any execute bit, but os.access(X_OK) asks
whether this user may run one: 0755 to 0655 leaves group and other executable and the
owner unable to run it, so the count never moved for a state health rejects. The
permission bits themselves are summed instead.

_find_llama_server_binary read UNSLOTH_LLAMA_CPP_PATH literally while
default_managed_llama_dir, get_stored_custom_llama_cpp_path and the desktop's pinning
all expand it, so a ~/llama.cpp written into a service unit or a .env sent discovery to
a folder named ~ beside the working directory and every other component reported on a
different tree. It expands now, and so does the orphan reaper's allowlist, which has to
name the tree discovery spawns from.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address review: the split entrypoint libraries, and reuse asking what the probe asks

Two of the three items from the last round, both measured against a b10360
managed install rather than a fixture.

1. The Linux impl split had no payload group.

ggml-org/llama.cpp#23462 moved each binary's entry code into a lib<binary>-impl
library. Windows already required llama-server-impl.dll, gated on the build the
split landed in. Linux got the same treatment upstream and none of it here: the
groups name the shared libraries only, so libllama-server-impl.so and
libllama-quantize-impl.so were required by nothing.

Measured on a copy of the managed install, removing either one:

  installed_runtime_health -> (True, "")
  _existing_install_runs   -> False

which is the disagreement the whole probe exists to remove, in the direction
that hurts: preflight says Ready and llama-server dies in the loader.

_linux_split_entrypoint_groups adds both, gated the same way the Windows side is
and on the same build number, since it is one upstream commit rather than one
platform's packaging. A source build ships neither whatever the tag says, and a
pre-split archive is healthy without them, so requiring one of those would
reinstall on every check forever.

2. The exact-release reuse decision asked exists() where the probe asks for the
execute bit.

installed_runtime_health asks _entrypoint_is_runnable, because that is what
_find_llama_server_binary asks. existing_install_matches_choice asked exists(),
and its Linux ldd gate reads a non-executable ELF quite happily. Clearing the
execute bit on llama-server, again on a real copy:

  installed_runtime_health -> (False, "llama_runtime_binaries_missing")
  _existing_install_runs   -> False
  exists()                 -> True
  preflight_linux_installed_binaries -> passes

so preflight says broken, repair says the exact release is already installed,
nothing is downloaded, and the next launch says broken again. Both attempts land
in the same place. It now calls _entrypoint_is_runnable, which is the same test
both other answers use.

Tests:

- test_quarantining_a_split_entrypoint_library_is_reported_broken, per library,
  against a managed copy, asserting the two answers agree afterwards.
- test_an_older_monolithic_linux_release_is_not_asked_for_the_impl_libraries,
  which pins the gate rather than the requirement: b9279 owes neither, b9283
  owes both, a source build owes neither.
- test_a_stripped_execute_bit_is_not_reused_as_an_exact_release_match, checking
  the two gates directly.
- The fixture tables gain both libraries, and the shape writers now chmod the
  entrypoints, which a real extraction does and the reuse decision now reads.

tests/studio/install: 5991 passed, 6 skipped. cargo test --bin unsloth-studio:
571 passed.

The third item, a versionless libllama.so surviving its SONAME's removal, does
not apply: the release ships exactly two names per library, libllama.so.0 beside
libllama.so.0.0.10360, with no versionless file and no symlinks. Replied on the
thread.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address review: resolve a named-user override the same way on both sides of a spawn

preflight::managed resolves UNSLOTH_LLAMA_CPP_PATH=~alice/llama.cpp through
getpwnam_r, the way posixpath.expanduser does. process.rs, pinning the same
variable for the child it is about to move, read it with the Windows rule, which
leaves ~alice alone off Windows, so it fell through to being anchored under the
directory being left.

Measured, with the two halves side by side on this host:

  preflight::managed  ~root/llama.cpp -> /root/llama.cpp
  process.rs pin      ~root/llama.cpp -> /mnt/work/session/~root/llama.cpp

The child is handed the pinned value, so it grades and runs one tree while the
cache fingerprints another. Quarantining a file from the tree actually in use
then never invalidates a Ready verdict, which is the whole failure this
fingerprint exists to catch.

expand_user now makes the split every other reader in that function already
makes, Windows rules on Windows and the native ones off it, and expand_posix_user
resolves the named form through the same lookup preflight::managed uses, which is
now pub(crate) rather than duplicated. An unknown name is left exactly as it
arrived, which is what expanduser does, so both halves fall through to anchoring
it and still agree. Bare ~ and ~/rest are unchanged: they went through
expand_windows_user's empty-name arm, which answers home on any platform, and
they go through the posix one now.

Windows was already aligned. named_user_home's Windows arm delegates to
named_windows_user_home, which is the same rule expand_windows_user applies.

Tests, all three unix-only since they turn on the password database:

- a_named_user_override_is_pinned_where_the_fingerprint_watches, asserting the
  pin is not under the directory being left and equals what the fingerprint side
  reaches through the same lookup.
- an_unknown_named_user_is_left_alone_and_anchored_by_both_halves.
- a_bare_tilde_override_still_reaches_home_off_windows, for the form that already
  worked.

cargo test --bin unsloth-studio: 574 passed. tests/studio/install: 5991 passed,
6 skipped.

* Address review: the SONAME beside a flattened versionless copy, and an override that cannot expand

Two items, and the first one corrects a rebuttal of mine that was wrong.

1. A versionless copy kept the group satisfied after the SONAME was quarantined.

I argued against this last round on the grounds that the bundle ships exactly two
names per library. That was true of the tree I measured, the b10360 install on
this machine, and it is not true of what the installer produces today. Two things
moved underneath it:

  - b10840 ships the trio. libllama.so -> libllama.so.0 -> libllama.so.0.4.0, as
    symlinks in the tarball.
  - copy_globs flattens them. It selects with is_file() and copies with
    shutil.copy2, which follows symlinks, so all three arrive in build/bin as
    independent regular files. My reproduction moved the extracted tree instead,
    which kept the links, and a dangling link is dropped by is_file() on its own.
    That made the argument look decisive about a shape no install has.

Extracting b10840 with prebuilt_core.extract_archive and installing it through
copy_globs, which is the path install_prebuilt takes:

  baseline                          health=(True, "")
  quarantine libllama.so.0          health=(True, "")   runs=False
  quarantine libggml.so.0           health=(True, "")   runs=False
  quarantine libllama-common.so.0   health=(True, "")   runs=False
  quarantine libggml-base.so.0      health=(True, "")   runs=False
  quarantine libmtmd.so.0           health=(True, "")   runs=False

_payload_match_is_loadable can no longer answer from the name alone, because
libllama.so means one thing in a family that has a SONAME and another in a family
that never had one. It now reads the family: a versionless name counts only when
nothing versioned sits beside it. Any versioned sibling disqualifies it, not only
a SONAME-shaped one, since asking for a SONAME specifically would read the family
as versionless again exactly when the SONAME is the file that went missing.

Same rule on macOS, where dyld asks for the install name in LC_ID_DYLIB:
libggml.dylib does not stand in for libggml.0.dylib.

2. An unresolvable named user made runtime discovery throw.

Path.expanduser() raises RuntimeError when it cannot determine the home, which
includes every unknown named user, unlike os.path.expanduser, which hands the
value back:

  Path("~no-such-account-anywhere/llama.cpp").expanduser()
  RuntimeError: Could not determine home directory.

Every reader of UNSLOTH_LLAMA_CPP_PATH used the raising form, so a pin left in a
service unit or a .env after an account rename took discovery down with it rather
than being treated as unusable, and several callers have no exception boundary.
Four sites, not the one reported: the search, the process allowlist that has to
name the same tree, the settings reader and the status payload the UI renders.

expanded_user_path is the non-raising expansion, shared by all four so they cannot
diverge, and it leaves an unresolvable name exactly as it arrived, which is what
the desktop's pinning does with one too.

Tests:

- test_the_flattened_trio_installs_healthy and
  test_quarantining_a_soname_beside_a_versionless_copy_is_reported_broken, per
  library, built from the b10840 asset through copy_globs, asserting the three
  names really are flattened regular files first, so the test cannot pass for the
  dangling-link reason instead. Skipped where the asset is absent, as the rest of
  that file is.
- test_a_family_that_only_ever_ships_one_name_is_still_loadable and the macOS
  counterpart, both artifact-free, for the half a blunter rule would break:
  libggml-cpu-x64.so has no versioned copy anywhere and is the name the loader
  asks for.
- The expanduser guard, including the status payload and discovery reaching its
  own answer rather than raising.
- test_a_dangling_library_symlink_does_not_count_as_present now builds all three
  rungs, which is what its own docstring already described; it had been building
  the outer two, and the SONAME rung is what the new rule needs to see.

tests/studio/install: 5999 passed, 6 skipped. studio/backend/tests -k "llama_cpp
or path_settings": 1928 passed, 4 skipped. cargo test --bin unsloth-studio: 574
passed.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address review: the HIP module by name, both impl halves, and a marker that will not parse

Six items, each measured against a real bundle built through copy_globs rather
than reasoned about.

ggml-hip.dll by name, not "*hip*.dll". app-b10798-mix-659e406-windows-x64-rocm-gfx1150
ships amdhip64_7.dll, hipblas.dll and libhipblaslt.dll beside it, and all four
match that pattern, so quarantining the one module ggml actually loads left the
group satisfied by three libraries that cannot stand in for it. Measured:
installed_runtime_health answered (True, "") with the backend gone.

llama-quantize-impl.dll under the same split-build gate as the server's.
llama-quantize.exe links against its own impl library exactly as llama-server.exe
does, and every post-b9283 bundle ships both, so requiring one let a quarantined
quantize implementation read as healthy while quantization could not start.

A marker that exists but will not parse names no source, and the source-gated
groups were dropped with it: on Windows llama.dll stood in for the whole payload,
so an interrupted marker plus a quarantined ggml-base.dll answered healthy.
Assuming "published" instead would be worse, because a statically linked source
build ships none of those names and would fail health on a tree the setup scripts
keep, repairing on every launch with nothing to change. _tree_looks_prebuilt reads
the source off the tree from a name only a release ships, and stays lenient when
quarantine has taken the evidence too.

The runtime fingerprint now includes entry names. Its four counters are all
aggregates, and a rename in place moves none of them, so security software that
renames ggml-base.dll beside itself left the cached Ready matching a tree
installed_runtime_health rejects, and preflight answered Ready without running the
capability probe. FNV-1a rather than DefaultHasher, so a toolchain bump does not
invalidate every cached verdict; summed rather than folded, because read_dir order
is unspecified and the counters beside it are order-independent for that reason.

The CLI classifies UNSLOTH_LLAMA_CPP_PATH instead of trusting the marker.
studio/backend/main.py calls mark_managed_llama_cpp_path before discovery, which
marks any override equal to the managed tree however it got there, and the finder
then skips it; _ensure_studio_env_exported writes exactly that value under a
custom STUDIO_HOME and sets no marker. So preflight graded the managed tree as a
user pin while the backend walked past it to the stored selection, blocking launch
over a tree nothing would open. Compared against the studio home's own path with
the override out of the way, never default_managed_llama_dir(), which reads the
override first and would call every user pin managed.

expanded_user_path at the last Path.expanduser left in the doctor, a gap in the
earlier pass: a "~name" naming no account raises RuntimeError out of a command
whose whole job is to answer.

Also: the stored-selection stub in test_desktop_capability_llama_runtime was
missing expanded_user_path, so the helper's import raised and every test in that
file was silently grading the except fallback rather than the code it names.

tests/studio: 10171 passed, 198 skipped. cargo test --bin unsloth-studio: 575
passed. The four new payload tests and the CLI one all fail on the previous head.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Gate the PowerShell reuse shortcut on runtime health, as the shell already is

The POSIX half of this loop was closed and the Windows half was not. setup.ps1
reaches "already built" through an elseif on Test-PathQuiet $LlamaServerBin, so a
Windows repair that fell through to the source stage kept a tree whose
ggml-base.dll had been quarantined, returned it byte for byte identical, and
reported success. Desktop preflight grades that same tree on every launch, so it
offered the same repair forever.

Test-LlamaTreeStillHealthy makes the same --check-existing-install call setup.sh
makes, through Invoke-LlamaHelper, so there is one definition of healthy rather
than two that can disagree. It answers healthy on any failure to ask: a helper
that cannot run must not turn into a multi-gigabyte source build on a machine
whose only fault was an unreadable tree.

The reason this survived is in the convergence model's own comment, which said
setup.ps1 had no reuse step and that a Windows update reaching the source stage
always builds. That was wrong, and the model therefore never exercised the
Windows branch. It now models both shells, and reverting the gate in the model
fails every Windows cell of
test_no_damaged_tree_survives_the_shell_rebuild_skip, which is what it should
have done all along.

A model cannot catch a shell losing its gate, so
test_both_shells_gate_their_reuse_shortcut_on_the_same_check reads both scripts
and asserts the check sits on the shortcut itself rather than somewhere else in
the file.

tests/studio/install: 6007 passed, 6 skipped.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Reject a library renamed in place instead of letting it satisfy its own group

* Grade the root entrypoint, and plan the Windows rebuild the health gate forces

* Grade the studio root the desktop scrubbed, and fix the Windows fixture

* Reject empty payload files, and stop grading a runtime no repair can reach

* Give the entrypoint check one owner, and cache only what the probe read

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Close the repair loop between the launch check and the update

Found by simulating the cycle a user walks rather than by testing the new
check on its own, and reproduced before being fixed.

installed_runtime_health rejects a root llama-server or llama-quantize that
lost its execute bit, so the desktop marks the install stale and offers a
repair. existing_install_current_without_plan is the shortcut
install_prebuilt returns on before reinstalling anything, and it checked
os.access(X_OK) under build/bin ONLY, while _find_llama_server_binary
reaches the install root's copy FIRST. So the repair ran, changed nothing,
and the next launch was stale again.

Measured, with an undamaged install accepted as the control:

  root llama-server -x    launch health broken, shortcut True,  full False
  root llama-quantize -x  launch health broken, shortcut True,  full False
  build/bin copy -x       launch health broken, shortcut False, full False

_damaged_entrypoint now answers for the shortcut too, which is what its own
docstring already asks for: one owner, so a tree one check rejects and
another keeps cannot be repaired by changing nothing. It is four stat plus
os.access calls and spawns nothing, so the shortcut stays a shortcut.

test_the_execute_bit_is_checked_on_the_runtime_copies_only pinned the old
boundary, so it is rewritten as
test_the_execute_bit_is_checked_on_every_entrypoint, keeping the visual
server as the control that stops the fix becoming "reject everything".

tests/studio/install plus test_llama_cpp_path_settings.py: 8787 passed,
65 skipped.

* Require the split entrypoint dylibs on macOS

The impl split that gave Windows llama-server-impl.dll and Linux
libllama-server-impl.so gives macOS libllama-server-impl.dylib and
libllama-quantize-impl.dylib, and the macOS branch of
runtime_payload_health_groups was the one that did not ask for them. Quarantining
either left every library group satisfied and both execute-bit checks passing while
dyld could not start the entrypoint, so installed_runtime_health answered Ready on
the platform this probe exists for.

Verified against the real bundles rather than assumed: both
llama-b10840-mix-d5c17a0 and llama-b11007-mix-3e83366 macos-arm64 ship the two,
unversioned, beside the entrypoints. _PREBUILT_TREE_EVIDENCE already reads
libllama-server-impl*.dylib as proof of a prebuilt macOS tree.

_macos_split_entrypoint_groups delegates the gate to its Linux counterpart rather
than repeating it, so the source labels and the b9283 floor cannot drift.

The three fixtures that claimed to list a real macOS bundle were short of these two
files and now carry them, and the matrix states the requirement independently with
the matching pre-split pruning. New test with the loop-direction control: a pre-split
upstream b6099 bundle never shipped them and stays healthy.

* Shorten the macOS split docstring

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

* Grade the macOS fixture against a real bundle, and stop a test carrying 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.

* Name the folder the antivirus advice is asking the user to allow

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.

* Grade a root entrypoint only when discovery would start it

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.

* Scope the root-entrypoint relaxation to the launch verdict

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.

* Grade the runtime a master root install actually uses

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.

* Fingerprint the runtime a master root install actually loads

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.

* [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>
Co-authored-by: danielhanchen <[email protected]>
Co-authored-by: oobabooga <[email protected]>
Co-authored-by: danielhanchen <[email protected]>
Co-authored-by: danielhanchen <[email protected]>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…leases (unslothai#11237)

* Studio: stop the macOS update re-probing binaries and resolving 16 releases

* Hash the macOS runtime payload so the probe skip covers the load graph

* refactor(studio): simplify the lazy release walk and harden the macOS probe skip

Re-raise the last release failure once the lazy plan iteration ends instead of looking ahead through LazyReleasePlans.has_index and _has_release_plan, and write iter_release_plans with yield from.

Build the ROCm attempts inside _with_rocm_behind_vulkan's try: the plans resolve lazily, so a later release's listing failure escaped it and abandoned the Vulkan install (or failed --resolve-prebuilt hard) instead of dropping the CPU tail.

Keep the dyld probe when the macOS version is unknown. An unparseable platform.mac_ver() records macos_version as None on both sides, so the host profiles compared equal while the minos check was also skipped, leaving no load check at all.

Let the macOS planner keep the download-host fast path on and pass only continue_after_fast_path, fold the record-hash check into _macos_load_record_is_current, and tighten comments, including ones that still said macOS turns the download host off.

Adapt the probe-record and lazy release-plan tests to iterate plans through iter_release_plans, and add coverage for the ROCm fallback and an unknown macOS version.

* Record that the macOS load probe ran, and compare the full macOS version

The probe skip trusted two things it had not established.

An inconclusive probe was remembered as a pass. macos_dyld_load_issues fails
open on purpose: a timeout or a refusal to spawn is logged and returns no
issue, so a loaded machine cannot lose a healthy bundle. The runtime record
was then written immediately after, carrying no trace of whether the probe had
actually run, and every later update skipped the probe on the strength of it.
Before this PR that cost one retry per update and healed itself; with the skip
it never retried. The reported cold probe of 24 to 42 seconds against a 60
second timeout makes that reachable rather than theoretical.

preflight_macos_installed_binaries now reports whether dyld really resolved
every binary, and only then does the marker gain macos_load_probe. A marker
without it takes the probe, which is what every update did before the skip
existed, so no existing install is invalidated and the key is not
fingerprinted.

host_profile could not see a macOS point release. It records
parse_macos_version, which is (major, minor), so 15.5 and 15.5.1 compare
equal. Since Big Sur the system libraries are a dyld shared cache blob that
Apple replaces in point releases and in Rapid Security Responses, which is
precisely the case of unchanged bundle bytes that stop loading, and the case
the probe was added for in unslothai#9843. The recorded evidence now carries the full
product version, so a patch update probes again while an unchanged one still
skips.

Two smaller ones in the release walk:

- A pinned tag resolved twice under continue_after_fast_path. The download
  host had already yielded it, and the pinned block below resolved the same
  tag again through api.github.com. A pin names one release and has nothing
  to walk back to, so the fast path returns.
- LazyReleasePlans forgot why it stopped. A generator that raised is closed,
  so a second traversal reported a short, clean sequence and len() disagreed
  with the call that had raised. The failure is kept and re-raised.

Tests: an install whose probe never ran still probes; a timed out probe
reports no pass while still not rejecting the bundle; a patch update probes
again and an identical one does not; a pin resolves once with the walk-back
on and still reaches the API when the download host is unavailable; a failed
walk reports the same failure every time.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Persist a reuse-path load probe that passed

The probe skip was unreachable for anyone not born with the record. Only a fresh
install wrote macos_load_probe, and the three reuse paths discarded what their own
preflight had just learned, so a marker written before the record existed, an
install whose first probe timed out, and every install after a macOS point release
re-ran the expensive dyld probe on EVERY later update and never stopped.

Each reuse path now records a probe that actually ran and loaded every binary. A
legacy marker whose payload entries carry sizes but no digests is re-recorded at the
same moment, since that shape can never satisfy the skip either. Both are safe here
and nowhere else: the minos check, whatever digests the marker did carry, and dyld
itself all passed on these exact bytes moments earlier, which is the same evidence
the install path records on. A probe that could not run still records nothing, so a
fail-open timeout does not become a pass.

Measured on a marker written by the pre-change installer: update 1 probes once and
upgrades the record from 6 of 9 files hashed to 9 of 9, updates 2 and 3 probe zero
times. Before this, every update probed.

Tests: a passing reuse probe is remembered and the next update skips; a legacy
size-only marker is upgraded by it; a probe that could not run is not remembered.
The spawn-counting fixture now reports which binaries loaded, because a stub that
only returned no issues exercised the no-evidence path rather than the pass.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Catch a Rapid Security Response in the recorded macOS identity

platform.mac_ver() reads ProductVersion, and an RSR does not move it. macOS 13.3.1
(a) reports ProductVersion 13.3.1 with the "(a)" in ProductVersionExtra and the build
at 22E772610a instead of 22E261, so the probe skip went on accepting a pre-RSR result
across exactly the event the comment claimed it caught. Reading SystemVersion.plist
has the same blind spot and is additionally stale for an RSR (osquery/osquery#8008).

The recorded identity now comes from sw_vers, joining --productVersion,
--productVersionExtra and --buildVersion, so a point release, an RSR and a plain
build bump each invalidate it. --productVersionExtra exits non-zero when no RSR is
installed and did not exist before macOS 13, so absent is recorded as absent rather
than treated as a failure; if sw_vers cannot be run at all the product version alone
is kept, which still catches a point release.

Tests: an RSR probes again; the recorded string carries all three fields in order;
a host with no RSR still yields a version.

* Skip the macOS probe tests that start a binary on Windows

The fixture writes shell scripts as stand-in binaries, so on Windows
_binary_image_runs correctly reports a bad exe format and the install reads as
unusable: the six tests that let _existing_install_runs start them assert a True
they cannot get there. _pr10648_helpers.POSIX_ONLY already exists for this class.
The tests that skip the probe, or stub the spawn, keep running on Windows.

* Ask sw_vers with no arguments instead of guessing a flag spelling

sw_vers documents single-dash options (-productVersion), so the double-dash forms
this used are at best undocumented, and a flag that errors would have silently cost
the ProductVersionExtra and BuildVersion fields that were the entire point: the
function would have fallen back to platform.mac_ver() and gone on accepting a
pre-RSR probe.

Bare sw_vers prints every field as documented tab-aligned Key: Value lines,
ProductVersionExtra among them when a Rapid Security Response is installed. One
spawn instead of three, and nothing to spell wrong. An absent ProductVersionExtra
still reads as no RSR, and an unavailable sw_vers still falls back to the product
version, which catches a point release.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Record the load probe only once every image has started

_existing_install_runs recorded straight after the dyld probe, then went on to start
the root copies. The root entrypoint can be a separate wrapper rather than a symlink,
so a corrupt one was hashed into the digest record and given probe evidence before it
was ever started; the call still returned False, but the NEXT one read that record as
current, returned before the wrapper was reached, and accepted an unusable entrypoint.
For a pre-change marker the same write also upgraded its size-only payload entries on
the strength of a check that had not finished.

Recording now happens after every image has started, and in
existing_install_matches_choice after the fingerprint and field comparisons rather
than before them, so no tree that is about to be rejected gets its payload re-hashed.
existing_install_current_without_plan already recorded on its success path.

Test: a root wrapper that will not start leaves no probe evidence and no upgraded
record, and fails with the previous ordering.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Record the load probe only from the path that starts every image

The record covers the root copies as well as build/bin, and a later run skips
starting them on the strength of it. Only a caller that has started them all can
honestly write it, and the two reuse fast paths cannot: both probe build/bin alone
and neither reaches a root llama-server, which can be a separate wrapper rather than
a symlink. Persisting from there recorded and hashed a wrapper nothing had started,
and _existing_install_runs then read the record as current and returned before it
would have started the wrapper either.

Persistence now happens only in _existing_install_runs, after every image has run.
existing_install_matches_choice and existing_install_current_without_plan still probe
and still reuse; they just no longer write evidence they did not gather.

Test: neither fast path leaves probe evidence, even though both probed.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Trim three comments that had started repeating each other

The persist_macos_load_probe docstring and its one call site both spelled out the
root-wrapper ordering at length; the docstring now states the precondition and the
call site keeps the reason it comes last. macos_product_version keeps why sw_vers
is asked bare, in a clause rather than a paragraph.

---------

Co-authored-by: Lyxot <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…t model load (unslothai#10494)

* Repair a quarantined llama.cpp runtime at launch instead of failing at 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.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Close the gaps the simulations found, and prove the repair cannot loop

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.

* Format the new install-health files with the pinned ruff

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

* Fix the review round, and two defects the simulations found under it

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.

* Give a runtime tree with no build/bin its own fingerprint

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.

* Catch up the fingerprint tests with the bin and nobin prefixes

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.

* Tighten the comments on the runtime health preflight

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.

* Address review: per-library macOS payload groups, ~user paths, blank 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.

* Address review: macOS SONAME links, the execute bit, and which runtime 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.

* Ask for the execute bit by the tree's platform, not the interpreter's

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.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address review: the fingerprint's blind spots, and which tree it watches

- The runtime fingerprint counted regular files only, so deleting an install-name
  link (libggml.0.dylib, or the SONAME link on Linux) or taking the execute bit
  off llama-server left it identical. Both are states installed_runtime_health
  rejects, so a cached Ready went on matching a tree that could no longer launch.
  Links and executable files are counted now.
- An installer-managed venv under a custom root names its own runtime. The
  desktop strips UNSLOTH_STUDIO_HOME before spawning the CLI, but the CLI
  re-infers the root from sys.prefix and points UNSLOTH_LLAMA_CPP_PATH at its
  llama.cpp, so reading only the ambient environment fingerprinted the legacy
  tree and quarantine in the real one never invalidated anything.
- An override holding no server does not end the search, so it is no longer
  treated as final on either side. The CLI names the tree it grades rather than
  answering yes or no, so the two cannot pick different trees.
- ~name resolves through getpwnam_r. getpwnam hands back process-global storage
  and this runs on a Tauri worker thread, where a concurrent lookup could
  overwrite pw_dir mid-copy.

* Address review: entrypoints that are files, the mode bits, and one override spelling

installed_runtime_health asked os.access(X_OK), which a directory named llama-server
answers true for because directories are searchable, while the finder asks is_file()
and rejects the tree. Both now go through one helper that _existing_install_runs
shares, so the keep-or-reinstall decision and the launch verdict cannot disagree.

The runtime fingerprint counted files with any execute bit, but os.access(X_OK) asks
whether this user may run one: 0755 to 0655 leaves group and other executable and the
owner unable to run it, so the count never moved for a state health rejects. The
permission bits themselves are summed instead.

_find_llama_server_binary read UNSLOTH_LLAMA_CPP_PATH literally while
default_managed_llama_dir, get_stored_custom_llama_cpp_path and the desktop's pinning
all expand it, so a ~/llama.cpp written into a service unit or a .env sent discovery to
a folder named ~ beside the working directory and every other component reported on a
different tree. It expands now, and so does the orphan reaper's allowlist, which has to
name the tree discovery spawns from.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address review: the split entrypoint libraries, and reuse asking what the probe asks

Two of the three items from the last round, both measured against a b10360
managed install rather than a fixture.

1. The Linux impl split had no payload group.

ggml-org/llama.cpp#23462 moved each binary's entry code into a lib<binary>-impl
library. Windows already required llama-server-impl.dll, gated on the build the
split landed in. Linux got the same treatment upstream and none of it here: the
groups name the shared libraries only, so libllama-server-impl.so and
libllama-quantize-impl.so were required by nothing.

Measured on a copy of the managed install, removing either one:

  installed_runtime_health -> (True, "")
  _existing_install_runs   -> False

which is the disagreement the whole probe exists to remove, in the direction
that hurts: preflight says Ready and llama-server dies in the loader.

_linux_split_entrypoint_groups adds both, gated the same way the Windows side is
and on the same build number, since it is one upstream commit rather than one
platform's packaging. A source build ships neither whatever the tag says, and a
pre-split archive is healthy without them, so requiring one of those would
reinstall on every check forever.

2. The exact-release reuse decision asked exists() where the probe asks for the
execute bit.

installed_runtime_health asks _entrypoint_is_runnable, because that is what
_find_llama_server_binary asks. existing_install_matches_choice asked exists(),
and its Linux ldd gate reads a non-executable ELF quite happily. Clearing the
execute bit on llama-server, again on a real copy:

  installed_runtime_health -> (False, "llama_runtime_binaries_missing")
  _existing_install_runs   -> False
  exists()                 -> True
  preflight_linux_installed_binaries -> passes

so preflight says broken, repair says the exact release is already installed,
nothing is downloaded, and the next launch says broken again. Both attempts land
in the same place. It now calls _entrypoint_is_runnable, which is the same test
both other answers use.

Tests:

- test_quarantining_a_split_entrypoint_library_is_reported_broken, per library,
  against a managed copy, asserting the two answers agree afterwards.
- test_an_older_monolithic_linux_release_is_not_asked_for_the_impl_libraries,
  which pins the gate rather than the requirement: b9279 owes neither, b9283
  owes both, a source build owes neither.
- test_a_stripped_execute_bit_is_not_reused_as_an_exact_release_match, checking
  the two gates directly.
- The fixture tables gain both libraries, and the shape writers now chmod the
  entrypoints, which a real extraction does and the reuse decision now reads.

tests/studio/install: 5991 passed, 6 skipped. cargo test --bin unsloth-studio:
571 passed.

The third item, a versionless libllama.so surviving its SONAME's removal, does
not apply: the release ships exactly two names per library, libllama.so.0 beside
libllama.so.0.0.10360, with no versionless file and no symlinks. Replied on the
thread.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address review: resolve a named-user override the same way on both sides of a spawn

preflight::managed resolves UNSLOTH_LLAMA_CPP_PATH=~alice/llama.cpp through
getpwnam_r, the way posixpath.expanduser does. process.rs, pinning the same
variable for the child it is about to move, read it with the Windows rule, which
leaves ~alice alone off Windows, so it fell through to being anchored under the
directory being left.

Measured, with the two halves side by side on this host:

  preflight::managed  ~root/llama.cpp -> /root/llama.cpp
  process.rs pin      ~root/llama.cpp -> /mnt/work/session/~root/llama.cpp

The child is handed the pinned value, so it grades and runs one tree while the
cache fingerprints another. Quarantining a file from the tree actually in use
then never invalidates a Ready verdict, which is the whole failure this
fingerprint exists to catch.

expand_user now makes the split every other reader in that function already
makes, Windows rules on Windows and the native ones off it, and expand_posix_user
resolves the named form through the same lookup preflight::managed uses, which is
now pub(crate) rather than duplicated. An unknown name is left exactly as it
arrived, which is what expanduser does, so both halves fall through to anchoring
it and still agree. Bare ~ and ~/rest are unchanged: they went through
expand_windows_user's empty-name arm, which answers home on any platform, and
they go through the posix one now.

Windows was already aligned. named_user_home's Windows arm delegates to
named_windows_user_home, which is the same rule expand_windows_user applies.

Tests, all three unix-only since they turn on the password database:

- a_named_user_override_is_pinned_where_the_fingerprint_watches, asserting the
  pin is not under the directory being left and equals what the fingerprint side
  reaches through the same lookup.
- an_unknown_named_user_is_left_alone_and_anchored_by_both_halves.
- a_bare_tilde_override_still_reaches_home_off_windows, for the form that already
  worked.

cargo test --bin unsloth-studio: 574 passed. tests/studio/install: 5991 passed,
6 skipped.

* Address review: the SONAME beside a flattened versionless copy, and an override that cannot expand

Two items, and the first one corrects a rebuttal of mine that was wrong.

1. A versionless copy kept the group satisfied after the SONAME was quarantined.

I argued against this last round on the grounds that the bundle ships exactly two
names per library. That was true of the tree I measured, the b10360 install on
this machine, and it is not true of what the installer produces today. Two things
moved underneath it:

  - b10840 ships the trio. libllama.so -> libllama.so.0 -> libllama.so.0.4.0, as
    symlinks in the tarball.
  - copy_globs flattens them. It selects with is_file() and copies with
    shutil.copy2, which follows symlinks, so all three arrive in build/bin as
    independent regular files. My reproduction moved the extracted tree instead,
    which kept the links, and a dangling link is dropped by is_file() on its own.
    That made the argument look decisive about a shape no install has.

Extracting b10840 with prebuilt_core.extract_archive and installing it through
copy_globs, which is the path install_prebuilt takes:

  baseline                          health=(True, "")
  quarantine libllama.so.0          health=(True, "")   runs=False
  quarantine libggml.so.0           health=(True, "")   runs=False
  quarantine libllama-common.so.0   health=(True, "")   runs=False
  quarantine libggml-base.so.0      health=(True, "")   runs=False
  quarantine libmtmd.so.0           health=(True, "")   runs=False

_payload_match_is_loadable can no longer answer from the name alone, because
libllama.so means one thing in a family that has a SONAME and another in a family
that never had one. It now reads the family: a versionless name counts only when
nothing versioned sits beside it. Any versioned sibling disqualifies it, not only
a SONAME-shaped one, since asking for a SONAME specifically would read the family
as versionless again exactly when the SONAME is the file that went missing.

Same rule on macOS, where dyld asks for the install name in LC_ID_DYLIB:
libggml.dylib does not stand in for libggml.0.dylib.

2. An unresolvable named user made runtime discovery throw.

Path.expanduser() raises RuntimeError when it cannot determine the home, which
includes every unknown named user, unlike os.path.expanduser, which hands the
value back:

  Path("~no-such-account-anywhere/llama.cpp").expanduser()
  RuntimeError: Could not determine home directory.

Every reader of UNSLOTH_LLAMA_CPP_PATH used the raising form, so a pin left in a
service unit or a .env after an account rename took discovery down with it rather
than being treated as unusable, and several callers have no exception boundary.
Four sites, not the one reported: the search, the process allowlist that has to
name the same tree, the settings reader and the status payload the UI renders.

expanded_user_path is the non-raising expansion, shared by all four so they cannot
diverge, and it leaves an unresolvable name exactly as it arrived, which is what
the desktop's pinning does with one too.

Tests:

- test_the_flattened_trio_installs_healthy and
  test_quarantining_a_soname_beside_a_versionless_copy_is_reported_broken, per
  library, built from the b10840 asset through copy_globs, asserting the three
  names really are flattened regular files first, so the test cannot pass for the
  dangling-link reason instead. Skipped where the asset is absent, as the rest of
  that file is.
- test_a_family_that_only_ever_ships_one_name_is_still_loadable and the macOS
  counterpart, both artifact-free, for the half a blunter rule would break:
  libggml-cpu-x64.so has no versioned copy anywhere and is the name the loader
  asks for.
- The expanduser guard, including the status payload and discovery reaching its
  own answer rather than raising.
- test_a_dangling_library_symlink_does_not_count_as_present now builds all three
  rungs, which is what its own docstring already described; it had been building
  the outer two, and the SONAME rung is what the new rule needs to see.

tests/studio/install: 5999 passed, 6 skipped. studio/backend/tests -k "llama_cpp
or path_settings": 1928 passed, 4 skipped. cargo test --bin unsloth-studio: 574
passed.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address review: the HIP module by name, both impl halves, and a marker that will not parse

Six items, each measured against a real bundle built through copy_globs rather
than reasoned about.

ggml-hip.dll by name, not "*hip*.dll". app-b10798-mix-659e406-windows-x64-rocm-gfx1150
ships amdhip64_7.dll, hipblas.dll and libhipblaslt.dll beside it, and all four
match that pattern, so quarantining the one module ggml actually loads left the
group satisfied by three libraries that cannot stand in for it. Measured:
installed_runtime_health answered (True, "") with the backend gone.

llama-quantize-impl.dll under the same split-build gate as the server's.
llama-quantize.exe links against its own impl library exactly as llama-server.exe
does, and every post-b9283 bundle ships both, so requiring one let a quarantined
quantize implementation read as healthy while quantization could not start.

A marker that exists but will not parse names no source, and the source-gated
groups were dropped with it: on Windows llama.dll stood in for the whole payload,
so an interrupted marker plus a quarantined ggml-base.dll answered healthy.
Assuming "published" instead would be worse, because a statically linked source
build ships none of those names and would fail health on a tree the setup scripts
keep, repairing on every launch with nothing to change. _tree_looks_prebuilt reads
the source off the tree from a name only a release ships, and stays lenient when
quarantine has taken the evidence too.

The runtime fingerprint now includes entry names. Its four counters are all
aggregates, and a rename in place moves none of them, so security software that
renames ggml-base.dll beside itself left the cached Ready matching a tree
installed_runtime_health rejects, and preflight answered Ready without running the
capability probe. FNV-1a rather than DefaultHasher, so a toolchain bump does not
invalidate every cached verdict; summed rather than folded, because read_dir order
is unspecified and the counters beside it are order-independent for that reason.

The CLI classifies UNSLOTH_LLAMA_CPP_PATH instead of trusting the marker.
studio/backend/main.py calls mark_managed_llama_cpp_path before discovery, which
marks any override equal to the managed tree however it got there, and the finder
then skips it; _ensure_studio_env_exported writes exactly that value under a
custom STUDIO_HOME and sets no marker. So preflight graded the managed tree as a
user pin while the backend walked past it to the stored selection, blocking launch
over a tree nothing would open. Compared against the studio home's own path with
the override out of the way, never default_managed_llama_dir(), which reads the
override first and would call every user pin managed.

expanded_user_path at the last Path.expanduser left in the doctor, a gap in the
earlier pass: a "~name" naming no account raises RuntimeError out of a command
whose whole job is to answer.

Also: the stored-selection stub in test_desktop_capability_llama_runtime was
missing expanded_user_path, so the helper's import raised and every test in that
file was silently grading the except fallback rather than the code it names.

tests/studio: 10171 passed, 198 skipped. cargo test --bin unsloth-studio: 575
passed. The four new payload tests and the CLI one all fail on the previous head.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Gate the PowerShell reuse shortcut on runtime health, as the shell already is

The POSIX half of this loop was closed and the Windows half was not. setup.ps1
reaches "already built" through an elseif on Test-PathQuiet $LlamaServerBin, so a
Windows repair that fell through to the source stage kept a tree whose
ggml-base.dll had been quarantined, returned it byte for byte identical, and
reported success. Desktop preflight grades that same tree on every launch, so it
offered the same repair forever.

Test-LlamaTreeStillHealthy makes the same --check-existing-install call setup.sh
makes, through Invoke-LlamaHelper, so there is one definition of healthy rather
than two that can disagree. It answers healthy on any failure to ask: a helper
that cannot run must not turn into a multi-gigabyte source build on a machine
whose only fault was an unreadable tree.

The reason this survived is in the convergence model's own comment, which said
setup.ps1 had no reuse step and that a Windows update reaching the source stage
always builds. That was wrong, and the model therefore never exercised the
Windows branch. It now models both shells, and reverting the gate in the model
fails every Windows cell of
test_no_damaged_tree_survives_the_shell_rebuild_skip, which is what it should
have done all along.

A model cannot catch a shell losing its gate, so
test_both_shells_gate_their_reuse_shortcut_on_the_same_check reads both scripts
and asserts the check sits on the shortcut itself rather than somewhere else in
the file.

tests/studio/install: 6007 passed, 6 skipped.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Reject a library renamed in place instead of letting it satisfy its own group

* Grade the root entrypoint, and plan the Windows rebuild the health gate forces

* Grade the studio root the desktop scrubbed, and fix the Windows fixture

* Reject empty payload files, and stop grading a runtime no repair can reach

* Give the entrypoint check one owner, and cache only what the probe read

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Close the repair loop between the launch check and the update

Found by simulating the cycle a user walks rather than by testing the new
check on its own, and reproduced before being fixed.

installed_runtime_health rejects a root llama-server or llama-quantize that
lost its execute bit, so the desktop marks the install stale and offers a
repair. existing_install_current_without_plan is the shortcut
install_prebuilt returns on before reinstalling anything, and it checked
os.access(X_OK) under build/bin ONLY, while _find_llama_server_binary
reaches the install root's copy FIRST. So the repair ran, changed nothing,
and the next launch was stale again.

Measured, with an undamaged install accepted as the control:

  root llama-server -x    launch health broken, shortcut True,  full False
  root llama-quantize -x  launch health broken, shortcut True,  full False
  build/bin copy -x       launch health broken, shortcut False, full False

_damaged_entrypoint now answers for the shortcut too, which is what its own
docstring already asks for: one owner, so a tree one check rejects and
another keeps cannot be repaired by changing nothing. It is four stat plus
os.access calls and spawns nothing, so the shortcut stays a shortcut.

test_the_execute_bit_is_checked_on_the_runtime_copies_only pinned the old
boundary, so it is rewritten as
test_the_execute_bit_is_checked_on_every_entrypoint, keeping the visual
server as the control that stops the fix becoming "reject everything".

tests/studio/install plus test_llama_cpp_path_settings.py: 8787 passed,
65 skipped.

* Require the split entrypoint dylibs on macOS

The impl split that gave Windows llama-server-impl.dll and Linux
libllama-server-impl.so gives macOS libllama-server-impl.dylib and
libllama-quantize-impl.dylib, and the macOS branch of
runtime_payload_health_groups was the one that did not ask for them. Quarantining
either left every library group satisfied and both execute-bit checks passing while
dyld could not start the entrypoint, so installed_runtime_health answered Ready on
the platform this probe exists for.

Verified against the real bundles rather than assumed: both
llama-b10840-mix-d5c17a0 and llama-b11007-mix-3e83366 macos-arm64 ship the two,
unversioned, beside the entrypoints. _PREBUILT_TREE_EVIDENCE already reads
libllama-server-impl*.dylib as proof of a prebuilt macOS tree.

_macos_split_entrypoint_groups delegates the gate to its Linux counterpart rather
than repeating it, so the source labels and the b9283 floor cannot drift.

The three fixtures that claimed to list a real macOS bundle were short of these two
files and now carry them, and the matrix states the requirement independently with
the matching pre-split pruning. New test with the loop-direction control: a pre-split
upstream b6099 bundle never shipped them and stays healthy.

* Shorten the macOS split docstring

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

* Grade the macOS fixture against a real bundle, and stop a test carrying one machine's path

Merging main up brought in test_macos_loader_probe_record.py from unslothai#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.

* Name the folder the antivirus advice is asking the user to allow

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.

* Grade a root entrypoint only when discovery would start it

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.

* Scope the root-entrypoint relaxation to the launch verdict

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.

* Grade the runtime a master root install actually uses

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.

* Fingerprint the runtime a master root install actually loads

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.

* [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>
Co-authored-by: danielhanchen <[email protected]>
Co-authored-by: oobabooga <[email protected]>
Co-authored-by: danielhanchen <[email protected]>
Co-authored-by: danielhanchen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants