Skip to content

fix(test): gate the loading-side pinned Muse Glimmer guard on MLXCEL_REQUIRE_PINNED_CHECKPOINTS - #1180

Merged
inureyes merged 5 commits into
mainfrom
fix/issue-1177-gate-loading-side-pinned-guard
Aug 16, 2026
Merged

inureyes merged 5 commits into
mainfrom
fix/issue-1177-gate-loading-side-pinned-guard

Conversation

@inureyes

@inureyes inureyes commented Aug 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Extends the pinned-checkpoint gate PR #1173 introduced to the loading-side sibling test, shares the gate logic between both call sites instead of duplicating it, and documents the variable including when and how to actually turn it on, per the scope the issue's comment added.

What changed

src/test_support/pinned_checkpoint.rs (new) holds a single skip_or_fail_pinned_checkpoint(test_name, reason) helper, declared from src/test_support/mod.rs alongside the existing env_lock module; it reads MLXCEL_REQUIRE_PINNED_CHECKPOINTS under crate::test_support::env_lock::env_lock(), drops the guard before asserting, and treats only the exact value 1 as enabling.
src/vision/encoders/muse_glimmer_fusion_pinned_tests.rs drops its private copy of the gate and calls the shared helper at both of its call sites, passing its own test name so the skip message is byte-identical to before and the failure message still names that test.
src/loading/vlm_muse_glimmer_tests.rs routes pinned_weight_index_classifies_each_source_weight_once's previously unconditional skip through the same shared helper, so it now fails rather than skips when the gate is on and the pinned index is absent; the existing panic! on read_muse_weight_inventory_from_index returning Err is untouched, since that is a genuine contract violation rather than an availability problem.
docs/environment-variables.md adds a row for MLXCEL_REQUIRE_PINNED_CHECKPOINTS to the existing "Test and CI variables" table, whose Variable | Purpose shape carries the value and default semantics inline, stating that only the exact string 1 enables it, plus prose covering that it is test-only, that it belongs on a machine that owns the pinned checkpoint, a single-run invocation example and a persistent-export suggestion, and its role in turning an ambiguous ok into positive evidence that the checkpoint was actually read (how acceptance criterion 2 of #1161 was proven).

Test plan

  • cargo check --lib --tests
  • cargo clippy --lib --tests -- -D warnings
  • cargo test --lib vision::encoders::muse_glimmer_fusion (23 passed, real pinned checkpoint present)
  • cargo test --lib loading::vlm::muse_glimmer:: (14 passed, real pinned checkpoint present)
  • Compiled test binary run from a temp directory with no models/, variable unset: both pinned guards skip, each still naming itself
  • Compiled test binary run from a temp directory with no models/, MLXCEL_REQUIRE_PINNED_CHECKPOINTS=1: both pinned guards fail, each still naming itself, exit 101

Closes #1177

…REQUIRE_PINNED_CHECKPOINTS

PR #1173 introduced MLXCEL_REQUIRE_PINNED_CHECKPOINTS=1 to turn the vision-side pinned Muse Glimmer contract test's graceful skip into a hard failure, so a half-downloaded or corrupted checkpoint cannot silently disable the only coverage that exists on the machine that owns it. The loading-side sibling, pinned_weight_index_classifies_each_source_weight_once, still used the original unconditional skip on an absent index, leaving the protection only half applied.

The gate logic (env_lock-guarded read of the variable, dropped before the assertion, strict equality on "1") is now extracted into a shared helper at src/test_support/pinned_checkpoint.rs, declared from src/test_support/mod.rs alongside the existing env_lock module. Both pinned guards call this one implementation instead of each holding a private copy; the helper takes the caller's test name as a parameter so each call site still names itself in its skip or failure message. The availability versus contract boundary from PR #1173 is preserved: this only ever turns a skip into a failure, and pinned_weight_index_classifies_each_source_weight_once still panics unchanged when read_muse_weight_inventory_from_index returns Err, since that is a genuine contract violation rather than an availability problem.

docs/environment-variables.md gains a table row for the variable in the existing "Test and CI variables" section, stating explicitly that only the exact string "1" enables it, unlike the document's usual truthy-parsing convention. The accompanying prose covers deliverable 4 from the issue comment: this is a test-only gate meant for a machine that owns the pinned checkpoint, how to enable it for one run or export it persistently, and its second use of turning an ambiguous "ok" into positive evidence that the checkpoint was actually read, which is how acceptance criterion 2 of issue #1161 was proven.

Verified on a machine with the pinned checkpoint present: both narrow test targets pass in full, including the two pinned guards, which read the real 60 GB checkpoint and validate their contracts. The skip and gated-failure paths were exercised by running the compiled test binary from a temp directory with no models/ present, both with the variable unset (both guards skip, naming themselves) and with MLXCEL_REQUIRE_PINNED_CHECKPOINTS=1 (both guards fail, naming themselves, exit 101).

Closes #1177
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:low Low priority area:models Model architectures, weights, loading, metadata status:review Under review labels Aug 16, 2026
… table

The entry arrived as a second table in the same section, introduced by a sentence explaining why its formatting differed. That is commentary about the document rather than about the variable, and the section's own precedent already shows rich detail belongs in the Purpose cell: the MLXCEL_ALLOW_PARALLEL_CUDA_TESTS and MLXCEL_ALLOW_CONCURRENT_GPU_TESTS rows both carry several sentences there.

Folds the row into the existing table with the value and default semantics stated inline, and drops the bridging sentence. The four prose paragraphs that follow are unchanged.
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Extend MLXCEL_REQUIRE_PINNED_CHECKPOINTS=1 to the loading-side pinned Muse Glimmer guard, share the gate between both call sites, and document the variable including when and how to actually turn it on (issue #1177 body plus its scope-adding comment).

Findings addressed

  • PR body described the doc change as a Variable | Values | Default | Notes row, which stopped being true after d399363 folded the entry into the section's existing two-column Variable | Purpose table. Corrected, since this body becomes the squash-merge commit body. (LOW)
  • PR body claimed the vision-side "skip or failure message is unchanged". The skip message is byte-identical, but the assertion message changed from "the pinned Muse Glimmer checkpoint is not usable" to "the pinned checkpoint <test_name> needs is not usable". Reworded to say what is actually true. (LOW)

Remaining items

  • src/lib.rs:47-49 still describes test_support as providing "the single shared ENV_LOCK", which is no longer exhaustive now that the module also holds the pinned-checkpoint gate. Its opening sentence ("Crate-wide helpers for #[cfg(test)] paths") still covers the module, so this is left alone rather than pulling the crate root into a test-only PR. (LOW, not fixed by design)
  • The loading-side call site passes its test name as an inline literal while the vision side hoists a TEST_NAME const. Both are correct and each file has the number of call sites that justifies its choice. (LOW, style only)
  • docs/environment-variables.md:38 contains a pre-existing em dash, unrelated to this PR and one of six docs files in that state. Not touched here. (LOW, pre-existing)

Verification

  • All stated requirements implemented, including the comment's fourth deliverable
  • No placeholder or mock code
  • Integrated: pinned_checkpoint is declared from test_support/mod.rs and called from both guards, no orphan
  • Correctness boundary intact: the helper only ever turns a skip into a failure, the loading-side panic! on read_muse_weight_inventory_from_index returning Err is untouched, safetensors_shape still panics rather than returning Err when a parsed header does not describe the key, and all four #[should_panic] synthetic contract tests carry expected = strings the gate's panic message cannot match, so the gate cannot let a contract regression pass for the wrong reason
  • Env-lock discipline correct: guard scoped to the read, dropped before the assertion, nothing inside the scope re-acquires the non-reentrant ENV_LOCK, and no caller of the helper holds that lock, so there is no deadlock against src/backend/tests.rs or src/server/muse_glimmer_startup_guard_tests.rs
  • Doc claims check out: nothing under .github/ or scripts/ references the variable, no production path reads it (test_support is cfg(test) at the crate root), and test: muse_glimmer fusion skip guard panics on a partially materialized checkpoint #1161's acceptance criterion 2 was indeed proven with this gate
  • Conventions: no AI attribution, no em dashes in any added line, Closes #1177 present, table row well formed at two columns like its neighbors
  • Tests pass (orchestrator-verified: 37 passed both with and without the gate against the real checkpoint, plus gate-off skip and gate-on failure from a directory with no models/)

The paragraph said a partially materialized checkpoint made the availability pre-check panic. There was no availability pre-check before #1173; that PR created it, and the panic came from unwrapping the reads directly. Restates what actually changed: unwraps became a pre-check that skips with a named reason while contract violations stay failures.
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

Copy link
Copy Markdown
Member Author

Security and performance review

Reviewed at d2b4f419 across the five dimensions this diff can actually carry risk in. No CRITICAL, HIGH, or MEDIUM findings. One LOW documentation-accuracy finding, fixed in 758fe64c.

Environment handling under Rust 2024

Sound. skip_or_fail_pinned_checkpoint binds the read as let required = { let _env_guard = env_lock(); ... }, so the guard is a named binding dropped at the end of the block rather than a temporary dropped at the end of the statement, and the assert! runs with the lock released.

  • No deadlock. env_lock is a non-reentrant std::sync::Mutex, but none of the three call sites (muse_glimmer_fusion_pinned_tests.rs:133, :185, vlm_muse_glimmer_tests.rs:477) holds it; neither module references env_lock anywhere else, and no env_lock holder in the crate reaches the helper, so there is no lock-order cycle.
  • No poisoning hazard, twice over: the guard drops before the assertion, and env_lock() already recovers with unwrap_or_else(|p| p.into_inner()).
  • No read/write race. Every env mutation in this crate's test binary takes the same lock. The three files that mutate the environment without it are src/multimodal/video.rs (a doc comment only, no mutation), src/cli/turbo_args.rs (production apply_to_environment, whose tests do take the lock), and src/loading/mod.rs (maybe_disable_cuda_graphs_for_model, reachable only from real model-load paths; src/backend/tests.rs exercises the seam with a nonexistent dir, where get_model_type(...)? returns before the write, and it holds the lock anyway).

Can the gate hide a failure

No. Its only effect when set is to panic; when unset it is byte-for-byte the prior eprintln! plus return. There is no path where setting or unsetting it lets a contract violation pass:

  • load_pinned_checkpoint returns Err for availability and readability only. An absent weight_map, an omitted pinned key, a config that parses but does not fit the schema, and a wrong recorded shape all flow past it to assertions.
  • safetensors_shape returns Err only for open/truncation/ceiling/parse problems, and panics rather than returning Err when a parsed header does not describe the key.
  • On the loading side the gate covers only the !index_path.exists() branch, upstream of every contract check; the panic! on read_muse_weight_inventory_from_index returning Err is untouched.
  • None of the four #[should_panic] tests can be satisfied by the gate's panic text. Their expected = strings are weight-key names, "does not deserialize into a Muse Glimmer config", and "failed: model.vision_adapter.fc1.weight"; the gate message carries only the variable name, the test name, and a reason that names paths, never keys. Independently, all four fail before reaching the gate, since their synthetic shards are well formed.

Surface

Not widened beyond the test binary. src/lib.rs:51-52 is a plain #[cfg(test)] pub(crate) mod test_support;, the new module is pub(crate) inside it, there is no re-export, and the only three references in the tree are the test call sites. Unreachable from production code, from the binaries, and from tests/.

Documentation (LOW, fixed)

The advice to export the variable persistently is safe: nothing outside the test files reads it, no code enumerates std::env::vars(), and there is no unknown-MLXCEL_* rejection, so a persistent export cannot affect a running mlxcel or mlxcel-server. The entry also does not overstate the gate's scope; it names the two tests it covers.

The last paragraph was inaccurate. It said there was no availability pre-check before PR #1173. PR #1157 (92d6d4c8) had already replaced the vision-side assert!(index_path.exists(), ...) with a silent skip and added the same index-absent skip on the loading side, which issue #1161 also records in its third acceptance criterion. As written it implied every partially materialized state was loud before #1173, overstating what that PR gave up and what the gate buys back. 758fe64c restates the sequence: #1157 made the index-absent case quiet, #1173 made the index-present-but-incomplete case quiet, and the gate restores loudness for both.

Performance

Nil. The lock is taken only on the skip or failure path, held for exactly one std::env::var call, and released before both the assertion and any I/O. In assert_post_tower_contract the shard header read happens outside the lock. On a machine with a complete checkpoint the helper is never called.

@inureyes inureyes added status:done Completed and removed status:review Under review labels 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 merged commit 9d78a1b into main Aug 16, 2026
7 checks passed
@inureyes
inureyes deleted the fix/issue-1177-gate-loading-side-pinned-guard branch August 16, 2026 05:50
@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
…REQUIRE_PINNED_CHECKPOINTS (lablup#1180)

## Summary

Extends the pinned-checkpoint gate PR lablup#1173 introduced to the loading-side sibling test, shares the gate logic between both call sites instead of duplicating it, and documents the variable including when and how to actually turn it on, per the scope the issue's comment added.

## What changed

`src/test_support/pinned_checkpoint.rs` (new) holds a single `skip_or_fail_pinned_checkpoint(test_name, reason)` helper, declared from `src/test_support/mod.rs` alongside the existing `env_lock` module; it reads `MLXCEL_REQUIRE_PINNED_CHECKPOINTS` under `crate::test_support::env_lock::env_lock()`, drops the guard before asserting, and treats only the exact value `1` as enabling.
`src/vision/encoders/muse_glimmer_fusion_pinned_tests.rs` drops its private copy of the gate and calls the shared helper at both of its call sites, passing its own test name so the skip message is byte-identical to before and the failure message still names that test.
`src/loading/vlm_muse_glimmer_tests.rs` routes `pinned_weight_index_classifies_each_source_weight_once`'s previously unconditional skip through the same shared helper, so it now fails rather than skips when the gate is on and the pinned index is absent; the existing `panic!` on `read_muse_weight_inventory_from_index` returning `Err` is untouched, since that is a genuine contract violation rather than an availability problem.
`docs/environment-variables.md` adds a row for `MLXCEL_REQUIRE_PINNED_CHECKPOINTS` to the existing "Test and CI variables" table, whose `Variable | Purpose` shape carries the value and default semantics inline, stating that only the exact string `1` enables it, plus prose covering that it is test-only, that it belongs on a machine that owns the pinned checkpoint, a single-run invocation example and a persistent-export suggestion, and its role in turning an ambiguous `ok` into positive evidence that the checkpoint was actually read (how acceptance criterion 2 of lablup#1161 was proven).

## Test plan

- [x] `cargo check --lib --tests`
- [x] `cargo clippy --lib --tests -- -D warnings`
- [x] `cargo test --lib vision::encoders::muse_glimmer_fusion` (23 passed, real pinned checkpoint present)
- [x] `cargo test --lib loading::vlm::muse_glimmer::` (14 passed, real pinned checkpoint present)
- [x] Compiled test binary run from a temp directory with no `models/`, variable unset: both pinned guards skip, each still naming itself
- [x] Compiled test binary run from a temp directory with no `models/`, `MLXCEL_REQUIRE_PINNED_CHECKPOINTS=1`: both pinned guards fail, each still naming itself, exit 101

Closes lablup#1177
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:low Low 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.

fix(test): gate the loading-side pinned Muse Glimmer guard on MLXCEL_REQUIRE_PINNED_CHECKPOINTS

1 participant