{"record":{"id":"801d7526a69726d3","repo":"xai-org/grok-build","slug":"does-not-refer-to-a-commit","errorCode":null,"errorMessage":"'{}' does not refer to a commit: {}","messagePattern":"'(.+?)' does not refer to a commit: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace/src/session/git.rs","lineNumber":771,"sourceCode":"}\nfn read_version_bytes(repo: &Repository, path: &str, version: &str) -> Result<Vec<u8>> {\n    match GitRef::parse(version) {\n        GitRef::Workdir => {\n            let full_path = repo\n                .workdir()\n                .ok_or_else(|| anyhow::anyhow!(\"cannot read working files from bare repository\"))?\n                .join(path);\n            std::fs::read(&full_path)\n                .map_err(|e| anyhow::anyhow!(\"failed to read '{}': {}\", path, e))\n        }\n        GitRef::Index => read_blob_from_index(repo, path),\n        GitRef::Treeish(refspec) => {\n            let obj = repo\n                .revparse_single(&refspec)\n                .map_err(|e| anyhow::anyhow!(\"'{}' is not a valid revision: {}\", refspec, e))?;\n            let commit = obj\n                .peel_to_commit()\n                .map_err(|e| anyhow::anyhow!(\"'{}' does not refer to a commit: {}\", refspec, e))?;\n            let tree = commit.tree()?;\n            read_blob_from_tree(repo, &tree, path)\n        }\n    }\n}\n/// Binary files return empty content with is_binary=true.\nfn read_version_content(repo: &Repository, path: &str, version: &str) -> Result<(String, bool)> {\n    let bytes = read_version_bytes(repo, path, version)?;\n    match String::from_utf8(bytes) {\n        Ok(text) => Ok((text, false)),\n        Err(_) => Ok((String::new(), true)),\n    }\n}\nfn read_version_text(repo: &Repository, path: &str, version: &str) -> Option<String> {\n    read_version_content(repo, path, version)\n        .ok()\n        .filter(|(_, is_binary)| !is_binary)\n        .map(|(text, _)| text)","sourceCodeStart":753,"sourceCodeEnd":789,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace/src/session/git.rs#L753-L789","documentation":"After revparse_single succeeds, the object must peel to a commit. If the refspec resolves to a non-commit object (a raw blob or tree), this error is thrown because read_blob_from_tree requires commit.tree(). It means the version points at a git object of the wrong kind.","triggerScenarios":"Passing a treeish refspec that resolves to a raw blob or tree object (e.g. a blob SHA from `git ls-tree`, or `HEAD^{tree}`) into read_version_content.","commonSituations":"Storing object ids from lower-level git tooling in session metadata, using `^{tree}` suffixed refs, or accidental copy-paste of a blob hash instead of a commit hash.","solutions":["Use a commit-like refspec: branch name, tag, or commit SHA (append ^{commit} to force peeling)","Verify with `git cat-file -t <refspec>` that the target is a commit","Replace blob/tree hashes in persisted metadata with their containing commit SHAs","Handle the error by re-resolving to the nearest commit before retrying"],"exampleFix":"// before\nlet bytes = read_version_bytes(&repo, \"src/main.rs\", &blob_sha)?; // resolves to a blob\n// after\nlet commit_sha = \"<containing commit sha>\"; // store commit shas, not blob/tree shas\nlet bytes = read_version_bytes(&repo, \"src/main.rs\", commit_sha)?;","handlingStrategy":"validation","validationCode":"fn is_commit(repo: &git2::Repository, refspec: &str) -> bool {\n    repo.revparse_single(refspec).ok()\n        .map(|o| o.as_commit().is_some() || o.peel_to_commit().is_ok())\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match read_version_bytes(repo, path, version) {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"does not refer to a commit\") => {\n        anyhow::bail!(\"version {} is a non-commit object; store a commit SHA\", version)\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Never persist blob/tree SHAs as versions; store the containing commit","Check object type with `git cat-file -t` when importing refs from other tools","Append ^{commit} to user-supplied refspecs to force commit peeling"],"tags":["git","revision","object-type"],"backgroundTag":"invalid-git-revision","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}