xai-org/grok-build · error

'{}' does not refer to a commit: {}

Error message

'{}' does not refer to a commit: {}

What it means

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.

Source

Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:771

}
fn read_version_bytes(repo: &Repository, path: &str, version: &str) -> Result<Vec<u8>> {
    match GitRef::parse(version) {
        GitRef::Workdir => {
            let full_path = repo
                .workdir()
                .ok_or_else(|| anyhow::anyhow!("cannot read working files from bare repository"))?
                .join(path);
            std::fs::read(&full_path)
                .map_err(|e| anyhow::anyhow!("failed to read '{}': {}", path, e))
        }
        GitRef::Index => read_blob_from_index(repo, path),
        GitRef::Treeish(refspec) => {
            let obj = repo
                .revparse_single(&refspec)
                .map_err(|e| anyhow::anyhow!("'{}' is not a valid revision: {}", refspec, e))?;
            let commit = obj
                .peel_to_commit()
                .map_err(|e| anyhow::anyhow!("'{}' does not refer to a commit: {}", refspec, e))?;
            let tree = commit.tree()?;
            read_blob_from_tree(repo, &tree, path)
        }
    }
}
/// Binary files return empty content with is_binary=true.
fn read_version_content(repo: &Repository, path: &str, version: &str) -> Result<(String, bool)> {
    let bytes = read_version_bytes(repo, path, version)?;
    match String::from_utf8(bytes) {
        Ok(text) => Ok((text, false)),
        Err(_) => Ok((String::new(), true)),
    }
}
fn read_version_text(repo: &Repository, path: &str, version: &str) -> Option<String> {
    read_version_content(repo, path, version)
        .ok()
        .filter(|(_, is_binary)| !is_binary)
        .map(|(text, _)| text)

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Use a commit-like refspec: branch name, tag, or commit SHA (append ^{commit} to force peeling)
  2. Verify with `git cat-file -t <refspec>` that the target is a commit
  3. Replace blob/tree hashes in persisted metadata with their containing commit SHAs
  4. Handle the error by re-resolving to the nearest commit before retrying

Example fix

// before
let bytes = read_version_bytes(&repo, "src/main.rs", &blob_sha)?; // resolves to a blob
// after
let commit_sha = "<containing commit sha>"; // store commit shas, not blob/tree shas
let bytes = read_version_bytes(&repo, "src/main.rs", commit_sha)?;
Defensive patterns

Strategy: validation

Validate before calling

fn is_commit(repo: &git2::Repository, refspec: &str) -> bool {
    repo.revparse_single(refspec).ok()
        .map(|o| o.as_commit().is_some() || o.peel_to_commit().is_ok())
        .unwrap_or(false)
}

Try / catch

match read_version_bytes(repo, path, version) {
    Ok(b) => b,
    Err(e) if e.to_string().contains("does not refer to a commit") => {
        anyhow::bail!("version {} is a non-commit object; store a commit SHA", version)
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/801d7526a69726d3. Report an issue: GitHub.