{"record":{"id":"c62c9237f199d1f4","repo":"janhq/jan","slug":"contextlengthinvalid","errorCode":"ContextLengthInvalid","errorMessage":"Invalid metadata: context_length not found or invalid","messagePattern":"Invalid metadata: context_length 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":71,"sourceCode":"    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\n\n#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize)]\npub enum ModelSupportStatus {\n    #[serde(rename = \"RED\")]\n    Red,\n    #[serde(rename = \"YELLOW\")]","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/types.rs#L53-L89","documentation":"KVCacheError::ContextLengthInvalid is raised when GGUF metadata lacks a valid `context_length` key. The KV-cache needs the model's maximum context length to allocate and bound the cache, so it refuses to proceed when the key is missing or unreadable. It indicates a defective or unsupported GGUF file.","triggerScenarios":"Loading a GGUF model without `{arch}.context_length` metadata, or with a value that cannot be parsed as the expected integer, during KV-cache creation.","commonSituations":"Bad downloads; models edited/stripped with third-party tools; very old GGUF files predating the context_length key; converters that don't write context settings.","solutions":["Re-download the model file and verify checksum integrity.","Check metadata via gguf-dump for a present, positive `context_length` value.","Re-convert the source model with up-to-date llama.cpp conversion tooling.","Patch/extend the plugin's metadata reader if the model legitimately stores context length under a different key."],"exampleFix":"// before: silently assuming defaults\nlet ctx = md.context_length();\n\n// after\nlet ctx = md.get(\"llama.context_length\")\n    .copied()\n    .filter(|v| *v > 0)\n    .ok_or_else(|| anyhow!(\"GGUF missing context_length; re-download/re-convert the model\"))?;","handlingStrategy":"validation","validationCode":"// Rust: verify context_length before KV-cache allocation\nfn has_context_length(md: &GgufMetadata, arch: &str) -> bool {\n    md.get_u64(&format!(\"{arch}.context_length\")).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::ContextLengthInvalid) => anyhow::bail!(\"GGUF missing context_length; use a properly converted model\"),\n    other => other?,\n}","preventionTips":["Include context_length in your model-file acceptance checklist.","Avoid hand-editing or stripping GGUF metadata.","Surface a clear 'model file invalid' message to users instead of a raw error."],"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"}