janhq/jan · error · KVCacheError::BlockCountInvalid

Invalid metadata: block_count not found or invalid

Error message

Invalid metadata: block_count not found or invalid

What it means

`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.

Source

Thrown at src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/types.rs:65

}

#[derive(Serialize)]
pub struct GgufMetadata {
    pub version: u32,
    pub tensor_count: u64,
    pub metadata: HashMap<String, String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct KVCacheEstimate {
    pub size: u64,
    pub per_token_size: u64,
}
#[derive(Debug, thiserror::Error)]
pub enum KVCacheError {
    #[error("Invalid metadata: architecture not found")]
    ArchitectureNotFound,
    #[error("Invalid metadata: block_count not found or invalid")]
    BlockCountInvalid,
    #[error("Invalid metadata: head_count not found or invalid")]
    HeadCountInvalid,
    #[error("Invalid metadata: embedding_length not found or invalid")]
    EmbeddingLengthInvalid,
    #[error("Invalid metadata: context_length not found or invalid")]
    ContextLengthInvalid,
}

impl serde::Serialize for KVCacheError {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(&self.to_string())
    }
}

View on GitHub (pinned to fad3f12a14)

Solutions

  1. Dump the keys under `<arch>.*` and confirm the block-count key name and value format.
  2. If the value is a numeric string, parse with tolerance for whitespace and float form (`s.trim().parse::<f64>()` then cast).
  3. If the architecture uses a different key name, add it to the lookup fallbacks.
  4. Verify the file is a complete, standard GGUF; re-download if metadata is stripped.

Example fix

// before
let n: u64 = meta.metadata.get(&format!("{}.block_count", arch))
    .ok_or(KVCacheError::BlockCountInvalid)?
    .parse().map_err(|_| KVCacheError::BlockCountInvalid)?;

// after - try common synonyms and parse defensively
let raw = ["block_count", "n_layer", "n_blocks"].iter()
    .find_map(|s| meta.metadata.get(&format!("{}.{}", arch, s)))
    .ok_or(KVCacheError::BlockCountInvalid)?;
let n: u64 = raw.trim().parse::<f64>().map_err(|_| KVCacheError::BlockCountInvalid)? as u64;
Defensive patterns

Strategy: validation

Validate before calling

fn block_count(meta: &GgufMetadata, arch: &str) -> Option<u64> {
    ["block_count", "n_layer", "n_blocks"].iter()
        .find_map(|k| meta.metadata.get(&format!("{arch}.{k}")))
        .and_then(|s| s.trim().parse::<u64>().ok())
}

Type guard

null

Try / catch

match estimate_kv_cache(&meta) {
    Ok(est) => Ok(est),
    Err(KVCacheError::BlockCountInvalid) => {
        tracing::warn!("block_count missing for arch={}", arch);
        Err(UserError::UnsupportedModel("missing block_count".into()))
    }
    Err(e) => Err(e.into()),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of janhq/jan@fad3f12a14 (2026-08-12). Data as JSON: /api/errors/ed9990f26273b70e. Report an issue: GitHub.