Skip to content

Studio: set DYLD_LIBRARY_PATH for llama-server on macOS, and classify macOS startup failures - #8574

Merged
danielhanchen merged 40 commits into
mainfrom
fix-macos-llama-server-loader-diagnostics
Aug 13, 2026
Merged

danielhanchen merged 40 commits into
mainfrom
fix-macos-llama-server-loader-diagnostics

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #8566, where Unsloth Desktop on an Apple Silicon Mac could not load any GGUF and the error blamed the GGUF and free memory:

llama-server failed to start. Check that the GGUF file is valid and you have enough memory.

That message is the classifier's last-resort fallback, and it discards the two things that would identify the real cause. This PR fixes the loader-path bug it exposed and makes that fallback carry its own evidence, so the next report of this arrives with the diagnosis attached.

Scope note: the reporter has not attached a llama-server log yet, so this does not claim to be the root cause of #8566. What it does fix is real and independently verifiable.

1. macOS never got a dyld search path

_llama_server_env_for_binary branched win32 vs everything else, and the else branch is Linux: WSL/ROCm probing, pip nvidia/cu*/lib globs, /usr/local/cuda*, and LD_LIBRARY_PATH. dyld ignores LD_LIBRARY_PATH, so on macOS llama-server was spawned with no library search path at all.

The inconsistency is what makes this hard to catch: install_llama_prebuilt.py does set DYLD_LIBRARY_PATH when it validates a staged binary, so install-time validation exercises a path the real launch never takes. The sibling engines already get it right (sd_cpp_engine._lib_path_var, stt_ggml_sidecar); llama_cpp.py was the only outlier.

Added a darwin branch plus a shared _loader_path_var(), and used it at the two other sites that equated "not Windows" with LD_LIBRARY_PATH: the Vulkan probe and the CPU-fallback replay. Linux and Windows branch bodies are untouched.

A healthy prebuilt resolves its dylibs through @loader_path and does not need this, which is why macOS has worked for most people. A bundle whose install names or runpaths are off dies in dyld before main() without it.

2. macOS startup failures were misclassified

The classifier matched glibc's error while loading shared libraries: only. dyld says none of that, so all of these fell through to the generic GGUF/memory message:

dyld output now reported as
Library not loaded: ... Reason: tried: ... (no such file) the named dylib is missing from the runtime
Reason: image not found (older macOS) same
(code signature ... not valid for use in process) macOS rejected the signature
(mach-o file, but is an incompatible architecture ...) built for the wrong CPU
built for macOS 26.0 which is newer than running OS runtime needs a newer macOS
Symbol not found with no missing file llama-server and its dylibs are from different builds

These reuse the existing _missing_library_message / _unloadable_library_message, so the managed-runtime vs custom-LLAMA_SERVER_PATH split in the advice is preserved. They sit ahead of the returncode heuristics on purpose: a dyld diagnostic is a fact, signal 9 is a guess.

Related: macOS SIGKILLs a Mach-O with an invalid code signature before it can print anything, which is indistinguishable from the OOM killer by returncode. returncode == -9 on darwin now offers both readings instead of sending the user to free memory they already have. Other platforms keep the existing OOM wording verbatim.

3. The unknown-failure fallback now carries its evidence

Studio already writes every byte of llama-server's stdout and stderr to a per-attempt log under ${UNSLOTH_STUDIO_HOME:-~/.unsloth/studio}/logs/llama-server/, and already holds the last 50 lines in memory. The 400 response dropped both, exactly when nothing had recognised the output.

The fallback now appends a bounded (2000 char), control-character-stripped output tail and the log path. Only the fallback: every classified message keeps its exact existing text. With no output and no log, the old string is returned byte for byte.

