{"record":{"id":"95297f8b128374da","repo":"AlexsJones/llmfit","slug":"valid-mlx-suffix-regex","errorCode":null,"errorMessage":"valid MLX suffix regex","messagePattern":"valid MLX suffix regex","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"llmfit-core/src/providers.rs","lineNumber":3296,"sourceCode":"/// mlx-community basenames reduce to catalog slugs (#854).\n/// \"llama-3.2-1b-instruct-4bit\" → \"llama-3.2-1b-instruct\"\n///\n/// End-anchored, unlike the GGUF list above: mlx-community always places the\n/// quant scheme last, and dtype-like fragments can occur inside genuine model\n/// names. Covers `-<N>bit` with optional trailing variant markers\n/// (`-4bit-dwq`, date-stamped `-4bit-dwq-05082025`) and the compound schemes\n/// `-mxfp4-q4`, `-mxfp4` and `-fp16`, stripped as whole units.\npub fn strip_mlx_quant_suffix(stem: &str) -> Option<String> {\n    for pat in [\"-mxfp4-q4\", \"-mxfp4\", \"-fp16\"] {\n        if let Some(base) = stem.strip_suffix(pat)\n            && !base.is_empty()\n        {\n            return Some(base.to_string());\n        }\n    }\n    static MLX_BIT_SUFFIX: OnceLock<Regex> = OnceLock::new();\n    let re = MLX_BIT_SUFFIX\n        .get_or_init(|| Regex::new(r\"-\\d+bit(?:-[a-z0-9]+)*$\").expect(\"valid MLX suffix regex\"));\n    if let Some(m) = re.find(stem)\n        && m.start() > 0\n    {\n        return Some(stem[..m.start()].to_string());\n    }\n    None\n}\n\n// ---------------------------------------------------------------------------\n// llama.cpp name-matching helpers\n// ---------------------------------------------------------------------------\n\n/// Authoritative mapping from HF repo names to known GGUF repository IDs on HuggingFace.\n/// Models not in this table fall back to a heuristic search.\nconst LLAMACPP_GGUF_MAPPINGS: &[(&str, &str)] = &[\n    // Meta Llama\n    (\n        \"llama-3.3-70b-instruct\",","sourceCodeStart":3278,"sourceCodeEnd":3314,"githubUrl":"https://github.com/AlexsJones/llmfit/blob/e11c6e1925118423ce20aeb8bc20c2ffcc07081b/llmfit-core/src/providers.rs#L3278-L3314","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// CI/test guard: fail early if the MLX suffix pattern is edited into an invalid regex\n#[test]\nfn mlx_suffix_regex_compiles() {\n    assert!(regex::Regex::new(r\"-\\d+bit(?:-[a-z0-9]+)*$\").is_ok());\n    assert_eq!(strip_mlx_quant_suffix(\"qwen3-4bit\").as_deref(), Some(\"qwen3\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["rust","regex","internal-invariant","panic"],"backgroundTag":"regex-compilation-failed","analyzedSha":"e11c6e1925118423ce20aeb8bc20c2ffcc07081b","analyzedAt":"2026-08-17T10:35:29.658Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}