{"record":{"id":"9dbdc8195abd1d11","repo":"janhq/jan","slug":"failed-to-read-name-for-tensor","errorCode":null,"errorMessage":"Failed to read name for tensor {}: {}","messagePattern":"Failed to read name for tensor (.+?): (.+?)","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs","lineNumber":60,"sourceCode":"    // v1 sized strings and dimensions with u32s. llama.cpp refuses that\n    // version outright, and reading it as v2 would invent names.\n    if meta.version < 2 {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"GGUF version {} has no readable tensor block\", meta.version),\n        ));\n    }\n    if meta.tensor_count > MAX_TENSORS {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            format!(\"tensor count {} is unreasonably large\", meta.tensor_count),\n        ));\n    }\n\n    let mut found: Vec<String> = Vec::new();\n    for i in 0..meta.tensor_count {\n        let name = read_gguf_string(&mut file).map_err(|e| {\n            io::Error::new(\n                io::ErrorKind::InvalidData,\n                format!(\"Failed to read name for tensor {}: {}\", i, e),\n            )\n        })?;\n        let n_dims = file.read_u32::<LittleEndian>()?;\n        if n_dims > MAX_TENSOR_DIMS {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                format!(\"tensor {} claims {} dimensions\", i, n_dims),\n            ));\n        }\n        // Read rather than seek: BufReader drops its buffer on every seek, so\n        // skipping this way costs a syscall per tensor on a large model.\n        for _ in 0..n_dims {\n            file.read_u64::<LittleEndian>()?;\n        }\n        file.read_u32::<LittleEndian>()?; // ggml type\n        file.read_u64::<LittleEndian>()?; // offset into the data section","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/src-tauri/plugins/tauri-plugin-llamacpp/src/gguf/helpers.rs#L42-L78","documentation":"While walking the tensor-info block in find_gguf_tensors, the u64-prefixed name string for tensor i could not be read (bad length prefix, truncated file, or desynchronized stream). The wrapper re-tags the underlying I/O or UTF-8 error with the tensor index so the corrupt record is identified.","triggerScenarios":"Calling find_gguf_tensors on a file where the tensor-info block is truncated mid-name, the preceding walk desynchronized (bad version/dims), or a tensor name length prefix points past EOF.","commonSituations":"Partially downloaded GGUF shards (only first shard parsed), files spliced or edited by conversion scripts, v1 files or other formats misread as v2/v3, memory-corrupted model caches.","solutions":["Re-download the model file and verify its checksum","Ensure the reader you pass is seekable over the complete file (not a partial stream)","Check the file is GGUF version >= 2; v1 files misparse and desynchronize the walk","Use llama.cpp's gguf_dump to locate exactly where the file structure breaks"],"exampleFix":"// before\nlet f = std::fs::File::open(\"partial-shard-00001-of-00002.gguf\")?;\nlet found = find_gguf_tensors(f, &wanted)?;\n// after\nlet f = std::fs::File::open(\"model.gguf\")?;\nlet meta = std::fs::metadata(\"model.gguf\")?;\nif meta.len() < expected_min_size { anyhow::bail!(\"file truncated; re-download\"); }\nlet found = find_gguf_tensors(f, &wanted)?;","handlingStrategy":"validation","validationCode":"fn file_looks_complete(path: &std::path::Path, min_bytes: u64) -> io::Result<bool> {\n    Ok(std::fs::metadata(path)?.len() >= min_bytes)\n}\n// check before opening the reader for find_gguf_tensors","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify file size and checksum after download before parsing","Parse GGUF files only from complete, locally stored files (not partial streams)","Log the tensor index from the error to locate the corruption point"],"tags":["gguf","corrupt-file","truncated-file","binary-parsing"],"backgroundTag":"file-read-failed","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"}