Tests

  • studio/backend/tests/test_llama_cpp_darwin_loader_env.py (new): darwin prepends the resolved bin dir to DYLD_LIBRARY_PATH, dedupes, keeps inherited entries after ours, leaves an inherited LD_LIBRARY_PATH alone, resolves a shell-wrapper entrypoint to the real bin dir, and never enters the Linux discovery helpers (they are monkeypatched to raise). Linux and Windows are regression-pinned in the same file.
  • test_llama_cpp_start_failure_classification.py: real dyld fixtures for each row of the table above, dyld output outranking signal 9, provenance for a pinned custom binary, the glibc wording still winning, and the fallback cases (tail present, tail bounded, control characters stripped, log path present, old message byte-identical when there is nothing to add, classified messages unchanged).

87 tests pass across the two modules. The 41 collection errors in the wider studio/backend/tests run on this machine are missing local deps (structlog, fastmcp, pymupdf) and reproduce identically on main.

Validated on macOS Actions runners; the details are in the thread below.

…g macOS startup diagnostics

_llama_server_env_for_binary branched win32 vs "everything else", and that
else branch is Linux: WSL/ROCm probing, pip nvidia wheel globs, CUDA toolkit
paths, and LD_LIBRARY_PATH. dyld ignores LD_LIBRARY_PATH, so llama-server was
launched on macOS with no library search path at all, while the installer's own
staged-binary validation does set DYLD_LIBRARY_PATH and therefore passed on a
path the real launch never took. sd_cpp_engine and stt_ggml_sidecar already map
the variable per platform; llama_cpp.py was the outlier. Add the darwin branch
plus a shared _loader_path_var(), and use it at the two other sites that
equated "not Windows" with LD_LIBRARY_PATH (the Vulkan probe and the CPU
fallback replay).

Classification was Linux-only too. dyld shares no wording with glibc, so
"Library not loaded", "Reason: tried: ... (no such file)", an invalid code
signature, an incompatible architecture and "built for macOS X which is newer
than running OS" all fell through to "check that the GGUF file is valid and you
have enough memory" - advice about a file and a resource that were never the
problem. Classify them, reusing the existing provenance-aware missing/unloadable
library messages, and keep them ahead of the returncode heuristics: a dyld
diagnostic is a fact, signal 9 is a guess. macOS also SIGKILLs a binary whose
code signature is invalid before it can print anything, so signal 9 there now
offers both readings instead of memory alone.

Finally, make the unknown-failure fallback self-diagnosing. Studio already
writes every byte of llama-server's stdout and stderr to a per-attempt log, and
already keeps the last 50 lines in memory, but the 400 response threw both away
precisely when nothing recognised the output. It now carries a bounded,
control-character-stripped output tail and the log path. With neither, the old
message is returned byte for byte.

Reported in #8566, where a Mac could load no GGUF at all and the error named the
two things that were fine.
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 12, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

macOS SIGKILLs a binary with an invalid code signature the same way the OOM
killer does, so the -9 message names both readings there. The existing test
asserted the .wslconfig wording against whatever host it ran on, which made it
fail on the macOS runners. Pin it to the non-Darwin platform and assert the
two messages stay distinct.
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 12, 2026
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 12, 2026
danielhanchen and others added 3 commits August 12, 2026 14:46
The test simulated darwin and asserted the binary's dir landed on
LD_LIBRARY_PATH, which is the bug: probe_server_capabilities goes through
_llama_server_env_for_binary, so on macOS it ran llama-server --help with a
variable dyld ignores. Assert DYLD_LIBRARY_PATH instead, and that an inherited
LD_LIBRARY_PATH is left as the user set it.
… candidate

Six fixes from the review of the first two commits.

A stray "Reason:" anywhere in the output used to be read as dyld's, because
the capture was DOTALL and matched the first occurrence anywhere, running to
the end of the output. llama.cpp prints its own "Reason:" lines, and Studio
appends its own health-timeout marker, so the classifier could quote either
back as dyld's diagnosis, or pick a verdict from a line belonging to a
different failure. The reason is now bounded to its own line plus the indented
continuations and read only after the "Library not loaded:" it explains.

