{"record":{"id":"ed9990f26273b70e","repo":"janhq/jan","slug":"invalid-metadata-block-count-not-found-or-invalid","errorCode":null,"errorMessage":"Invalid metadata: block_count not found or invalid","messagePattern":"Invalid metadata: block_count not found or invalid","errorType":"error_code","errorClass":"KVCacheError::BlockCountInvalid","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/types.rs","lineNumber":65,"sourceCode":"}\n\n#[derive(Serialize)]\npub struct GgufMetadata {\n    pub version: u32,\n    pub tensor_count: u64,\n    pub metadata: HashMap<String, String>,\n}\n\n#[derive(Debug, Serialize, Deserialize)]\npub struct KVCacheEstimate {\n    pub size: u64,\n    pub per_token_size: u64,\n}\n#[derive(Debug, thiserror::Error)]\npub enum KVCacheError {\n    #[error(\"Invalid metadata: architecture not found\")]\n    ArchitectureNotFound,\n    #[error(\"Invalid metadata: block_count not found or invalid\")]\n    BlockCountInvalid,\n    #[error(\"Invalid metadata: head_count not found or invalid\")]\n    HeadCountInvalid,\n    #[error(\"Invalid metadata: embedding_length not found or invalid\")]\n    EmbeddingLengthInvalid,\n    #[error(\"Invalid metadata: context_length not found or invalid\")]\n    ContextLengthInvalid,\n}\n\nimpl serde::Serialize for KVCacheError {\n    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>\n    where\n        S: serde::Serializer,\n    {\n        serializer.serialize_str(&self.to_string())\n    }\n}\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/janhq/jan/blob/fad3f12a147d138388a66f0d92a02b2675f65294/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/types.rs#L47-L83","documentation":"`KVCacheError::BlockCountInvalid` — the estimator could not find or parse the layer/block count for the architecture (e.g. `llama.block_count`). Block count multiplies per-layer KV-cache size, so without it no estimate is possible.","triggerScenarios":"Calling the KV-cache estimate after architecture was resolved, but the `<arch>.block_count` (or equivalent) key is missing or its string value does not parse to an integer. The parsed metadata values are stored as `String`, so a numeric parse failure produces this error too.","commonSituations":"A GGUF that set architecture but omitted the layer count; an architecture whose key naming differs from the lookup's expectation (e.g. `n_layer` vs `block_count`); a value stored as a float-formatted string that fails integer parsing.","solutions":["Dump the keys under `<arch>.*` and confirm the block-count key name and value format.","If the value is a numeric string, parse with tolerance for whitespace and float form (`s.trim().parse::<f64>()` then cast).","If the architecture uses a different key name, add it to the lookup fallbacks.","Verify the file is a complete, standard GGUF; re-download if metadata is stripped."],"exampleFix":"// before\nlet n: u64 = meta.metadata.get(&format!(\"{}.block_count\", arch))\n    .ok_or(KVCacheError::BlockCountInvalid)?\n    .parse().map_err(|_| KVCacheError::BlockCountInvalid)?;\n\n// after - try common synonyms and parse defensively\nlet raw = [\"block_count\", \"n_layer\", \"n_blocks\"].iter()\n    .find_map(|s| meta.metadata.get(&format!(\"{}.{}\", arch, s)))\n    .ok_or(KVCacheError::BlockCountInvalid)?;\nlet n: u64 = raw.trim().parse::<f64>().map_err(|_| KVCacheError::BlockCountInvalid)? as u64;","handlingStrategy":"validation","validationCode":"fn block_count(meta: &GgufMetadata, arch: &str) -> Option<u64> {\n    [\"block_count\", \"n_layer\", \"n_blocks\"].iter()\n        .find_map(|k| meta.metadata.get(&format!(\"{arch}.{k}\")))\n        .and_then(|s| s.trim().parse::<u64>().ok())\n}","typeGuard":"null","tryCatchPattern":"match estimate_kv_cache(&meta) {\n    Ok(est) => Ok(est),\n    Err(KVCacheError::BlockCountInvalid) => {\n        tracing::warn!(\"block_count missing for arch={}\", arch);\n        Err(UserError::UnsupportedModel(\"missing block_count\".into()))\n    }\n    Err(e) => Err(e.into()),\n}","preventionTips":["Maintain a per-architecture key-name table for known models.","Parse numeric metadata defensively (trim + float-tolerant).","Log all `<arch>.*` keys at estimate time for diagnostics."],"tags":["gguf","metadata","kvcache","llamacpp","rust"],"backgroundTag":null,"analyzedSha":"fad3f12a147d138388a66f0d92a02b2675f65294","analyzedAt":"2026-08-12T20:33:47.516Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}