xai-org/grok-build · error
path '{}' not found in commit: {}
Error message
path '{}' not found in commit: {} What it means
read_blob_from_tree looks up a path inside a commit's tree via tree.get_path. When the path does not exist in that commit's tree, git2 returns an error which is wrapped with this message. It means the requested file is absent at the requested revision.
Source
Thrown at crates/codegen/xai-grok-workspace/src/session/git.rs:663
tracing::debug!(
path = %repo.path().display(),
code = ?e.code(),
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)View on GitHub (pinned to bc7f02eddd)
Solutions
- Verify the file exists at that revision: `git ls-tree -r <refspec> -- <path>`
- Use a different refspec (e.g. the commit that actually contains the file version)
- Check path spelling, case sensitivity, and use repo-relative forward-slash paths
- If the file may be missing, handle the error and return empty content or a 'not found' result instead of propagating
Example fix
// before
let bytes = read_version_bytes(repo, "src/old_name.rs", "abc123")?;
// after
let bytes = match read_version_bytes(repo, "src/new_name.rs", "abc123") {
Ok(b) => b,
Err(e) if e.to_string().contains("not found in commit") => Vec::new(), // file absent at revision
Err(e) => return Err(e),
}; Defensive patterns
Strategy: fallback
Validate before calling
fn path_in_commit(repo: &git2::Repository, refspec: &str, path: &str) -> bool {
repo.revparse_single(refspec).ok()
.and_then(|o| o.peel_to_commit().ok())
.and_then(|c| c.tree().ok())
.map(|t| t.get_path(Path::new(path)).is_ok())
.unwrap_or(false)
} Try / catch
match read_version_bytes(repo, path, version) {
Ok(b) => b,
Err(e) if e.to_string().contains("not found in commit") => Vec::new(), // treat as absent
Err(e) => return Err(e),
} Prevention
- Store repo-relative forward-slash paths, not absolute or OS-specific paths
- Record the correct commit SHA alongside file paths in session metadata
- Check `git ls-tree -r <ref> -- <path>` when debugging missing historical files
When it happens
Trigger: Calling read_version_bytes with GitRef::Treeish(refspec) where `path` was added, renamed, or deleted after (or before) the revision the refspec resolves to.
Common situations: Reading a session file version from an older commit that predates the file, typos or case-sensitivity in the path, using a branch name pointing at a commit where the file was moved, or Windows/Unix path separator mismatches.
Related errors
- path '{}' not found in staging area
- failed to read '{}': {}
- '{}' is not a valid revision: {}
- '{}' does not refer to a commit: {}
- git reset --hard {} failed: {}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/f6718b70092ac6c3.
Report an issue: GitHub.