dyld4 lists every path it searched with a per-path verdict, so a mixed list is
normal: our own dylib missing, and a leftover Intel Homebrew copy under
/usr/local reporting an incompatible architecture or a policy-blocked
signature. Scanning the flattened list let the scariest entry decide, which
told users their install had been tampered with when a file was merely absent.
Parse the "tried:" list and judge the candidate in the runtime's own lib dir.

A stray "Reason:" also disabled the symbol-mismatch branch entirely, since the
lib/reason block returned instead of falling through.

"@rpath/libfoo.dylib" was passed to the shared message helpers as if it were a
path, producing "missing from that exact location" for a search directive that
is not a location. Strip the directive down to the soname.

The macOS SIGKILL message hardcoded `unsloth studio update`, which cannot touch
a pinned LLAMA_SERVER_PATH, and promised the log would say which cause it was
when a signature kill leaves the log empty. Route it through _runtime_remedy
and let it carry whatever diagnostics exist.

The output tail is llama-server's own stdout, and llama-server inherits nearly
all of Studio's environment, so a wrapper or diagnostic build echoing its env
would have put an API key in the load error. Redact credential-shaped env
values, plus bare hf_ and Bearer tokens, and slice the tail before filtering it
character by character so a runaway unterminated line is not walked in full.

Also fixes the same missing dyld search path in the RAG embedding server, which
Apple Silicon reaches through its use_gpu branch. It is the same bug as the
chat server's, in a second launcher.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

macOS validation

Run on Apple Silicon runners through a staging fork rather than the org queue. The decisive job installs a real llama.cpp runtime, then inspects the environment llama-server is actually launched with, at this branch and at the merge base. The pre-fix run must fail: an @loader_path-healthy bundle would otherwise make both revisions look green and prove nothing.

With the fix:

binary            : /Users/runner/.unsloth/llama.cpp/llama-server
resolved lib dir  : /Users/runner/.unsloth/llama.cpp/build/bin
DYLD_LIBRARY_PATH : /Users/runner/.unsloth/llama.cpp/build/bin
LD_LIBRARY_PATH   : <unset>
PASS  the child env sets DYLD_LIBRARY_PATH at all
PASS  the runtime's own lib dir comes first on DYLD_LIBRARY_PATH
PASS  that dir really holds the llama.cpp dylibs
PASS  a spawned child inherits it
PASS  llama-server still starts with this environment

Same runner, same install, merge base:

DYLD_LIBRARY_PATH : <unset>
LD_LIBRARY_PATH   : /Users/runner/.unsloth/llama.cpp/build/bin
3 check(s) failed

Also green on that branch: the two test modules on macos-14, macos-15 and ubuntu-latest, plus the repo's own Mac Studio GGUF CI, Windows GGUF CI and Startup profile.

Two limits worth stating rather than glossing over. The runners are M1 with 7GB, not an M4 with 16GB. And every macOS job here boots through install.sh and the API; none exercises the packaged Tauri app, which is the path the reporter is on, so the hardened-runtime process chain is still uncovered.

Review fixes

The first pass over this diff found six real bugs, all fixed in the last commit with tests:

  • A stray Reason: anywhere in the output was read as dyld's, because the capture was DOTALL and matched the first occurrence to the end of the output. llama.cpp prints its own Reason: lines, and Studio appends its health-timeout marker, so either could be quoted back as dyld's diagnosis. The same bug disabled the symbol-mismatch branch entirely.
  • dyld4 lists every searched path with a per-path verdict, so a mixed list is the normal shape on a Mac with a leftover Intel Homebrew tree. Scanning the flattened list let an unrelated candidate decide, telling users their install had been tampered with when a file was merely absent. It now judges the candidate in the runtime's own lib dir.
  • @rpath/libfoo.dylib was passed to the shared message helpers as a path, producing "missing from that exact location" for a search directive that is not a location.
  • The macOS SIGKILL message hardcoded unsloth studio update, which cannot touch a pinned LLAMA_SERVER_PATH; it now goes through the same provenance check as every other new message.
  • The output tail could carry a credential. llama-server inherits nearly all of Studio's environment, and a wrapper or diagnostic build echoing its env would have put an API key in the load error. Credential-shaped env values plus bare hf_ and Bearer tokens are redacted, and the tail is sliced before the character filter so a runaway unterminated line is not walked in full.
  • The RAG embedding server has the same missing dyld search path, and Apple Silicon reaches it on every startup warm. Fixed here rather than deferred, since it is the same bug in a second launcher.

