Skip to content

test: skip pinned muse_glimmer checkpoint tests and fix MLXCEL_BACKEND race - #1157

Merged
inureyes merged 2 commits into
mainfrom
fix/issue-1155-muse-glimmer-test-hygiene
Aug 14, 2026
Merged

inureyes merged 2 commits into
mainfrom
fix/issue-1155-muse-glimmer-test-hygiene

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Fixes three pre-existing muse_glimmer test defects (introduced with #1116, unrelated to epic #1148) that prevented cargo test --release --features metal,accelerate --lib from being green on a machine without the pinned models/mlx/muse-glimmer-30b checkpoint.

What changed

  • src/loading/vlm_muse_glimmer_tests.rs: pinned_weight_index_classifies_each_source_weight_once now checks whether model.safetensors.index.json exists before calling read_muse_weight_inventory_from_index, and skips with an eprintln reason instead of panicking when the pinned checkpoint is absent, matching the pattern already used in tests/prompt_cache_e2e.rs.
  • src/vision/encoders/muse_glimmer_fusion_tests.rs: pinned_post_tower_weight_roots_and_shapes_match_published_contract skips the same way instead of asserting on the missing index file.
  • src/server/muse_glimmer_startup_guard_tests.rs: muse_glimmer_startup_allows_baseline_and_keeps_video_disabled now acquires the crate-wide crate::test_support::env_lock::env_lock() guard before calling validate_muse_glimmer_unsupported_startup, which reads MLXCEL_BACKEND. The sibling test muse_glimmer_startup_rejects_xla_backend_selection in the same module already sets MLXCEL_BACKEND=xla under that lock; without the baseline test also taking it, the baseline test could intermittently observe the transient value under default parallel test execution and fail. A grep of MLXCEL_BACKEND across src/ confirmed no other test module mutates it, so no other module needs to share this lock.

Both pinned-checkpoint tests still run their full contract check when the index file is present; that arm could not be exercised on this machine (no models/mlx/ directory) and is verified by code inspection only, as noted in the commit body.

Test plan

  • cargo test --release --features metal,accelerate --lib muse_glimmer (80 passed, 0 failed, on a machine without models/mlx/muse-glimmer-30b)
  • cargo test --release --features metal,accelerate --lib muse_glimmer_startup_guard, repeated 5 times under default parallelism (5 passed each run, no flakes observed)
  • cargo check --lib --tests --features metal,accelerate
  • cargo clippy --release --lib --tests --features metal,accelerate -- -D warnings (clean)
  • cargo fmt --check (clean)

Closes #1155

…D race

Two Muse Glimmer tests introduced with #1116 panicked on a machine without the pinned models/mlx/muse-glimmer-30b checkpoint instead of skipping: loading::vlm::muse_glimmer::tests::pinned_weight_index_classifies_each_source_weight_once panicked reading the missing safetensors index, and vision::encoders::muse_glimmer_fusion::tests::pinned_post_tower_weight_roots_and_shapes_match_published_contract asserted on the same missing file. Both now check for the index file first and skip with an eprintln reason, matching the pattern already used in tests/prompt_cache_e2e.rs, while still running the full contract check when the checkpoint is present.

server::startup::muse_glimmer_startup_guard_tests::muse_glimmer_startup_allows_baseline_and_keeps_video_disabled also failed intermittently under the default parallel test runner. The sibling test in the same module, muse_glimmer_startup_rejects_xla_backend_selection, mutates the process-wide MLXCEL_BACKEND env var under the crate-wide env_lock guard, but the baseline test called into the same env-reading validate_muse_glimmer_unsupported_startup without acquiring that lock, so it could observe the transient MLXCEL_BACKEND=xla value. The baseline test now acquires crate::test_support::env_lock::env_lock() for the duration of its call. A grep of MLXCEL_BACKEND across src/ confirmed no other test module mutates this variable, so no other lock sharing is needed.

Verified on a machine without models/mlx/muse-glimmer-30b: cargo test --release --features metal,accelerate --lib muse_glimmer (80 passed), and cargo test --release --features metal,accelerate --lib muse_glimmer_startup_guard repeated 5 times under default parallelism (5 passed each run). cargo clippy --release --lib --tests --features metal,accelerate -- -D warnings and cargo fmt --check both pass. The checkpoint-present arm of the two skip fixes could not be exercised on this box and is verified by code inspection only.

Refs #1155
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority area:models Model architectures, weights, loading, metadata status:review Under review labels Aug 14, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Make cargo test --release --features metal,accelerate --lib green on a box without the pinned models/mlx/muse-glimmer-30b checkpoint, by fixing three pre-existing test defects from #1116 (two panics on a missing checkpoint index, one MLXCEL_BACKEND race).

Findings Addressed

None. No CRITICAL or HIGH findings; no fixes were required.

Verification performed by this review

Skip guards (deliverable a). Both guards test exactly models/mlx/muse-glimmer-30b/model.safetensors.index.json, which is the same file read_muse_weight_inventory_from_index reads and the same file the fusion test parses, so the guard condition matches the real precondition with no false-skip window. The checkpoint-present arms are byte-identical to their pre-PR bodies: the loading test still asserts the full MuseWeightInventory { 626, 806, 2, 1, 1, 1436 } equality, and the fusion test still runs config validation, the sorted post-tower key list, and the three per-shard safetensors shape assertions. No assertion was weakened or removed. The eprintln! skip wording matches the established repo pattern (tests/prompt_cache_e2e.rs:201, plus roughly 25 other call sites under tests/), including the Skipping <test_name>: <reason> form. Confirmed with --nocapture that both messages actually print on this machine (models/mlx does not exist) and both tests report ok.

Env lock (deliverable b). The sibling muse_glimmer_startup_rejects_xla_backend_selection already took crate::test_support::env_lock::env_lock() at line 148 and holds it across both the set_var and the restore, so with the baseline test now taking the same guard, both sides of the race hold the same lock. env_lock() recovers from poisoning via unwrap_or_else(|p| p.into_inner()), so a panic in one env test cannot cascade into spurious failures elsewhere. crate::test_support::env_lock is the crate's established helper (declared #[cfg(test)] pub(crate) mod test_support at src/lib.rs:52, 18 acquisition sites across the crate), not a new parallel invention.

Differential proof that the lock is load-bearing. Removing only the added env_lock() line and rerunning cargo test --release --features metal,accelerate --lib muse_glimmer_startup_guard: 25/25 runs FAILED. With the line restored: 10/10 runs passed. The two arms are unambiguously distinguished; this is a real fix, not a coincidental reordering.

Criterion 4 (no other test can observe the transient value), verified independently rather than taking the PR body's mutator-only argument. Under --features metal,accelerate the only MLXCEL_BACKEND reader reachable from a lib test is xla_backend_requested_from_env() (src/server/startup.rs:772), called from validate_muse_glimmer_unsupported_startup. Its other caller, start_server (src/server/startup.rs:1715), is not unit-tested. The three assert_rejected siblings in the module never reach the env read, because the XLA ensure! is the last check in the function and each of their mutated fields trips an earlier ensure! that returns first. backend::select_backend's env-reading form is compiled only under experimental-backend / xla-backend, and model_provider.rs:302 only under xla-iree; none are in the CI matrix. So the criterion holds for the stated feature set.

No production code touched. All three changed files are _tests.rs. cargo fmt --check clean on all three. Commit message follows commit-conventions (test: prefix, unwrapped body, no AI attribution) and honestly records that the checkpoint-present arm was verified by inspection only.

Remaining Items

  • (LOW, pre-existing, not fixed here) Under the opt-in xla-backend / experimental-backend features, backend::tests::mlx_session_threads_the_token_bias_through calls select_backend(), which reads MLXCEL_BACKEND without the env lock, and carries an unreachable!("select_backend defaults to MLX without MLXCEL_BACKEND=xla") arm that would fire if it observed the transient value. Neither feature is in the CI matrix and neither is in this issue's scope, so fixing it here would widen a test-hygiene PR. Worth a follow-up if an XLA build is ever added to CI.
  • (LOW, accepted tradeoff) The eprintln! skip pattern reports a skipped test as ok, so a partially-downloaded checkpoint (directory present, index missing) would silently skip rather than fail. This is the repo-wide convention and issue test: muse_glimmer tests panic without the pinned checkpoint and race on MLXCEL_BACKEND #1155 explicitly preferred it over #[ignore].

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow (test-only change; both fixed tests run in the default lib suite)
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass

@inureyes

Copy link
Copy Markdown
Member Author

Security and performance review

No CRITICAL or HIGH findings. Test-only change, no production code touched, nothing auto-fixed.

Re-verified on this box: cargo test --release --features metal,accelerate --lib muse_glimmer (80 passed, 0 failed, 0.33s) and --lib muse_glimmer_startup_guard repeated 3x (5 passed each, no hang).

Deadlock analysis: clear

  • env_lock() is a non-reentrant std::sync::Mutex, but nothing called under the guard can re-acquire it. test_support is #[cfg(test)]-gated at the crate root, so validate_muse_glimmer_unsupported_startup, detect_model_media_support, get_model_type, and tempfile structurally cannot reach it.
  • No lock-ordering cycle. The only other static test mutexes are the per-module MLX serialization guards in models/gemma3n_helpers_tests.rs, models/llama4_helpers_tests.rs, and models/cohere2_moe_tests.rs. None acquires env_lock while held, and none is acquired while env_lock is held.
  • Poison recovery (unwrap_or_else(|p| p.into_inner())) prevents a panicking test from wedging every later env test.
  • Drop order is correct: _env_guard is declared first, so it releases after the TempDir.

MEDIUM: acceptance criterion 4 is not fully met under --features xla-backend

The commit's grep covered mutators of MLXCEL_BACKEND, but the hazard class is readers. src/backend/tests.rs:103 (mlx_session_threads_the_token_bias_through) calls select_backend(), which under xla-backend or experimental-backend reads MLXCEL_BACKEND at src/backend/mod.rs:316 without the env lock. If it observes the sibling's transient xla it takes Session::Xla and hits the unreachable! at line 122.

Pre-existing (the setter came in with #1116), and not reachable in the default or CI feature sets since no workflow enables xla-backend. The one-line fix is let _env_guard = crate::test_support::env_lock::env_lock(); at the top of that test. Left unfixed here to keep this PR scoped; worth a follow-up so #1155's "no other test can observe a transient value" holds for feature-gated builds too.

LOW

  1. Incomplete skip guard, src/vision/encoders/muse_glimmer_fusion_tests.rs:203. The guard checks only model.safetensors.index.json, then unwrap()s the config.json read and every shard open in safetensors_shape. A partially materialized checkpoint (interrupted mlxcel download or hf download, since files land incrementally) panics with an opaque unwrap instead of skipping. The sibling loading test has no such gap because read_muse_weight_inventory_from_index reads the index and nothing else.
  2. Silent coverage erosion. On the machine that owns the pinned checkpoint, a moved or renamed model dir turns both contract tests into green no-ops, and libtest captures the eprintln unless the run uses --nocapture. An opt-in MLXCEL_REQUIRE_PINNED_CHECKPOINTS=1 that fails instead of skipping would keep the skip honest. Same weakness exists in the tests/prompt_cache_e2e.rs pattern this follows.
  3. Ordering fragility. The other reject tests in the module avoid the unlocked env read only because ensure!(!xla_backend_requested_from_env()) is the last check in validate_muse_glimmer_unsupported_startup (src/server/startup.rs:827) and each of them trips an earlier ensure!. Move that check earlier, or add a check after it, and they silently regain the race.

Not findings

  • TOCTOU between exists() and the read is present but inert: hardcoded relative path, no attacker-controlled input, no privileged context, and the worst case is the panic the tests already produced before this PR.
  • Path handling. model_dir is a literal; the shard name comes from the pinned index JSON, which is a trusted local artifact read the same way by the production loader. No injection surface.
  • Resource use. No leaks. The guard is held across one tempdir create and two small config reads; the added serialization against the other env_lock users is not measurable (0.00s across three runs).

@inureyes

Copy link
Copy Markdown
Member Author

PR Finalization Complete

Summary

  • Tests: no new tests expected (change is test-only). Verified the three modified files against their respective conventions: the two checkpoint-skip guards match the existing eprintln-and-return pattern already used in tests/prompt_cache_e2e.rs, and confirmed by git log that both were introduced by feat(models): support Muse Glimmer MLX 4-bit #1116 (not this PR's baseline). Ran cargo test --release --features metal,accelerate --lib muse_glimmer (80 passed, 0 failed) and cargo test --release --features metal,accelerate --lib muse_glimmer_startup_guard 5 times under default parallelism (5 passed each run, no flakes). Grepped MLXCEL_BACKEND across src/; confirmed only muse_glimmer_startup_guard_tests.rs mutates it, so the added env_lock() guard is the correct scope and no other module needs to share it.
  • Documentation: none required (test-hygiene fix, no user-facing or architectural change). PR body's claim that the checkpoint-present arm is verified by code inspection only, not execution, is accurate and left as-is.
  • Lint/Format: cargo fmt --check on the three changed files is clean. cargo clippy --release --lib --tests --features metal,accelerate -- -D warnings ran against the existing build cache (no C++ recompile triggered) and is clean.

No changes were needed; the branch is unchanged from commit 79bc61a. Ready for merge.

@inureyes inureyes added status:done Completed and removed status:review Under review labels Aug 14, 2026
@inureyes
inureyes merged commit 92d6d4c into main Aug 14, 2026
7 checks passed
@inureyes
inureyes deleted the fix/issue-1155-muse-glimmer-test-hygiene branch August 14, 2026 16:29
inureyes added a commit that referenced this pull request Aug 15, 2026
…ds (#1169)

## Summary

Closes a pre-existing test-only race in `src/backend/tests.rs`: under the opt-in `xla-backend` / `experimental-backend` features, `select_backend()` reads `MLXCEL_BACKEND`, and a parallel full-suite run could interleave with `muse_glimmer_startup_rejects_xla_backend_selection` (which transiently sets that variable while holding the crate-wide env lock added in #1157) and make a backend test observe the transient `xla` value instead of the default MLX selection.

## What changed

- `src/backend/tests.rs`: all four `select_backend()` call sites now acquire `crate::test_support::env_lock::env_lock()`, bound to a named `_env_guard` variable (never a bare `_`, since dropping it immediately would reinstate the exact race this fix closes), before calling `select_backend()`.
- `mlx_session_threads_the_token_bias_through` (the test named in the issue) is guarded: without the lock it would hit the `unreachable!("select_backend defaults to MLX without MLXCEL_BACKEND=xla")` arm under the race.
- `select_backend_resolves_to_mlx_under_default_features` is guarded: without the lock its `matches!(backend, Backend::Mlx(_))` and `backend.name() == "mlx"` assertions would fail under the race.
- `mlx_backend_creates_a_session_and_advertises_batched_serving` is guarded: without the lock, `backend.supports_batched_serving()` and the session's `caps.multimodal` assertion would fail under the race (the XLA scaffold session reports `multimodal: false`, the opposite of what this test asserts for MLX).
- `seam_delegates_to_real_mlx_loader_on_missing_dir` is guarded too, even though it would not fail outright under the race (both the MLX loader and the XLA scaffold's `load_unsupported()` return `Err` for a missing path): its docstring claims to prove the seam reaches the real MLX loader specifically, and without the lock a race could silently validate the XLA scaffold instead, defeating that claim without a visible test failure. All three of these sites were evaluated per the issue's discussion, and none were left unguarded.
- Each guarded test carries a short comment explaining why the lock is needed, since under default features `select_backend()` reads no environment variable and the lock can otherwise look superfluous to a future reader.
- Test-only change. `src/backend/mod.rs` (the feature-gated `select_backend` arm that reads `MLXCEL_BACKEND`) and `src/server/muse_glimmer_startup_guard_tests.rs` (already fixed by #1157) are untouched, and no production code path changed.

## Test plan

- [x] `cargo check --lib --tests` (default features)
- [x] `cargo test --lib backend::tests` (default features): 5 passed, 0 failed
- [x] `cargo clippy --lib --tests -- -D warnings` (default features): clean
- [ ] Full-suite parallel run with `--features metal,accelerate,xla-backend`: not run. This machine is a CUDA/GB10 Linux box where `metal` is not applicable, no CI workflow builds `xla-backend`, and a cold `mlxcel-xla` build exceeds local verification time budgets. Per the issue's accepted evidence, this PR relies on code inspection (the guard follows the exact `let _env_guard = crate::test_support::env_lock::env_lock();` pattern established by #1157 in `muse_glimmer_startup_guard_tests.rs`) plus the targeted default-feature run above.

Closes #1159
inureyes added a commit that referenced this pull request Aug 16, 2026
The paragraph claimed there was no availability pre-check before PR #1173. There was one, just a narrower one: PR #1157 (`92d6d4c8`) replaced the vision-side test's `assert!(index_path.exists(), ...)` with a silent skip and added the same index-absent skip to `pinned_weight_index_classifies_each_source_weight_once`. Issue #1161 records this as well, both in its third acceptance criterion and in its note that #1157 "added the index-absent guard".

As written the paragraph implied every partially materialized state was loud before #1173, which overstates what that PR gave up and therefore what the gate buys back. An absent index already skipped quietly under #1157. Restates the sequence accurately: #1157 made the index-absent case quiet, #1173 made the index-present-but-incomplete case quiet by replacing the unwraps past that guard, and `MLXCEL_REQUIRE_PINNED_CHECKPOINTS=1` restores the loudness for both.

Documentation only; no code, test, or gate behavior changes.
inureyes added a commit that referenced this pull request Aug 16, 2026
Bilingual report covering the shared pinned-checkpoint gate: why the gate had to move into test_support rather than be copied, why the loading-side panic on a classification error stays a panic, and why documenting when to enable the variable was half the deliverable given it was set nowhere in the tree. Records the two-step correction the pre-#1173 paragraph needed, since the #1157 and #1173 sequence is easy to state wrongly.
@inureyes inureyes self-assigned this Aug 27, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…D race (lablup#1157)

## Summary

Fixes three pre-existing muse_glimmer test defects (introduced with lablup#1116, unrelated to epic lablup#1148) that prevented `cargo test --release --features metal,accelerate --lib` from being green on a machine without the pinned `models/mlx/muse-glimmer-30b` checkpoint.

## What changed

- `src/loading/vlm_muse_glimmer_tests.rs`: `pinned_weight_index_classifies_each_source_weight_once` now checks whether `model.safetensors.index.json` exists before calling `read_muse_weight_inventory_from_index`, and skips with an `eprintln` reason instead of panicking when the pinned checkpoint is absent, matching the pattern already used in `tests/prompt_cache_e2e.rs`.
- `src/vision/encoders/muse_glimmer_fusion_tests.rs`: `pinned_post_tower_weight_roots_and_shapes_match_published_contract` skips the same way instead of asserting on the missing index file.
- `src/server/muse_glimmer_startup_guard_tests.rs`: `muse_glimmer_startup_allows_baseline_and_keeps_video_disabled` now acquires the crate-wide `crate::test_support::env_lock::env_lock()` guard before calling `validate_muse_glimmer_unsupported_startup`, which reads `MLXCEL_BACKEND`. The sibling test `muse_glimmer_startup_rejects_xla_backend_selection` in the same module already sets `MLXCEL_BACKEND=xla` under that lock; without the baseline test also taking it, the baseline test could intermittently observe the transient value under default parallel test execution and fail. A grep of `MLXCEL_BACKEND` across `src/` confirmed no other test module mutates it, so no other module needs to share this lock.

Both pinned-checkpoint tests still run their full contract check when the index file is present; that arm could not be exercised on this machine (no `models/mlx/` directory) and is verified by code inspection only, as noted in the commit body.

## Test plan

- [x] `cargo test --release --features metal,accelerate --lib muse_glimmer` (80 passed, 0 failed, on a machine without `models/mlx/muse-glimmer-30b`)
- [x] `cargo test --release --features metal,accelerate --lib muse_glimmer_startup_guard`, repeated 5 times under default parallelism (5 passed each run, no flakes observed)
- [x] `cargo check --lib --tests --features metal,accelerate`
- [x] `cargo clippy --release --lib --tests --features metal,accelerate -- -D warnings` (clean)
- [x] `cargo fmt --check` (clean)

Closes lablup#1155
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…ds (lablup#1169)

## Summary

Closes a pre-existing test-only race in `src/backend/tests.rs`: under the opt-in `xla-backend` / `experimental-backend` features, `select_backend()` reads `MLXCEL_BACKEND`, and a parallel full-suite run could interleave with `muse_glimmer_startup_rejects_xla_backend_selection` (which transiently sets that variable while holding the crate-wide env lock added in lablup#1157) and make a backend test observe the transient `xla` value instead of the default MLX selection.

## What changed

- `src/backend/tests.rs`: all four `select_backend()` call sites now acquire `crate::test_support::env_lock::env_lock()`, bound to a named `_env_guard` variable (never a bare `_`, since dropping it immediately would reinstate the exact race this fix closes), before calling `select_backend()`.
- `mlx_session_threads_the_token_bias_through` (the test named in the issue) is guarded: without the lock it would hit the `unreachable!("select_backend defaults to MLX without MLXCEL_BACKEND=xla")` arm under the race.
- `select_backend_resolves_to_mlx_under_default_features` is guarded: without the lock its `matches!(backend, Backend::Mlx(_))` and `backend.name() == "mlx"` assertions would fail under the race.
- `mlx_backend_creates_a_session_and_advertises_batched_serving` is guarded: without the lock, `backend.supports_batched_serving()` and the session's `caps.multimodal` assertion would fail under the race (the XLA scaffold session reports `multimodal: false`, the opposite of what this test asserts for MLX).
- `seam_delegates_to_real_mlx_loader_on_missing_dir` is guarded too, even though it would not fail outright under the race (both the MLX loader and the XLA scaffold's `load_unsupported()` return `Err` for a missing path): its docstring claims to prove the seam reaches the real MLX loader specifically, and without the lock a race could silently validate the XLA scaffold instead, defeating that claim without a visible test failure. All three of these sites were evaluated per the issue's discussion, and none were left unguarded.
- Each guarded test carries a short comment explaining why the lock is needed, since under default features `select_backend()` reads no environment variable and the lock can otherwise look superfluous to a future reader.
- Test-only change. `src/backend/mod.rs` (the feature-gated `select_backend` arm that reads `MLXCEL_BACKEND`) and `src/server/muse_glimmer_startup_guard_tests.rs` (already fixed by lablup#1157) are untouched, and no production code path changed.

## Test plan

- [x] `cargo check --lib --tests` (default features)
- [x] `cargo test --lib backend::tests` (default features): 5 passed, 0 failed
- [x] `cargo clippy --lib --tests -- -D warnings` (default features): clean
- [ ] Full-suite parallel run with `--features metal,accelerate,xla-backend`: not run. This machine is a CUDA/GB10 Linux box where `metal` is not applicable, no CI workflow builds `xla-backend`, and a cold `mlxcel-xla` build exceeds local verification time budgets. Per the issue's accepted evidence, this PR relies on code inspection (the guard follows the exact `let _env_guard = crate::test_support::env_lock::env_lock();` pattern established by lablup#1157 in `muse_glimmer_startup_guard_tests.rs`) plus the targeted default-feature run above.

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

Labels

area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: muse_glimmer tests panic without the pinned checkpoint and race on MLXCEL_BACKEND

1 participant