xai-org/grok-build · error

failed to read file content for '{}': {}

Error message

failed to read file content for '{}': {}

What it means

After finding the tree entry, read_blob_from_tree resolves it to a blob via repo.find_blob. This error wraps a git2 failure at that step, meaning the entry's object id could not be loaded as a blob — typically repository object-store corruption or a missing/packed object.

Source

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

                error = %e,
                "git.head: unresolvable",
            );
            None
        }
    }
}
/// The hash stored in HEAD, as `git rev-parse HEAD` prints it. Never loads the
/// object, so it may name one this repo does not have (see [`head_reference`]).
fn head_sha(repo: &Repository) -> Option<String> {
    Some(head_reference(repo)?.target()?.to_string())
}
fn read_blob_from_tree(repo: &Repository, tree: &git2::Tree, path: &str) -> Result<Vec<u8>> {
    let entry = tree
        .get_path(Path::new(path))
        .map_err(|e| anyhow::anyhow!("path '{}' not found in commit: {}", path, e))?;
    let blob = repo
        .find_blob(entry.id())
        .map_err(|e| anyhow::anyhow!("failed to read file content for '{}': {}", path, e))?;
    Ok(blob.content().to_vec())
}
fn read_blob_from_index(repo: &Repository, path: &str) -> Result<Vec<u8>> {
    let index = repo.index()?;
    let entry = index
        .get_path(Path::new(path), 0)
        .ok_or_else(|| anyhow::anyhow!("path '{}' not found in staging area", path))?;
    let blob = repo.find_blob(entry.id)?;
    Ok(blob.content().to_vec())
}
fn resolve_tree<'a>(repo: &'a Repository, refspec: &str) -> Option<git2::Tree<'a>> {
    repo.revparse_single(refspec).ok()?.peel_to_tree().ok()
}
fn resolve_oid(repo: &Repository, refspec: &str) -> Option<git2::Oid> {
    repo.revparse_single(refspec)
        .ok()
        .and_then(|obj| obj.peel_to_commit().ok())
        .map(|c| c.id())

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Run `git fsck --full` to identify and report missing/corrupt objects
  2. Re-fetch or re-clone: `git fetch --unshallow` or fresh `git clone`
  3. Check disk space and permissions in .git/objects
  4. Restore the object from a backup or remote before retrying the read

Example fix

// before
let bytes = read_version_bytes(repo, "src/main.rs", version)?; // Err: failed to read file content
// after
match read_version_bytes(repo, "src/main.rs", version) {
    Ok(b) => b,
    Err(e) if e.to_string().contains("failed to read file content") => {
        // object store corrupt; surface actionable guidance
        return Err(anyhow::anyhow!("git object store corrupt; run git fsck: {e}"));
    }
    Err(e) => return Err(e),
}
Defensive patterns

Strategy: retry

Validate before calling

fn objects_intact(repo: &git2::Repository) -> bool {
    // cheap sanity check: resolve HEAD tree
    repo.revparse_single("HEAD").and_then(|o| o.peel_to_tree()).is_ok()
}

Try / catch

match read_version_bytes(repo, path, version) {
    Ok(b) => b,
    Err(e) if e.to_string().contains("failed to read file content") => {
        // suggest `git fsck` / re-clone; retry only after repair
        anyhow::bail!("git object store damaged; run git fsck: {e}")
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling read_version_bytes on a treeish version where the tree entry references an object id that find_blob cannot resolve (missing object file, failed pack lookup, corrupt object database).

Common situations: Interrupted clones or fetches, disk corruption, garbage collection that removed objects while a process held references, or shallow clones missing historical blobs.

Related errors


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