Not in this PR

Found while reading, unproven against this report, and each large enough to want its own change:

  • --flash-attn on, --fit on, --no-context-shift and --jinja are emitted with no capability gate, while --fit-ctx / --fit-target / --kv-unified are gated. Fine for the pinned prebuilt, fatal for a stale or user-supplied LLAMA_SERVER_PATH.
  • The Apple fit-exception path can restore ctx to 0 and emit -c 0, which means full native context and defeats --fit shrinking.
  • The Apple memory budget falls back to 85% of total RAM rather than available, which is optimistic on a 16GB Mac already holding a GB of Studio.
  • A #!/bin/sh install entrypoint defeats this fix on macOS, since SIP purges DYLD_* when exec'ing a protected interpreter. The installer only writes a wrapper when it cannot make the symlink, so this is the tail, but it is silent when it hits.

The Mac job already installs a real llama.cpp and launches llama-server to
prove it loads on that host, but it launches it from the shell's own
environment, which says nothing about the one Studio builds for its child. That
environment was Linux-shaped on macOS (LD_LIBRARY_PATH, which dyld ignores), and
the installer's own staged-binary validation does set DYLD_LIBRARY_PATH, so
nothing at install time could see the defect.

Assert it here, where a real runtime is installed. A unit test with a
monkeypatched sys.platform can only prove the branch is taken; this proves the
launch environment points dyld at the dylibs that are actually on disk. Runs
under the interpreter the `unsloth` shim points at, so the backend imports
resolve without installing anything extra, and skips cleanly if no shim is on
PATH.

Verified on macos-14: fails on the pre-fix revision of llama_cpp.py, passes on
the current one.
@danielhanchen

Copy link
Copy Markdown
Member Author

Added a regression guard for this in the macOS CI, folded into the existing assert-llama-loads.sh rather than a new job so it reuses that step's install.

That script already installs a real llama.cpp and runs llama-server --version to prove the binary loads on the host, but it launches from the shell's own environment, which says nothing about the one Studio builds for its child. It now also asserts that the child environment points dyld at the dylibs that are on disk. A unit test with a monkeypatched sys.platform can only prove the branch is taken; this proves the launch environment is right against a real install.

It runs under the interpreter the unsloth shim points at, so the backend imports resolve without installing anything extra, and skips cleanly when no shim is on PATH. Verified on macos-14: it fails on the pre-fix revision of llama_cpp.py and passes on the current one.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 3 commits August 12, 2026 17:13
Five follow-ups from the second review round, all consequences of the first
fix not reaching far enough.

The RAG embedding server only got the dyld search path on its GPU branch,
because it was bolted onto the CUDA helper. A CPU start (EMBED_DEVICE=cpu, or
the retry after a failed GPU start) loads the same sibling dylibs, so the path
now applies whichever device it lands on.

That server also passed Path(binary).parent as the library directory, while the
chat backend resolves the entrypoint with _llama_lib_dir. The managed install
puts an entrypoint in front of the real server, so on a normal install the
wrapper's own directory was named instead of the one holding the dylibs.

Its capability probe ran `llama-server --help` with no loader environment at
all, ahead of any launch. A bundle that needs the search path dies in the
loader there, and the error text reads as help output with no --embedding in
it, so the user was told their build lacks embedding support instead of that it
failed to load. The probe now runs under the same environment as the launch.

