Repository navigation
test(mlx): trip on the cross-thread eval break that starts at core v0.31.2 - #115
Merged
Merged
Conversation
….31.2 Our pin, mlx-core v0.31.1, is the last release before ml-explore/mlx#3348 made CommandEncoder and default_stream() thread-local. mlx-swift's Stream.gpu and Stream.cpu are process-global statics materialized on whichever thread first touches MLX, so from v0.31.2 onward an eval on any other OS thread dies with Fatal error: There is no Stream(gpu, 0) in current thread. That is a process abort, not a throw, and we are squarely in its path: a Hummingbird server answering concurrent requests, a SwiftUI app, and Swift Concurrency tasks that hop cooperative-pool threads all evaluate off the thread that booted MLX. Filed upstream as ml-explore/mlx-swift#457, open with no maintainer response; the fix needs mlx-c's two default-stream entry points to use new_thread_unsafe_stream, which was bound in ml-explore/mlx-c#122. So the fork is doing two jobs, and only one of them was written down. It carries nine correctness cherry-picks, and it also holds us on the last core whose concurrency model matches the Swift layer. This test guards the second. What it does not do is fail. Demonstrating that would mean building against core >= 0.31.2, which is the whole of the bump it guards, so unlike the parity suites it has never been observed red. It is a transcription of the upstream reproduction, held green against the current pin, and the header says so. Also documents what a move off v0.31.1 actually costs, from a working 0.32.1 bump published on mlx-swift#450: the qmv template-arity abort that hits JIT-only builds like ours (fixed in core v0.32.2), NAX sources referencing symbols the header gates out below deployment target 26.2, update-mlx.sh missing gemv and searchsorted at 0.32.x, the mlx-c compile-cache handle, and the new FFT norm parameter.
The 45-day freshness guard on site content started failing every build on
2026-08-24: the competitor entries were last verified 2026-07-10. That guard
exists because the public site names each competitor's exact version, and four
of the five had genuinely moved — this was not a date technicality.
Ollama v0.31.2 -> v0.33.1 (two minors)
oMLX v0.4.4 -> v0.6.3 (two minors)
Swama v2.2.0 -> v2.3.0
SwiftLM b648 -> b704
LM Studio 0.4.19 Build 2 -> Bionic 1.1.0 (new version scheme)
Each claim was re-read against the source rather than the version string alone:
- oMLX is still Python-cored at 0.6.3 — 76.5% Python, requires Python
3.11-3.13, still a FastAPI server behind the SwiftUI menu-bar app — so our
positioning holds. It now requires macOS 15.0+, and its focus has grown to
continuous batching, prefix-shared paged caching, multi-token prediction,
and distributed serving.
- LM Studio still ships as app + llmster headless daemon + lms CLI, so only
the version string changed. Its Python-bundling wording is now
version-neutral, since the bundled version is no longer stated.
- Ollama's MLX runner gained structured output in v0.33.1.
- Swama gained prompt and KV-cache reuse on the chat completions path.
- SwiftLM b704 is a version-display fix; nothing descriptive changed.
The test dates move with the content, and they are coupled in three ways that
each surfaced as its own failure:
- the pinned `today` in 27 assertions, which must sit at or after the newest
snapshot date and before the facts expire (2026-09-03), so 2026-08-28;
- the negative assertion that staleness IS detected, which must sit after
the facts expire and after every snapshot, so 2026-09-05;
- the five future-date fixtures written as literals one day past the old
`today`, and the snapshot of exact verified versions.
Facts, releases, and pages are untouched: at 40 days they are still inside the
window, and v0.8.0 remains the current release. They expire 2026-09-03.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The fork has a second job nobody wrote down
We pin
mlx-core v0.31.1to carry nine correctness cherry-picks. It turns out that pin is also holding us on the last core release whose concurrency model matches mlx-swift's Swift layer — and that was luck, not design.ml-explore/mlx#3348madeCommandEncoderanddefault_stream()thread-local, first released in core v0.31.2. Every OS thread that asks for a default stream now gets its own, whose command encoder is registered only in that thread's registry. mlx-swift predates this:Process-global statics, materialized on whichever thread first touches MLX, handed to every op via
Device.defaultStream. From v0.31.2 onward, evaluating from any other OS thread gives:A process abort, not a throw.
We are squarely in the blast radius. A Hummingbird server answering concurrent requests, a SwiftUI app, and Swift Concurrency tasks that hop cooperative-pool threads all evaluate off the thread that booted MLX. This would not be a corner case for us; it would be total.
Upstream: ml-explore/mlx-swift#457, open since 2026-08-18 with no maintainer response. The fix belongs on the mlx-c side — point the two default-stream entry points at
new_thread_unsafe_stream, which registers in the global registry the Swift statics were built for. That binding landed in ml-explore/mlx-c#122.What this PR adds
CrossThreadEvalTripwireTests— a transcription of the upstream reproduction: materializeStream.gpuon the test thread, then evaluate from a detached one.It has never been observed to fail, and it says so in its own header. Demonstrating a red would mean building against core >= 0.31.2, which is the entire bump this guards. Unlike the parity suites, this is not an empirically inverted guard — it is a faithful transcription held green against the current pin. A failure will most likely arrive as a crashed run rather than a red assertion, since the abort takes the runner with it; the timeout branch only catches the milder hang.
Also: what a move off v0.31.1 actually costs
.claude/distribution.mdgains a section, drawn from a working 0.32.1 bump published on mlx-swift#450:qmv()passes 6 template args to 5-param kernel templatesmlx#4350→mlx#4372, already in core v0.32.2*_nax.cppreference symbols the header gates out below deployment target 26.2tools/update-mlx.shkernel make-list missinggemv/searchsortedat 0.32.xUpstream state as of this PR: mlx-c woke up on 2026-08-27 and now pins core v0.32.2, so the blocker davidkoski named on #441 is cleared. mlx-swift's own bump, #450, is open but conflicted (172 files, +20501/-7758).
Verification
CrossThreadEvalTripwireTestsxcodebuildexit 0MacMLXCoregatedxcodebuild testNo production code changes.
Note
Low Risk
Documentation and a gated regression test only; no runtime or vendored MLX changes.
Overview
Adds
CrossThreadEvalTripwireTests, which reproduces the mlx-swift#457 scenario: touch MLX on the test thread, thenMLX.evalon a detached thread. It is meant to catch a future mlx-core bump to ≥ v0.31.2 that ships thread-local default streams without the mlx-cnew_thread_unsafe_streamfix—failures may show up as a process abort rather than a failed assertion. The suite uses the samemlxMetallibIsAvailablegate as other Engine MLX tests..claude/distribution.mdgains “Moving off v0.31.1 is not a version bump”, documenting that pin exit is more than a one-line change: the cross-thread stream issue first, plus a checklist table (quantizedqmv, NAX generated sources on macOS 14,update-mlx.shkernel list, mlx-c compile cache, FFT C API) drawn from upstream bump work.No production or dependency pin changes in this PR.
Reviewed by Cursor Bugbot for commit 36ea800. Configure here.