Skip to content

Reject a macOS llama.cpp prebuilt that dyld will not load - #9843

Merged
danielhanchen merged 8 commits into
mainfrom
fix-macos-dylib-preflight
Aug 27, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
fix-macos-dylib-preflight

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

The failure

Every macOS lane on every open PR:

dyld[41694]: Library not loaded: /usr/lib/librdma.dylib
  Referenced from: .../llama.cpp/build/bin/libggml-rpc.0.dylib
  Reason: tried: '/usr/lib/librdma.dylib' (no such file) ...
llama-server failed to launch on macOS 15.7.7 (dyld load / symbol error)

Upstream llama.cpp b114b4739 (2026-08-25, "rpc: support apple RDMA as an RPC transport") added RDMA with auto-detection:

if (APPLE)
    set(RDMA_LIB_NAME rdma)
find_library(RDMA_LIB ${RDMA_LIB_NAME})
if (RDMA_LIB)
    option(GGML_RPC_RDMA "..." ON)

The build host resolved librdma, so /usr/lib/librdma.dylib was baked into libggml-rpc.0.dylib. macOS 15 has no such library. Release b10639-mix-f6f92fe (2026-08-27) is the first to contain that commit; b10472-mix-4b653db predates it and is fine.

This PR does not fix the artifact - that needs a rebuild with -DGGML_RPC_RDMA=OFF in unslothai/llama.cpp and a republish. It fixes the reason a bundle like that reached users at all.

The gap

preflight_linux_installed_binaries runs an ldd sweep and refuses a bundle with an unresolved library. The macOS side only compared minimum-OS versions. So the bundle passed preflight, was logged prebuilt installed and validated, and then died on first launch.

The one check that would have caught it, validate_server, is skipped for checksummed bundles since #5854 because it loads a model and costs minutes.

The fix

llama-server --version costs a process spawn and still makes dyld resolve the whole link graph, so it catches a missing dylib, a missing symbol and a too-new slice. Failing here raises PrebuiltFallback, which spends a source build instead of installing something that cannot start.

Two deliberate choices:

  • Report dyld's own output rather than scanning install names with otool -L. An absolute install name absent from disk is the normal case for /usr/lib, whose members live in the dyld shared cache, so "missing from disk" cannot separate the culprit from its healthy peers. I wrote the otool version first; a test caught it flagging libSystem.B.dylib. dyld names both the library and the dylib that asked for it, which is strictly better evidence.
  • A binary that cannot be spawned is not treated as a link failure. That would reject healthy bundles on a loaded or locked-down host.

.github/scripts/assert-llama-loads.sh needs no change - it did its job and caught this.

Verification

python -m pytest -q tests/studio/install/ -> 2719 passed, 3 failed. The 3 are pre-existing on main in test_managed_node_runtime.py and unrelated (confirmed by stashing this change).

New tests in test_macos_version_compat.py: rejects a binary dyld refuses, keeps the referencing dylib in the message, accepts one that loads, and does not treat an unspawnable binary as a link failure.

I cannot run dyld on this host, so the probe's behaviour against a real broken bundle is argued from the CI log above rather than reproduced locally.

shimmyshimmer and others added 2 commits August 27, 2026 08:52
preflight_linux_installed_binaries runs an ldd sweep and refuses a bundle with
an unresolved library. The macOS side only compared minimum-OS versions, so a
bundle whose libggml-rpc.0.dylib links /usr/lib/librdma.dylib -- present on the
builder, absent on macOS 15 -- passed preflight, was logged 'prebuilt installed
and validated', and then failed on first launch.

The one check that would have caught it, validate_server, is skipped for
checksummed bundles since #5854 because it loads a model and costs minutes.
llama-server --version costs a process spawn and still makes dyld resolve the
whole link graph, so it catches a missing dylib, a missing symbol and a too-new
slice. Failing here spends a source build instead of installing something that
cannot start.

Reporting dyld's own tail rather than scanning install names with otool -L: an
absolute install name absent from disk is the normal case for /usr/lib, whose
members live in the shared cache, so absence cannot separate the culprit from
its healthy peers. dyld names both the library and the dylib that asked for it.

A binary that cannot be spawned is not treated as a link failure -- that would
reject healthy bundles on a loaded or locked-down host.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…oadable

CI caught this on the first run: the probe rejected every published macOS
prebuilt, walked the release history to its end and fell back to a source build
on every macOS runner.

    published release b10290-mix-b1e9972 failed; trying the next older published
    prebuilt (macos prebuilt does not load on this host: llama-quantize: 7 or
    Q8_0 : 7.96G, +0.0026 ppl @ Llama-3-8B | ...)

llama-quantize answers --version by printing its quantization table and exiting
non-zero. That is a binary that loaded perfectly. assert_macho_minos.sh in the
llama.cpp fork already makes this distinction, for this reason, and I did not.

An exit code cannot separate 'never reached main' from 'ran and disagreed', so
require dyld's own diagnostic instead. looks_like_macos_loader_failure is
deliberately narrow: a false positive rejects a working prebuilt and spends a
source build, so anything unrecognised is treated as healthy and left to the
runtime validation that follows.