On macOS the launch resolves a shell entrypoint before spawning it. SIP purges
DYLD_* while starting the protected /bin/sh, so the loader path did not survive
a wrapper's exec of the real binary. The wrapper does nothing but exec the
target, so this is the same launch without the shell hop.

Secret redaction in the diagnostics tail now uses the same predicate that
decides what to strip from a managed server's own environment, plus URL
userinfo and common token shapes. The previous name-marker list missed
DATABASE_URL, REDIS_URL and GITHUB_PAT, which is exactly the class of variable
whose name says nothing about its contents.
Two follow-ups from the third review round.

A "Symbol not found" with no missing file was always reported as llama.cpp
libraries from different builds. That is right when dyld expected the symbol in
one of our dylibs, and wrong when it expected it in a system framework: there
the build wants a newer macOS than this one, and reinstalling the same build
cannot make the OS export the symbol. Read the "Expected in:" path and pick the
remedy from it. The MTLResidency special case is the same failure, now covered
by the general rule as well.

The macOS launch-environment assertion looked the interpreter up with
`command -v unsloth`. The clean-machine lane scrubs PATH to system directories
and puts the shim under its own UNSLOTH_STUDIO_HOME, so the lookup came back
empty exactly there and the check skipped, while the job still reported success.
It resolves from STUDIO_HOME first now, and a missing interpreter fails rather
than skips: an install that produced a llama-server but no reachable
interpreter is a broken install, and a skip is indistinguishable from a pass.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Three follow-ups from the fourth review round.

The interpreter lookup added last round misses the tauri delivery, which nests
its venv one level deeper at $STUDIO_HOME/studio/unsloth_studio. Since the same
commit made a missing interpreter fail rather than skip, that turned a good
tauri install into a red job. Both layouts are candidates now.

The embedding server built its loader environment from the resolved directory
but still probed and launched the entrypoint itself, so on macOS SIP would take
DYLD_* away again on the way through the wrapper. It resolves the executable
once, before the capability probe, so both the probe and the spawn run the real
binary.

The startup diagnostics could echo our own --api-key. It is minted per launch
with secrets.token_urlsafe(32), so it is in no environment variable to look up
and matches no token shape; the log path already treated it as sensitive but
the API error did not. It is now redacted by its flag, and the live value is
handed to the scrubber so it goes wherever it appears.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits August 12, 2026 17:40
Five follow-ups from the fifth review round, all narrowing something the
previous rounds made too broad.

Resolving a shell entrypoint past its exec line is right for the one the
installer generates and wrong for a user's own: a custom LLAMA_SERVER_PATH
wrapper may export backend variables before it execs, and jumping to the target
would drop that silently. Resolution is now gated on the binary being ours,
through a single _exec_path_for_launch used by the chat launch, the capability
probe and the embedding backend.

That probe needed it too. Only load_model resolved, so the startup, status and
preflight routes still probed the wrapper, lost DYLD_* to SIP, and read back
inconclusive capabilities, which clamps parallel slots and disables DSpark and
DFlash sizing on a server that supports both.

Stripping only the leading directive left "@loader_path/../Frameworks/libomp.dylib"
as "../Frameworks/libomp.dylib", still path-like enough to earn the same
"missing from that exact location" advice one level in. Placeholder install
names reduce to the library name now.

The classifier is pure text and runs on every platform, so keying a macOS
diagnosis on the words "Symbol not found" claimed a Linux wrapper's plugin
error as a mixed macOS runtime, and suppressed the output tail that would have
shown what really happened. It now requires dyld's own framing.

Redaction skipped any value under eight characters, which is the right rule for
a port number and the wrong one for DATABASE_PASSWORD=hunter2. Short values
from secret-named variables are redacted where they appear beside their name,
rather than globally.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 12, 2026
danielhanchen and others added 2 commits August 13, 2026 11:05
One conflict, in the embedding server child environment. Main added
arch-gated GPU pinning inside the use_gpu branch; this branch had put a
darwin branch in front of it and turned the trailing else into
"if not use_gpu" so a macOS CPU start still blanks the devices.

