{"record":{"id":"aa250a751470b1c0","repo":"janhq/jan","slug":"blockcountinvalid","errorCode":"BlockCountInvalid","errorMessage":"Invalid metadata: block_count not found or invalid","messagePattern":"Invalid metadata: block_count not found or invalid","errorType":"error_code","errorClass":"KVCacheError","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/7205d770c1e097c3daf35a911176410e93bc5564/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/types.rs#L47-L83","documentation":"KVCacheError::BlockCountInvalid is raised when a GGUF model file's metadata does not contain a valid `block_count` key. The KV-cache setup code in the llamacpp plugin requires this value to size the cache and fails fast if it is missing or not a readable integer. It indicates a malformed, truncated, or unsupported GGUF file rather than a bug in calling code.","triggerScenarios":"Loading a GGUF model whose metadata map lacks `{arch}.block_count` (e.g. corrupted download, non-standard exporter, or an architecture the reader doesn't recognize), or where the value cannot be read as u64.","commonSituations":"Partially downloaded or hand-truncated GGUF files; models produced by unusual quantization/conversion tools; renamed architecture prefixes in metadata keys; very old GGUF revisions.","solutions":["Re-download the GGUF model file and verify its checksum; a truncated download commonly drops trailing metadata.","Inspect the file with `gguf-dump` (or llama.cpp's gguf tooling) to confirm the `block_count` metadata key exists.","Re-convert the model to GGUF with an up-to-date llama.cpp `convert*.py` script so all required metadata keys are written.","If the file is fine, update the tauri-plugin-llamacpp plugin in case it lacks support for the model's architecture prefix."],"exampleFix":"// before: trusting an arbitrary downloaded GGUF\nlet cache = kv_cache::from_gguf(path)?;\n\n// after: verify metadata first\nlet md = gguf::read_metadata(path)?;\nif md.get(\"llama.block_count\").is_none() {\n    return Err(anyhow!(\"GGUF file missing block_count; re-download or re-convert\"));\n}\nlet cache = kv_cache::from_gguf(path)?;","handlingStrategy":"validation","validationCode":"// Rust: validate GGUF metadata before KV-cache construction\nfn has_block_count(md: &GgufMetadata, arch: &str) -> bool {\n    md.get_u64(&format!(\"{arch}.block_count\")).map(|v| v > 0).unwrap_or(false)\n}","typeGuard":"fn valid_u64(v: Option<&u64>) -> bool {\n    matches!(v, Some(n) if *n > 0)\n}","tryCatchPattern":"match kv_cache::from_gguf(&path) {\n    Err(KVCacheError::BlockCountInvalid) => eprintln!(\"bad GGUF: missing block_count\"),\n    other => other?,\n}","preventionTips":["Always verify GGUF downloads with checksums before use.","Run gguf-dump on new model files in CI before shipping them to users.","Obtain models only from sources using current llama.cpp conversion tooling."],"tags":["gguf","rust","model-loading","metadata"],"backgroundTag":"missing-required-config-field","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}