The regression test uses the exact llama-quantize output from the CI log.
@danielhanchen

Copy link
Copy Markdown
Member Author

CI caught a real bug in the first version of this, on the first run. Pushed a fix.

The probe treated a non-zero exit as a link failure. llama-quantize answers --version by printing its quantization table and exiting non-zero - a binary that loaded perfectly - so the probe rejected every published prebuilt, walked the release history to its end, and fell back to a source build on every macOS runner:

published release b10290-mix-b1e9972 failed; trying the next older published prebuilt
(macos prebuilt does not load on this host: llama-quantize: 7 or Q8_0 : 7.96G,
 +0.0026 ppl @ Llama-3-8B | 1 or F16 : 14.00G, ...)
...
[llama-prebuilt] prebuilt install path failed; falling back to source build

That would have been worse than the bug this PR is fixing.

assert_macho_minos.sh in the llama.cpp fork already makes exactly this distinction, and says why:

llama-quantize's usage() ends in exit(1), so --help is non-zero by design. A dyld/symbol failure dies before main and prints nothing, so verify the binary actually reached main rather than trusting the code.

An exit code cannot separate "never reached main" from "ran and disagreed", so the probe now requires dyld's own diagnostic. looks_like_macos_loader_failure is deliberately narrow - a false positive rejects a working prebuilt and spends a source build, so anything unrecognised is treated as healthy and left to the runtime validation that follows.

The regression test uses the verbatim llama-quantize output from the failing run above.

Also opened unslothai/llama.cpp#131, which fixes the root cause: the macOS build auto-detects RDMA and links the runner's librdma, so -DGGML_RPC_RDMA=OFF is now pinned rather than detected.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Only the static minimum-version comparison needs platform.mac_ver(); dyld does
not. The early return skipped both, so a host with an unreadable or unparseable
version got no check at all -- and the runtime validation it deferred to is
disabled by default for checksummed bundles (#5854), which is the common path.

Skip only the comparison now, and still ask dyld.
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 3e0bc93264

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ilure

Two gaps in the previous round.

The reuse path never reached the probe. existing_install_matches_choice ran the
Linux preflight only, so a bundle that cannot load but whose fingerprint matches
was accepted and reused. That is the path that reaches the users who matter: a
broken bundle is usually ALREADY installed by the time the installer learns to
reject it, so re-running the installer kept the broken tree and failed at first
launch again. Rejecting it there reinstalls instead.

The loader-failure matcher treated any dyld-prefixed line as a refusal.
DYLD_PRINT_LIBRARIES makes dyld narrate every image it loads under that same
prefix on a perfectly healthy run, which paired with llama-quantize's nonzero
--version would reject a good bundle for anyone who has the diagnostic set --
the same false-positive class as the exit-code bug. The prefix says who is
speaking, not that anything went wrong, so the failure markers now decide alone,
and the probe drops DYLD_PRINT_* and DYLD_INSERT_LIBRARIES from its environment
so its output is the binary's own.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: ac181ecad0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 27, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d04dc6fdbb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +5219 to +5220
if any(marker in lowered for marker in _MACOS_LOADER_FAILURE_MARKERS):
return True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require dyld framing before rejecting probe output

When llama-quantize --version exits nonzero, this accepts generic application phrases such as symbol not found, image not found, or code signature as proof that dyld rejected the executable, even when no dyld[...] diagnostic is present. A wrapper or plugin loader emitting one of those phrases therefore causes a healthy prebuilt to be discarded for an expensive source build. The existing runtime classifier in studio/backend/core/inference/llama_cpp.py explicitly requires line-start dyld framing because bare occurrences previously produced these false diagnoses; apply the same framing requirement here.

Useful? React with 👍 / 👎.

raise PrebuiltFallback(
"macos prebuilt requires a newer macOS than this host:\n" + "\n".join(issues)
)
load_issues = macos_dyld_load_issues(binaries, install_dir, host)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the executable iterable for the dyld pass

When binaries is a one-shot iterable such as Path.glob(...) or a generator and the host version is known, macos_binary_minos_issues first exhausts it via list(binaries), so this second pass receives no executables. The new dyld check is then silently skipped and can install exactly the unloadable bundle this preflight is meant to reject. Materialize binaries once before either check and pass the resulting collection to both.

Useful? React with 👍 / 👎.

Comment on lines +5297 to +5298
if not looks_like_macos_loader_failure(output):
continue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Detect silent macOS code-signature kills

When macOS rejects the executable's own code signature, it can terminate the process with signal 9 before emitting any diagnostic text. In that case looks_like_macos_loader_failure("") returns false and this branch accepts the bundle, so both the fresh-install preflight and cached-install reuse path retain a binary that cannot launch. The repository's runtime classifier already documents and handles this silent macOS -9 case in studio/backend/core/inference/llama_cpp.py; the preflight needs an equivalent signature check rather than relying exclusively on output markers.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit 6386137 into main Aug 27, 2026
51 of 56 checks passed
@danielhanchen
danielhanchen deleted the fix-macos-dylib-preflight branch August 27, 2026 10:34
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.
danielhanchen added a commit that referenced this pull request Sep 18, 2026
…leases (#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 #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
…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>
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.

2 participants