Kept both: the darwin branch stays first, main's pinning stays inside
the Linux GPU branch verbatim, and the device blanking stays an
independent "if not use_gpu" so darwin still reaches it.

Checked the resolution against main over
[linux, win32, darwin] x [gpu, cpu] x [no pin, pinned]: linux and
win32 are identical in all eight cases, and darwin differs only by
gaining DYLD_LIBRARY_PATH. Skipping the pinning call on darwin is a
no-op there, since _arch_gate_survivors returns an empty list without a
mapped_targets marker and macOS has none.

688 tests pass in the changed areas.
danielhanchen and others added 4 commits August 13, 2026 11:55
_classify_llama_start_failure returned the child's stdout unchanged when
that stdout carried the framing _with_startup_diagnostics writes. I added
that early return two rounds ago to keep re-classification a fixed point.
It was a bad trade: the guard reads untrusted text, so a wrapper or a
diagnostic build whose first line happens to be "llama-server output:" or
"Full log: " had its whole stdout returned as the API error, past the
redaction and past the 2000-character cap.

Measured on the branch before this commit, with an environment dump behind
the heading: 50067 characters returned verbatim with the credential intact
and no log path, against 2136 characters, scrubbed, for the same bytes
without the heading.

Removed the early return. The only guard on our own framing is the one in
_with_startup_diagnostics, which reads the message this module built
itself, and that one is safe.

The property this drops was for a caller that does not exist. What
replaces it is the property that actually matters and is now pinned by a
test: repeated passes stay bounded. Each pass wraps the previous message
in a fresh tail, roughly 136 characters, and the tail cap stops it at
2136 no matter how many times it runs.

Tests: the fixed-point test is replaced by a bounded-growth test plus a
parametrised regression test covering all four ways the heading can
appear. 141 tests in the classification suite, 688 across the changed
areas.
Attaching a tail of llama-server's own stdout to the failure message had a
consequence I missed. The inference route scans the whole error string for
unsupported-model phrases:

    _NOT_SUPPORTED_HINTS = ("No config file found", "not yet supported",
                            "is not supported", "does not support")

Those now match inside the quoted child output. So a llama-server that
prints a line like "ggml_vulkan: device Intel(R) UHD does not support
16-bit storage" gets its failure rewritten to "This model is not supported
yet. Try a different model." The model was fine; the message sends the
user to replace it.

llama.cpp prints lines of that shape for ordinary reasons, so this was
reachable on Linux and Windows as much as on macOS. Reproduced on the
branch before this commit with three different phrasings.

_diagnosis_text() cuts the message at the diagnostics block, and both the
unsupported-model matcher and the NVFP4 matcher now decide on the part
this backend wrote. The evidence still reaches the user, and is still
quoted in full when a rewrite does happen; it just no longer votes on the
diagnosis. A message with no diagnostics block is returned unchanged, so
every other error source is untouched.

Tests: 11 new, covering four real llama.cpp phrasings, the same phrase in
our own text (still rewritten), our text carrying a tail (still rewritten,
evidence preserved), the NVFP4 matcher, and four shapes that must pass
through unchanged. 710 tests pass across the changed areas.

Whole backend suite against origin/main: 244 failures on each side, the
same 244, no regressions.
Two findings from a fresh adversarial pass over the diagnostics tail, both
reproduced on the branch before this commit.

Redaction missed an encoded secret. _scrub_secret_values matched the
credential's literal text, so it only worked when the child printed the
value verbatim. A wrapper dumping its environment as JSON prints

    DB_PASSWORD = pa"ss\word-12345

as

    {"DB_PASSWORD": "pa\"ss\\word-12345"}

