AlexsJones/llmfit · info
valid MLX suffix regex
Error message
valid MLX suffix regex
What it means
An .expect() panic string in strip_mlx_quant_suffix (llmfit-core/src/providers.rs). OnceLock lazily compiles the hardcoded regex -\d+bit(?:-[a-z0-9]+)*$; Regex::new only fails on an invalid pattern, and this literal is a fixed, tested constant. The expect can therefore only fire if someone edits the pattern into an invalid regex — it is an internal-invariant assertion (per repo convention), not a runtime error users can trigger.
Source
Thrown at llmfit-core/src/providers.rs:3296
/// mlx-community basenames reduce to catalog slugs (#854).
/// "llama-3.2-1b-instruct-4bit" → "llama-3.2-1b-instruct"
///
/// End-anchored, unlike the GGUF list above: mlx-community always places the
/// quant scheme last, and dtype-like fragments can occur inside genuine model
/// names. Covers `-<N>bit` with optional trailing variant markers
/// (`-4bit-dwq`, date-stamped `-4bit-dwq-05082025`) and the compound schemes
/// `-mxfp4-q4`, `-mxfp4` and `-fp16`, stripped as whole units.
pub fn strip_mlx_quant_suffix(stem: &str) -> Option<String> {
for pat in ["-mxfp4-q4", "-mxfp4", "-fp16"] {
if let Some(base) = stem.strip_suffix(pat)
&& !base.is_empty()
{
return Some(base.to_string());
}
}
static MLX_BIT_SUFFIX: OnceLock<Regex> = OnceLock::new();
let re = MLX_BIT_SUFFIX
.get_or_init(|| Regex::new(r"-\d+bit(?:-[a-z0-9]+)*$").expect("valid MLX suffix regex"));
if let Some(m) = re.find(stem)
&& m.start() > 0
{
return Some(stem[..m.start()].to_string());
}
None
}
// ---------------------------------------------------------------------------
// llama.cpp name-matching helpers
// ---------------------------------------------------------------------------
/// Authoritative mapping from HF repo names to known GGUF repository IDs on HuggingFace.
/// Models not in this table fall back to a heuristic search.
const LLAMACPP_GGUF_MAPPINGS: &[(&str, &str)] = &[
// Meta Llama
(
"llama-3.3-70b-instruct",View on GitHub (pinned to e11c6e1925)
Solutions
- Revert or fix the regex literal in providers.rs to a valid pattern (e.g. the original r"-\d+bit(?:-[a-z0-9]+)*$")
- Run `cargo test -p llmfit-core providers` after touching the pattern to catch compile-time regex breakage in CI
Defensive patterns
Strategy: validation
Validate before calling
// CI/test guard: fail early if the MLX suffix pattern is edited into an invalid regex
#[test]
fn mlx_suffix_regex_compiles() {
assert!(regex::Regex::new(r"-\d+bit(?:-[a-z0-9]+)*$").is_ok());
assert_eq!(strip_mlx_quant_suffix("qwen3-4bit").as_deref(), Some("qwen3"));
} Prevention
- Never edit the pattern literal without running the providers unit tests
- Keep expect() messages tied to compile-time constants so reviewers see they are invariants
- Add a compile-check test for every OnceLock<Regex> in the codebase
When it happens
Trigger: A contributor changes the pattern string (e.g. introduces an unescaped '(' or mismatched brace) and the first call to strip_mlx_quant_suffix for a stem without the -mxfp4/-fp16 suffixes panics at regex compile time.
Common situations: Editing the MLX suffix rules without running the unit tests that exercise this function; cargo test suites that cover providers.rs would catch it before merge.
Related errors
- JSON serialization failed
- files list is not empty
- embedded benchmarks.yaml is invalid
- JSON serialization failed
- embedded use_case_benchmarks.json is invalid
AI-assisted analysis of AlexsJones/llmfit@e11c6e1925 (2026-08-17).
Data as JSON: /api/errors/95297f8b128374da.
Report an issue: GitHub.