which is a different string. The escaped form went into the API error
fully reconstructible. URL-encoding it did the same.

_redact_secret_assignments replaces whatever sits beside a secret-looking
NAME, in the three shapes an environment dump takes: shell-ish, JSON and
bare. Positional, so the encoding does not matter, and it also covers a
value we never set and therefore could not have matched on. The old
value pass stays, because it catches a credential under a name that does
not look like one. The remaining gap is an unrecognised name AND an
escaped value.

Checked against over-redaction, which would defeat the point of the tail:
PATH, port, n_ctx, model_path, timings and llama_model_loader lines are
all untouched. Both regex arms are unambiguous single-character
alternations, so the pass is linear; 200000-character pathological inputs
run in 7 to 52 ms.

The library name was unbounded. A dyld install name is a path and macOS
PATH_MAX is 1024, but nothing enforced that on untrusted output: a
200093-character input produced a 100444-character HTTP error. Capped at
2048 with an ellipsis, which cannot truncate anything the loader could
have produced. A real name is unchanged.

Tests: 22 new across encoded secrets, the never-set value, six
over-redaction controls, four linearity checks and the name cap. 722 pass
across the changed areas. The 1392-scenario classifier differential
against origin/main is unchanged: 540 non-dyld differences, all still
strictly additive, 0 violations.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits August 13, 2026 12:35
…appers

Three findings, all reproduced on the branch before this commit. Two of
the three are defects in code I added earlier in this PR.

Redaction only covered the tail. _scrub_secret_values ran inside
_with_startup_diagnostics, so it protected the fallback and nothing else.
Every other branch also quotes untrusted text: a dyld message names the
library it could not load, and that name comes from the child. A
credential appearing there went out in the API error while the same
credential in the tail was starred out. Verified with a token as the
library name: leaked before, redacted now.

The fix is one boundary rather than one guard per interpolation, which is
the arrangement that let this through in the first place. The classifier
body moves to _classify_start_failure_text and the public function scrubs
whatever comes back. Scrubbing twice is a no-op, since a redacted value no
longer matches.

The quoted arm ended on either quote character. So a JSON value holding an
apostrophe, or a shell value holding a quote, failed to match, fell
through to the bare arm, and that arm stops at whitespace:

    {"DB_PASSWORD": "prefix' supersecret"}

left ` supersecret"` standing in the API error. The arm now closes on the
delimiter it opened with. Still linear, still an unambiguous alternation.

Launch resolution stepped over somebody else's wrapper. Approving the
outer entrypoint says nothing about what it points at, so an
installer-shaped symlink whose target was a hand-written wrapper had that
wrapper skipped on macOS, along with any exports it set, even though
running the symlink directly would have executed it. _resolve_llama_binary
grows a template_only flag: launching stops at the first link that is not
the installer's own template, while the library-directory lookup keeps
following the whole chain, because that is where the dylibs sit whoever
wrote the links. Pinned by a test on each of the three shapes.

Tests: 9 new. 731 pass across the changed areas, 1482 across every
llama.cpp and secret-handling suite. Both differentials against
origin/main are unchanged: 1392 classifier scenarios with 540 non-dyld
differences, all still strictly additive and 0 violations, and 1080 env
scenarios differing on darwin only.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits August 13, 2026 13:11
All three reproduced on the previous head. Each is reachable by a wrapper
or crash handler that prints its own configuration rather than the
environment we can match values against, which is the case the name pass
exists to cover and where it was weakest.

An unterminated quoted value leaked its tail. A truncated line ends the
output mid-value, so

    DB_PASSWORD="prefix supersecret

has no closing delimiter, cannot match the terminated arm, and fell to the
bare arm, which stops at whitespace and left ` supersecret` behind. A
third arm now runs an opened-but-unclosed quote to the end of the line,
ordered after the terminated arm so a properly closed value still prefers
that one. The opening delimiter is kept and no closing one is invented,
since that would misreport what the child printed. Only the value's line
is consumed; a following line survives.

A config-style key was never tested. The name accepted shell identifiers
only, so `db-password` and `api-key` never reached is_secret_env_name at
all. The name now accepts hyphens and dots, and the separator is
normalised to an underscore before the predicate is asked, because the
predicate's markers are underscored (API_KEY, PRIVATE_KEY). The predicate
stays the one place that decides what counts as a secret.

Checked hard against over-redaction, since a wider name is the obvious way
to make this worse: model-path, ggml.backend, n-gpu-layers, cache.type-k,
llama_model_loader and timing lines are all untouched.

Overlapping literals masked each other. With TOKEN_A=abcdefgh and
TOKEN_B="abcdefgh VERYSECRET", replacing the short value first rewrote the
long one's only occurrence to "*** VERYSECRET", after which the long value
no longer matched itself and its tail went out. The minted secrets and the
environment's own values are now collected into one set and replaced
longest first, so a credential cannot partially mask another before it is
scrubbed. Order-independent, verified both ways round.

Tests: 20 new. 185 in the classification suite, 1715 across every
llama.cpp and secret-handling suite. Both differentials against
origin/main unchanged: 540 non-dyld classifier differences, all strictly
additive, 0 violations; 1080 env scenarios differing on darwin only.
Linearity re-checked on the widened pattern: 200000-character inputs in 15
to 61 ms.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 7ff0ef0a9c

ℹ️ About Codex in GitHub

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

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

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

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

@danielhanchen
danielhanchen merged commit ce3f5c9 into main Aug 13, 2026
42 of 58 checks passed
@danielhanchen
danielhanchen deleted the fix-macos-llama-server-loader-diagnostics branch August 13, 2026 13:32
danielhanchen added a commit that referenced this pull request Aug 30, 2026
Backend CI (Python 3.13) failed on main a6887c5:

  test_a_pathological_reason_does_not_stall_the_classifier
  AssertionError: assert (728.070290015 - 727.064322356) < 1.0

1.006s against a 1.0s budget, missed by six milliseconds, on a classifier that
costs about ten.

The caps #8574 added are working. Measured here, the classifier holds ~0.0097s
median over seven runs, 0.0168s worst, which is a hundredfold margin under the
budget. Nothing regressed; the clock was the wrong one.

What the caps buy is that the candidate scan stops being quadratic, and that is
a cost in cycles. Wall clock also counts every microsecond this thread is not
running, and a hosted runner running the whole backend suite deschedules freely.
Pinned to one core, against four spinners on that same core:

  no contention    wall 0.0097s   cpu 0.0097s
  contended        wall 0.0429s   cpu 0.0118s
  contended        wall 0.0249s   cpu 0.0098s
  contended        wall 0.0516s   cpu 0.0096s

Identical work. The wall reading moves 5.3x and the CPU reading does not move at
all. That is the whole failure: CI charged the classifier for time it spent
waiting for a core.

So the assertion measures time.process_time(). The budget stays 1.0s because it
was never the problem: healthy is ~0.01s and the regression it guards is 6.3s,
two orders of magnitude of room on either side.

It keeps its teeth. Lifting _DYLD_REASON_MAX_CHARS and _DYLD_REASON_SCAN_CHARS
to 100M restores the quadratic scan, and the assertion catches it on CPU time at
6.33s, which is the 6.3s the docstring records. Under the four spinners above the
whole file passes, taking 25.4s wall for what is normally 6s.

One thing this does not show: that the old assertion would have failed under
that same contention. It would not have -- 0.0516s is well inside 1.0s. CI's
1.006s on a 0.01s classifier is roughly a hundredfold inflation, heavier than
four spinners on one core reproduce here. The mechanism is what is demonstrated,
and it is the only thing that explains a six-millisecond miss on a budget with a
hundredfold margin.

studio/backend/tests/test_llama_cpp_start_failure_classification.py: 224 passed.

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.

1 participant